creado toggle habilitar grupo y correjido un par de bugs de
modalestatico
This commit is contained in:
@@ -9,6 +9,12 @@ public class GrupoDtoBuilder : Builder<GrupoDto>
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GrupoDtoBuilder ConHabilitado(bool habilitado)
|
||||||
|
{
|
||||||
|
data.Habilitado = habilitado;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public GrupoDtoBuilder ConIdGrupo(int id)
|
public GrupoDtoBuilder ConIdGrupo(int id)
|
||||||
{
|
{
|
||||||
data.idgrupo = id;
|
data.idgrupo = id;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class GruposController : ControllerBase
|
|||||||
.Select(g => new GrupoDtoBuilder()
|
.Select(g => new GrupoDtoBuilder()
|
||||||
.ConNombre(g.Nombre)
|
.ConNombre(g.Nombre)
|
||||||
.ConIdGrupo(g.Id)
|
.ConIdGrupo(g.Id)
|
||||||
|
.ConHabilitado(g.Habilitado ?? false)
|
||||||
.ConGruposIncluidos(new HashSet<string>(g.IdGrupoHijos
|
.ConGruposIncluidos(new HashSet<string>(g.IdGrupoHijos
|
||||||
.Select(id => id.Nombre ?? "")))
|
.Select(id => id.Nombre ?? "")))
|
||||||
.ConPermisos(g.Idpermisos.Select(p => new PermisoDtoBuilder()
|
.ConPermisos(g.Idpermisos.Select(p => new PermisoDtoBuilder()
|
||||||
@@ -64,4 +65,20 @@ public class GruposController : ControllerBase
|
|||||||
bool ret2 = RepositorioGrupos.Singleton.AddGrupo(grupo, cli);
|
bool ret2 = RepositorioGrupos.Singleton.AddGrupo(grupo, cli);
|
||||||
return ret2 ? Ok(new { message = "Se Añadio el grupo" }) : BadRequest(new { message = "Fallo al añadirse el grupo" });
|
return ret2 ? Ok(new { message = "Se Añadio el grupo" }) : BadRequest(new { message = "Fallo al añadirse el grupo" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("/api/grupo")]
|
||||||
|
public IActionResult DeleteGrupo([FromHeader(Name = "Auth")] string Auth, [FromQuery] int id)
|
||||||
|
{
|
||||||
|
var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 18);
|
||||||
|
if (ret == false) return BadRequest(new { message = "No tiene permiso para Gestionar grupos" });
|
||||||
|
|
||||||
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
if (cli == null) return BadRequest(new { message = "No hay un cliente por el token que enviaste" });
|
||||||
|
|
||||||
|
if (id <= 0) return BadRequest(new { message = "El ID del grupo debe ser mayor que cero" });
|
||||||
|
var (ret2, estado) = RepositorioGrupos.Singleton.ToggleGrupo(id, cli);
|
||||||
|
return ret2
|
||||||
|
? Ok(new { message = (estado ? "Grupo habilitado exitosamente" : "Grupo deshabilitado exitosamente") })
|
||||||
|
: BadRequest(new { message = "No se pudo cambiar el estado del grupo" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ public class GrupoDto
|
|||||||
{
|
{
|
||||||
public int idgrupo { get; set; }
|
public int idgrupo { get; set; }
|
||||||
public string Nombre { get; set; } = "";
|
public string Nombre { get; set; } = "";
|
||||||
|
public bool Habilitado { get; set; } = false;
|
||||||
public HashSet<string> GruposIncluidos { get; set; } = [];
|
public HashSet<string> GruposIncluidos { get; set; } = [];
|
||||||
public List<PermisoDto> Permisos { get; set; } = [];
|
public List<PermisoDto> Permisos { get; set; } = [];
|
||||||
|
|
||||||
|
|||||||
@@ -109,10 +109,28 @@
|
|||||||
modaldat = "Fallo al hacer la request";
|
modaldat = "Fallo al hacer la request";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function togglegrupo(grupo: GrupoDto) {
|
||||||
|
try {
|
||||||
|
const req = await fetch($urlG + "/api/grupo?id=" + grupo.idgrupo, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
Auth: token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (req.ok) {
|
||||||
|
grupo.habilitado = !grupo.habilitado;
|
||||||
|
}
|
||||||
|
modaldat = (await req.json()).message;
|
||||||
|
ObtenerGrupos();
|
||||||
|
} catch {
|
||||||
|
modaldat = "Fallo al hacer la request";
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if modaldat != ""}
|
{#if modaldat != ""}
|
||||||
<ModalEstatico payload={modaldat} />
|
<ModalEstatico payload={modaldat} close={() => !!(modaldat = "")} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if showModal}
|
{#if showModal}
|
||||||
@@ -157,6 +175,14 @@
|
|||||||
aria-controls={grupo.idgrupo}
|
aria-controls={grupo.idgrupo}
|
||||||
>
|
>
|
||||||
{grupo.nombre}
|
{grupo.nombre}
|
||||||
|
<span
|
||||||
|
class="ms-1 badge text-bg-secondary position-relative"
|
||||||
|
style="top: -5px;"
|
||||||
|
>
|
||||||
|
{grupo.habilitado
|
||||||
|
? "Habilitado"
|
||||||
|
: "Desabilitado"}
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div id={grupo.idgrupo} class="accordion-collapse collapse">
|
<div id={grupo.idgrupo} class="accordion-collapse collapse">
|
||||||
@@ -202,6 +228,14 @@
|
|||||||
onclick={() => setModalEditar(grupo)}
|
onclick={() => setModalEditar(grupo)}
|
||||||
>Editar</button
|
>Editar</button
|
||||||
>
|
>
|
||||||
|
<button
|
||||||
|
class="btn"
|
||||||
|
class:btn-danger={grupo.habilitado}
|
||||||
|
class:btn-success={!grupo.habilitado}
|
||||||
|
onclick={() => togglegrupo(grupo)}
|
||||||
|
>
|
||||||
|
{#if grupo.habilitado}Baja{:else}Alta{/if}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -108,7 +108,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if modaldat != ""}
|
{#if modaldat != ""}
|
||||||
<ModalEstatico payload={modaldat} />
|
<ModalEstatico payload={modaldat} close={() => !!(modaldat = "")} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<NavBarAutocompletable />
|
<NavBarAutocompletable />
|
||||||
|
|||||||
Vendored
+1
@@ -223,6 +223,7 @@ export type PatchPropiedad = {
|
|||||||
export type GrupoDto = {
|
export type GrupoDto = {
|
||||||
idgrupo:number,
|
idgrupo:number,
|
||||||
nombre:string,
|
nombre:string,
|
||||||
|
habilitado:boolean
|
||||||
gruposIncluidos:string[],
|
gruposIncluidos:string[],
|
||||||
permisos:PermisoDto[]
|
permisos:PermisoDto[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,19 @@ public class RepositorioGrupos : RepositorioBase<RepositorioGrupos>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (bool, bool) ToggleGrupo(int id, Cliente cli)
|
||||||
|
{
|
||||||
|
var con = Context;
|
||||||
|
var grupo = con.Grupos.FirstOrDefault(x => x.Id == id);
|
||||||
|
if (grupo == null) return (false, false);
|
||||||
|
if (grupo.Habilitado == null) grupo.Habilitado = false;
|
||||||
|
|
||||||
|
grupo.Habilitado = !grupo.Habilitado;
|
||||||
|
|
||||||
|
GenerarLog(con, cli.Dni, $"Se dio de {(grupo.Habilitado == true ? "alta" : "baja")} el grupo: {id}");
|
||||||
|
return (Guardar(con), grupo.Habilitado ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
public IQueryable<Grupo> ListarTodosLosGrupos()
|
public IQueryable<Grupo> ListarTodosLosGrupos()
|
||||||
{
|
{
|
||||||
var con = Context;
|
var con = Context;
|
||||||
|
|||||||
Reference in New Issue
Block a user