Private
Public Access
añadidas imagenes a los grupos y pérmisos
This commit is contained in:
1 parent
00f140480d
commit
cec07f51f9
4 files changed
+191
-64
No files matched your search
@@ -74,7 +74,7 @@ func (r *repositorioGrupo) ObtenerPorIDConRelaciones(id uint, simple bool) (*mod
|
||||
if simple {
|
||||
if err := r.db.
|
||||
Preload("Permisos", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id", "nombre", "alias")
|
||||
return db.Select("id", "nombre", "alias", "imagen")
|
||||
}).
|
||||
First(&grupo, id).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
import IconPreview from '$lib/components/IconPreview.svelte';
|
||||
import GrupoFormModal from './GrupoFormModal.svelte';
|
||||
import DeleteGrupoModal from './DeleteGrupoModal.svelte';
|
||||
import AgregarPermisoModal from './AgregarPermisoModal.svelte';
|
||||
@@ -32,6 +33,7 @@
|
||||
let formId = $state(0);
|
||||
let formNombre = $state('');
|
||||
let formDescripcion = $state('');
|
||||
let formImagen = $state('');
|
||||
|
||||
let deleteModalOpen = $state(false);
|
||||
let deleteId = $state(0);
|
||||
@@ -51,6 +53,7 @@
|
||||
|
||||
const headers = [
|
||||
{ key: 'id' as const, value: 'ID' },
|
||||
{ key: 'imagen' as const, value: 'Icono' },
|
||||
{ key: 'nombre' as const, value: 'Nombre' },
|
||||
{ key: 'descripcion' as const, value: 'Descripción' }
|
||||
];
|
||||
@@ -97,13 +100,15 @@
|
||||
if (modalEditando) {
|
||||
await actualizarGrupo(formId, {
|
||||
nombre: formNombre,
|
||||
descripcion: formDescripcion
|
||||
descripcion: formDescripcion,
|
||||
imagen: formImagen
|
||||
});
|
||||
mostrarNotificacion('Grupo actualizado', '');
|
||||
} else {
|
||||
await crearGrupo({
|
||||
nombre: formNombre,
|
||||
descripcion: formDescripcion
|
||||
descripcion: formDescripcion,
|
||||
imagen: formImagen
|
||||
});
|
||||
mostrarNotificacion('Grupo creado', '');
|
||||
}
|
||||
@@ -215,7 +220,7 @@
|
||||
<div class="page-container">
|
||||
<div class="flex justify-between">
|
||||
<h1 class="page-title">Gestión de Grupos</h1>
|
||||
<Button onclick={() => { modalEditando = false; formId = 0; formNombre = ''; formDescripcion = ''; modalOpen = true; }} icon={Add}>Nuevo Grupo</Button>
|
||||
<Button onclick={() => { modalEditando = false; formId = 0; formNombre = ''; formDescripcion = ''; formImagen = ''; modalOpen = true; }} icon={Add}>Nuevo Grupo</Button>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
@@ -245,10 +250,22 @@
|
||||
style="cursor: pointer"
|
||||
>
|
||||
{#each headers as header}
|
||||
<TableCell>{String(g[header.key] ?? '-')}</TableCell>
|
||||
<TableCell>
|
||||
{#if header.key === 'imagen'}
|
||||
{#if g.imagen}
|
||||
<span class="grupo-icono" title={g.imagen}>
|
||||
<IconPreview nombre={g.imagen} size={20} />
|
||||
</span>
|
||||
{:else}
|
||||
-
|
||||
{/if}
|
||||
{:else}
|
||||
{String(g[header.key] ?? '-')}
|
||||
{/if}
|
||||
</TableCell>
|
||||
{/each}
|
||||
<TableCell class="acciones-cell">
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => { modalEditando = true; formId = g.id; formNombre = g.nombre; formDescripcion = g.descripcion ?? ''; modalOpen = true; }}>
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => { modalEditando = true; formId = g.id; formNombre = g.nombre; formDescripcion = g.descripcion ?? ''; formImagen = g.imagen ?? ''; modalOpen = true; }}>
|
||||
Editar
|
||||
</Button>
|
||||
<Button
|
||||
@@ -270,6 +287,9 @@
|
||||
<section class="detail-section">
|
||||
<div class="detail-header">
|
||||
<h2 class="section-title">
|
||||
{#if selectedGrupo.imagen}
|
||||
<IconPreview nombre={selectedGrupo.imagen} size={24} />
|
||||
{/if}
|
||||
<strong>{selectedGrupo.nombre}</strong>
|
||||
</h2>
|
||||
{#if selectedGrupo.descripcion}
|
||||
@@ -298,7 +318,14 @@
|
||||
<TableBody>
|
||||
{#each selectedGrupo.permisos as permiso}
|
||||
<TableRow>
|
||||
<TableCell>{permiso.nombre}</TableCell>
|
||||
<TableCell>
|
||||
<span class="permiso-nombre">
|
||||
{#if permiso.imagen}
|
||||
<IconPreview nombre={permiso.imagen} size={16} />
|
||||
{/if}
|
||||
{permiso.nombre}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>{permiso.alias || '-'}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
@@ -369,6 +396,7 @@
|
||||
editando={modalEditando}
|
||||
bind:nombre={formNombre}
|
||||
bind:descripcion={formDescripcion}
|
||||
bind:imagen={formImagen}
|
||||
alGuardar={guardarGrupo}
|
||||
alCerrar={() => (modalOpen = false)}
|
||||
/>
|
||||
@@ -421,11 +449,26 @@
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.grupo-icono {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.permiso-nombre {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.text-secondary {
|
||||
color: var(--cds-text-secondary, #6f6f6f);
|
||||
margin-top: 0.25rem;
|
||||
|
||||
@@ -4,7 +4,17 @@
|
||||
import { ObtenerGruposDeUsuario } from '$lib/hooks/ObtenerGruposDeUsuario';
|
||||
import CardError from '$lib/components/CardError.svelte';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import { Accordion, ContainedList, ContainedListItem } from 'carbon-components-svelte';
|
||||
import IconPreview from '$lib/components/IconPreview.svelte';
|
||||
import {
|
||||
ClickableTile,
|
||||
Column,
|
||||
Grid,
|
||||
Row,
|
||||
SkeletonPlaceholder,
|
||||
SkeletonText,
|
||||
Text,
|
||||
Tile
|
||||
} from 'carbon-components-svelte';
|
||||
import { BpmnLinkOutline } from 'carbon-icons-svelte';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
@@ -15,37 +25,110 @@
|
||||
});
|
||||
|
||||
let grupos = usuario ? ObtenerGruposDeUsuario(usuario) : undefined;
|
||||
|
||||
function hrefPermiso(alias: string): string {
|
||||
return alias.startsWith('/') ? alias : `/${alias}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Header {usuario} {grupos} />
|
||||
|
||||
<main>
|
||||
<section class="dashboard-section">
|
||||
<div class="dashboard-header">
|
||||
<h2 class="section-title">Tu panel de control</h2>
|
||||
<p class="section-subtitle">Accede a los módulos de tu cuenta</p>
|
||||
<section class="mx-auto! max-w-[1000px] px-4! py-20!">
|
||||
<div class="mb-8">
|
||||
<Text tag="h2" type="productive-heading-05" weight="semibold" class="mb-3! text-center">
|
||||
Tu panel de control
|
||||
</Text>
|
||||
<Text
|
||||
tag="p"
|
||||
type="body-long-01"
|
||||
color="secondary"
|
||||
class="mx-auto! mb-12! max-w-[520px] text-center"
|
||||
>
|
||||
Accede a los módulos de tu cuenta
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{#await grupos}
|
||||
<Accordion skeleton />
|
||||
<Grid fullWidth>
|
||||
<Row>
|
||||
{#each Array(8) as _, i (i)}
|
||||
<Column sm={4} md={4} lg={4}>
|
||||
<Tile
|
||||
class="pointer-events-none flex! aspect-square min-h-[9rem]! animate-pulse cursor-default flex-col items-center justify-center gap-3"
|
||||
>
|
||||
<SkeletonPlaceholder size={32} />
|
||||
<SkeletonText lines={2} width="80%" />
|
||||
</Tile>
|
||||
</Column>
|
||||
{/each}
|
||||
</Row>
|
||||
</Grid>
|
||||
{:then gg}
|
||||
{#if gg == undefined}
|
||||
<p class="py-8 text-center text-neutral-500">No tienes grupos asignados</p>
|
||||
{#if !gg || gg.groups.length === 0}
|
||||
<Text tag="p" type="body-long-01" color="secondary" class="py-8! text-center">
|
||||
No tienes grupos asignados
|
||||
</Text>
|
||||
{:else}
|
||||
{#each gg.groups as g}
|
||||
<p class="text-2xl!">{g.nombre}</p>
|
||||
{#if g.permisos?.length == 0}
|
||||
<p class="text-neutral-500">No hay permisos en este grupo</p>
|
||||
{:else}
|
||||
<ContainedList>
|
||||
{#each g.permisos?.sort((a, b) => (a.alias > b.alias ? 0 : -1)) as p}
|
||||
<div class="w-full cursor-pointer hover:bg-white/5">
|
||||
<ContainedListItem icon={BpmnLinkOutline} on:click={() => goto(p.alias)}>
|
||||
<span>{p.nombre}</span>
|
||||
</ContainedListItem>
|
||||
</div>
|
||||
{/each}
|
||||
</ContainedList>
|
||||
{/if}
|
||||
{#each gg.groups as g (g.id)}
|
||||
<section class="mb-12! last:mb-0!">
|
||||
<div class="mb-2 flex items-center gap-3">
|
||||
<span
|
||||
class="inline-flex items-center justify-center text-[var(--cds-icon-primary,#f4f4f4)]"
|
||||
>
|
||||
{#if g.imagen}
|
||||
<IconPreview nombre={g.imagen} size={28} />
|
||||
{:else}
|
||||
<BpmnLinkOutline size={28} />
|
||||
{/if}
|
||||
</span>
|
||||
<Text tag="h3" type="productive-heading-03" weight="semibold">
|
||||
{g.nombre}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{#if g.descripcion}
|
||||
<Text tag="p" type="body-long-01" color="secondary" class="mb-4!">
|
||||
{g.descripcion}
|
||||
</Text>
|
||||
{/if}
|
||||
|
||||
{#if g.permisos && g.permisos.length > 0}
|
||||
<Grid fullWidth class="mt-4">
|
||||
<Row>
|
||||
{#each [...g.permisos].sort( (a, b) => a.nombre.localeCompare(b.nombre) ) as p (p.nombre)}
|
||||
<Column sm={4} md={4} lg={4}>
|
||||
<ClickableTile
|
||||
href={hrefPermiso(p.alias)}
|
||||
title={p.nombre}
|
||||
class="flex! aspect-square min-h-[9rem]! mb-2! flex-col items-center justify-center text-center whitespace-normal! no-underline! hover:-translate-y-0.5"
|
||||
>
|
||||
<span class="inline-flex items-center justify-center">
|
||||
{#if p.imagen}
|
||||
<IconPreview nombre={p.imagen} size={32} />
|
||||
{:else}
|
||||
<BpmnLinkOutline size={32} />
|
||||
{/if}
|
||||
</span>
|
||||
<Text
|
||||
tag="span"
|
||||
type="body-short-01"
|
||||
weight="semibold"
|
||||
class="line-clamp-2 max-w-full wrap-anywhere"
|
||||
>
|
||||
{p.nombre}
|
||||
</Text>
|
||||
</ClickableTile>
|
||||
</Column>
|
||||
{/each}
|
||||
</Row>
|
||||
</Grid>
|
||||
{:else}
|
||||
<Text tag="p" type="body-long-01" color="secondary" class="py-8! text-center">
|
||||
No hay permisos en este grupo
|
||||
</Text>
|
||||
{/if}
|
||||
</section>
|
||||
{/each}
|
||||
{/if}
|
||||
{:catch err}
|
||||
@@ -53,34 +136,3 @@
|
||||
{/await}
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.section-title {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.section-subtitle {
|
||||
font-size: 1.05rem;
|
||||
color: var(--cds-text-secondary, #c6c6c6);
|
||||
text-align: center;
|
||||
max-width: 520px;
|
||||
margin: 0 auto 3rem;
|
||||
}
|
||||
|
||||
.dashboard-section {
|
||||
padding: 5rem 1rem;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.dashboard-header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.dashboard-section :global(.bx--accordion) {
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -17,6 +17,8 @@
|
||||
} from 'carbon-components-svelte';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
import IconPicker from '$lib/components/IconPicker.svelte';
|
||||
import IconPreview from '$lib/components/IconPreview.svelte';
|
||||
import { obtenerPermisos } from '$lib/hooks/obtenerPermisos';
|
||||
import { crearPermiso } from '$lib/hooks/crearPermiso';
|
||||
import { actualizarPermiso } from '$lib/hooks/actualizarPermiso';
|
||||
@@ -36,6 +38,7 @@
|
||||
let formNombre = $state('');
|
||||
let formAlias = $state('');
|
||||
let formDescripcion = $state('');
|
||||
let formImagen = $state('');
|
||||
|
||||
let deleteModalOpen = $state(false);
|
||||
let deleteId = $state(0);
|
||||
@@ -47,6 +50,7 @@
|
||||
|
||||
const headers = [
|
||||
{ key: 'id' as const, value: 'ID' },
|
||||
{ key: 'imagen' as const, value: 'Icono' },
|
||||
{ key: 'nombre' as const, value: 'Nombre' },
|
||||
{ key: 'alias' as const, value: 'Alias' },
|
||||
{ key: 'descripcion' as const, value: 'Descripción' }
|
||||
@@ -70,6 +74,7 @@
|
||||
formNombre = '';
|
||||
formAlias = '';
|
||||
formDescripcion = '';
|
||||
formImagen = '';
|
||||
modalOpen = true;
|
||||
}
|
||||
|
||||
@@ -79,6 +84,7 @@
|
||||
formNombre = p.nombre;
|
||||
formAlias = p.alias;
|
||||
formDescripcion = p.descripcion ?? '';
|
||||
formImagen = p.imagen ?? '';
|
||||
modalOpen = true;
|
||||
}
|
||||
|
||||
@@ -119,14 +125,16 @@
|
||||
await actualizarPermiso(formId, {
|
||||
nombre: formNombre,
|
||||
alias: formAlias,
|
||||
descripcion: formDescripcion
|
||||
descripcion: formDescripcion,
|
||||
imagen: formImagen
|
||||
});
|
||||
mostrarNotificacion('Permiso actualizado', '');
|
||||
} else {
|
||||
await crearPermiso({
|
||||
nombre: formNombre,
|
||||
alias: formAlias,
|
||||
descripcion: formDescripcion
|
||||
descripcion: formDescripcion,
|
||||
imagen: formImagen
|
||||
});
|
||||
mostrarNotificacion('Permiso creado', '');
|
||||
}
|
||||
@@ -190,7 +198,19 @@
|
||||
{#each permisos as p (p.id)}
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableCell>{String(p[header.key] ?? '-')}</TableCell>
|
||||
<TableCell>
|
||||
{#if header.key === 'imagen'}
|
||||
{#if p.imagen}
|
||||
<span class="permiso-icono" title={p.imagen}>
|
||||
<IconPreview nombre={p.imagen} size={20} />
|
||||
</span>
|
||||
{:else}
|
||||
-
|
||||
{/if}
|
||||
{:else}
|
||||
{String(p[header.key] ?? '-')}
|
||||
{/if}
|
||||
</TableCell>
|
||||
{/each}
|
||||
<TableCell class="acciones-cell">
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => abrirModalEditar(p)}>
|
||||
@@ -216,12 +236,14 @@
|
||||
<form id="permiso-form" onsubmit={guardarPermiso}>
|
||||
<Modal
|
||||
bind:open={modalOpen}
|
||||
size="lg"
|
||||
modalHeading={modalEditando ? 'Editar Permiso' : 'Nuevo Permiso'}
|
||||
primaryButtonText={modalEditando ? 'Guardar' : 'Crear'}
|
||||
secondaryButtonText="Cancelar"
|
||||
formId="permiso-form"
|
||||
on:click:button--secondary={handleSecondary}
|
||||
hasForm
|
||||
hasScrollingContent
|
||||
>
|
||||
<TextInput bind:value={formNombre} labelText="Nombre" placeholder="ej: crear_usuario" />
|
||||
<TextInput bind:value={formAlias} labelText="Alias" placeholder="ej: Crear Usuario" />
|
||||
@@ -230,6 +252,8 @@
|
||||
labelText="Descripción"
|
||||
placeholder="Descripción del permiso"
|
||||
/>
|
||||
|
||||
<IconPicker bind:value={formImagen} label="Imagen / icono del permiso" />
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
@@ -251,3 +275,11 @@
|
||||
subtitle={successMsg ? '' : errorMsg}
|
||||
open={notifOpen}
|
||||
/>
|
||||
|
||||
<style>
|
||||
.permiso-icono {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user