diff --git a/back/config/auditoria.go b/back/config/auditoria.go index 83537ad..0e5e3d1 100644 --- a/back/config/auditoria.go +++ b/back/config/auditoria.go @@ -84,6 +84,7 @@ func generarLogCreate(tx *gorm.DB) { detalles := []logs.LogDetalle{ { + ID: 0, NombreTabla: tx.Statement.Table, Columna: "*", ValorNuevo: fmt.Sprintf("Registro creado (ID: %v)", obtenerID(tx.Statement.Dest)), @@ -100,6 +101,7 @@ func generarLogDelete(tx *gorm.DB) { detalles := []logs.LogDetalle{ { + ID: 0, NombreTabla: tx.Statement.Table, Columna: "*", ValorAnterior: fmt.Sprintf("Registro eliminado (ID: %v)", obtenerID(tx.Statement.Dest)), @@ -148,6 +150,7 @@ func generarDetalles(tabla string, anterior, nuevo interface{}) []logs.LogDetall if vAnt != vNue { detalles = append(detalles, logs.LogDetalle{ + ID: uint(i), NombreTabla: tabla, Columna: campo.Name, ValorAnterior: vAnt, diff --git a/back/models/logs/logdetalle.go b/back/models/logs/logdetalle.go index 6534a94..32a254f 100644 --- a/back/models/logs/logdetalle.go +++ b/back/models/logs/logdetalle.go @@ -1,6 +1,7 @@ package logs type LogDetalle struct { + ID uint `json:"id"` NombreTabla string `json:"nombreTabla"` Columna string `json:"columna"` ValorAnterior string `json:"valorAnterior,omitempty"` diff --git a/front/src/lib/hooks/logs/obtenerLogs.ts b/front/src/lib/hooks/logs/obtenerLogs.ts index 7cda695..3a642e1 100644 --- a/front/src/lib/hooks/logs/obtenerLogs.ts +++ b/front/src/lib/hooks/logs/obtenerLogs.ts @@ -11,5 +11,6 @@ export async function obtenerLogs(pagina: number): Promise(); @@ -32,8 +33,8 @@ }); const headers = [ + { key: 'id', value: '#' }, { key: 'created_at', value: 'Fecha' }, - { key: 'empresaId', value: 'Empresa' }, { key: 'usuario', value: 'Usuario' }, { key: 'accion', value: 'Acción' } ]; @@ -48,7 +49,7 @@ }); } - const cargandoActual = $derived(() => cache.estaCargando(cache.paginaActual())); + const cargandoActual = $derived.by(() => cache.estaCargando(cache.pagina));
@@ -60,8 +61,8 @@ size="small" icon={Renew} iconDescription="Recargar página actual" - disabled={cargandoActual()} - onclick={() => irAPagina(cache.paginaActual(), true)} + disabled={cargandoActual} + onclick={() => irAPagina(cache.pagina, true)} > Recargar @@ -70,9 +71,9 @@ {#if error}

{error}

- +
- {:else if cargandoActual() && logs.length === 0} + {:else if cargandoActual && logs.length === 0} {:else if logs.length === 0} @@ -92,18 +93,33 @@ {/if} - + {#if row.detalles && row.detalles.length > 0} -
- {#each row.detalles as d} -
- {d.nombreTabla} - {d.columna} - {d.valorAnterior ?? '—'} - {d.valorNuevo ?? '—'} -
- {/each} -
+ {@const detallesConId = row.detalles.map((d, i) => ({ ...d, id: d.id || i + 1 }))} + + + {#if cell.key === 'valorAnterior'} + {cell.value ?? '—'} + {:else if cell.key === 'valorNuevo'} + {#if cell.value} + {cell.value} + {:else} + — + {/if} + {:else} + {cell.value} + {/if} + + {:else}

Sin detalles registrados.

{/if} @@ -111,14 +127,15 @@ {/if} -
- irAPagina(e.detail)} - /> - {#if cache.ultimoFueCache()} - desde caché - {/if} -
+ irAPagina(e.detail.page - 1)} + /> + diff --git a/front/src/routes/logs/LogsEstado.svelte.ts b/front/src/routes/logs/LogsEstado.svelte.ts index c92b2c1..ac3f42d 100644 --- a/front/src/routes/logs/LogsEstado.svelte.ts +++ b/front/src/routes/logs/LogsEstado.svelte.ts @@ -4,20 +4,19 @@ import { SvelteMap, SvelteSet } from 'svelte/reactivity'; export interface RespuestaPagina { logs: T[]; maxPagina: number; + totalItems: number; } export class LogsCache { #cache = new SvelteMap(); #cargando = new SvelteSet(); #enVuelo = new Map>(); - #pagina = $state(0); - #maxPagina = $state(0); + pagina = $state(0); + maxPagina = $state(0); + totalItems = $state(0); + ultimoHit = $state(true); - #ultimoHit = $state(true); - ultimoFueCache = $derived(() => this.#ultimoHit); - paginaActual = $derived(() => this.#pagina); - paginaMaxima = $derived(() => this.#maxPagina); - paginaActMax = $derived(() => `${this.#pagina}/${this.#maxPagina}`); + paginaActMax = $derived(() => `${this.pagina}/${this.maxPagina}`); tieneCache(pagina: number): boolean { return this.#cache.has(pagina); @@ -36,10 +35,10 @@ export class LogsCache { fetcher: (pagina: number) => Promise>, forzar = false ): Promise { - this.#pagina = pagina; + this.pagina = pagina; if (!forzar && this.#cache.has(pagina)) { - this.#ultimoHit = true; + this.ultimoHit = true; return this.#cache.get(pagina)!; } @@ -47,12 +46,13 @@ export class LogsCache { return this.#enVuelo.get(pagina)!; } - this.#ultimoHit = false; + this.ultimoHit = false; this.#cargando.add(pagina); const promesa = fetcher(pagina) - .then(({ logs, maxPagina }) => { + .then(({ logs, maxPagina, totalItems }) => { this.#cache.set(pagina, logs); - this.#maxPagina = maxPagina; + this.maxPagina = maxPagina; + this.totalItems = totalItems; return logs; }) .finally(() => { @@ -77,10 +77,10 @@ export class LogsCache { } get puedeAvanzar(): boolean { - return this.#pagina < this.#maxPagina; + return this.pagina < this.maxPagina; } get puedeRetroceder(): boolean { - return this.#pagina > 0; + return this.pagina > 0; } } diff --git a/front/src/routes/repuestos/CrearRepuestoForm.svelte b/front/src/routes/repuestos/CrearRepuestoForm.svelte index e375273..e7feb72 100644 --- a/front/src/routes/repuestos/CrearRepuestoForm.svelte +++ b/front/src/routes/repuestos/CrearRepuestoForm.svelte @@ -7,6 +7,7 @@ let { open = $bindable(), onClose } = $props(); let error = $state(''); + let enviando = $state(false); let repuesto: CrearRepuestoDto = $state({ nombre: '', descripcion: '', @@ -35,6 +36,8 @@ id="crearRepuestoForm" onsubmit={async (e) => { e.preventDefault(); + if (enviando) return; + enviando = true; error = ''; if (repuesto.descripcion == '') error += 'Falta Descripcion, '; if (repuesto.marca == '') error += 'Falta Marca, '; @@ -48,6 +51,7 @@ invalidate('repuestos:load'); handleClose(); } + enviando = false; }} > diff --git a/front/src/routes/repuestos/EditarRepuestoForm.svelte b/front/src/routes/repuestos/EditarRepuestoForm.svelte index 70cea44..ecab989 100644 --- a/front/src/routes/repuestos/EditarRepuestoForm.svelte +++ b/front/src/routes/repuestos/EditarRepuestoForm.svelte @@ -11,6 +11,7 @@ }: { open: boolean; onClose: Function; repuesto: ActualizarRepuestoDto } = $props(); let error = $state(''); + let enviando = $state(false); function handleClose() { reset(); @@ -33,6 +34,8 @@ id="actualizarRepuestoForm" onsubmit={async (e) => { e.preventDefault(); + if (enviando) return; + enviando = true; error = ''; if (repuesto.id == 0) error += 'Falta id'; if (repuesto.descripcion == '') error += 'Falta Descripcion, '; @@ -47,6 +50,7 @@ invalidate('repuestos:load'); handleClose(); } + enviando = false; }} > diff --git a/front/src/types.d.ts b/front/src/types.d.ts index a0b39a1..4488eb0 100644 --- a/front/src/types.d.ts +++ b/front/src/types.d.ts @@ -23,6 +23,7 @@ export interface LogEntry { } export interface LogDetalle { + id: number; nombreTabla: string; columna: string; valorAnterior?: string;