2023-12-05 10:37:40 -03:00
|
|
|
<script>
|
|
|
|
import Paginate from "$/components/Paginate.svelte";
|
|
|
|
import { getAplicaciones } from "$/services/aplicaciones";
|
|
|
|
import PageTitle from "$/components/PageTitle.svelte";
|
|
|
|
import ModalAplicacion from "./ModalAplicacion.svelte";
|
2024-01-07 21:25:33 -03:00
|
|
|
import { useLocation } from "svelte-navigator";
|
|
|
|
import { getPermisosPath } from "$/services/usuarios";
|
2023-12-05 10:37:40 -03:00
|
|
|
|
|
|
|
const limit = 15;
|
|
|
|
let page = 1;
|
|
|
|
let offset = 0;
|
|
|
|
let count = 0;
|
|
|
|
let ordering = 'id_aplicacion'
|
|
|
|
let aplicaciones = []
|
|
|
|
let aplicacion = null
|
|
|
|
let loading = false;
|
2024-01-07 21:25:33 -03:00
|
|
|
let escritura = false;
|
|
|
|
let location = useLocation()
|
|
|
|
|
|
|
|
getPermisosPath($location.pathname)
|
|
|
|
.then(data => escritura = data.escritura)
|
|
|
|
.catch(error => console.log({ error }))
|
2023-12-05 10:37:40 -03:00
|
|
|
|
|
|
|
$: onPage(page)
|
|
|
|
|
|
|
|
async function onPage(p) {
|
|
|
|
try {
|
|
|
|
loading = true
|
|
|
|
offset = (p - 1) * limit;
|
|
|
|
const data = await getAplicaciones({ offset, limit, ordering })
|
|
|
|
aplicaciones = data.results;
|
|
|
|
count = data.count;
|
|
|
|
} catch (error) {
|
2024-01-20 14:19:38 -03:00
|
|
|
globalThis.toast.error(error)
|
2023-12-05 10:37:40 -03:00
|
|
|
} finally {
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEdita(item) {
|
|
|
|
aplicacion = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onNuevo() {
|
|
|
|
aplicacion = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onOrderBy(field) {
|
|
|
|
ordering = ordering === field ? '-' + field : field;
|
|
|
|
onPage(page)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<PageTitle {loading}>Aplicaciones</PageTitle>
|
|
|
|
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-header">
|
2024-01-07 21:25:33 -03:00
|
|
|
{#if escritura}
|
2024-01-07 13:16:53 -03:00
|
|
|
<button class="btn btn-primary" on:click|preventDefault={onNuevo}>
|
|
|
|
<i class="bi bi-plus-lg"></i> Nuevo
|
|
|
|
</button>
|
|
|
|
{/if}
|
2023-12-05 10:37:40 -03:00
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-sm table-bordered">
|
|
|
|
<thead>
|
|
|
|
<tr class="table-light">
|
|
|
|
<th style="width:5%">Nro</th>
|
|
|
|
<th>
|
|
|
|
<a href={"#"} on:click|preventDefault={() => onOrderBy('id_aplicacion')}>ID</a>
|
|
|
|
{#if ordering === 'id_aplicacion'}<i class="bi bi-caret-up-fill"></i>{/if}
|
|
|
|
{#if ordering === '-id_aplicacion'}<i class="bi bi-caret-down-fill"></i>{/if}
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
<a href={"#"} on:click|preventDefault={() => onOrderBy('nombre_app')}>Nombre</a>
|
|
|
|
{#if ordering === 'nombre_app'}<i class="bi bi-caret-up-fill"></i>{/if}
|
|
|
|
{#if ordering === '-nombre_app'}<i class="bi bi-caret-down-fill"></i>{/if}
|
|
|
|
</th>
|
2024-01-06 12:25:39 -03:00
|
|
|
<th>
|
|
|
|
<a href={"#"} on:click|preventDefault={() => onOrderBy('path_app')}>Ruta URL</a>
|
|
|
|
{#if ordering === 'path_app'}<i class="bi bi-caret-up-fill"></i>{/if}
|
|
|
|
{#if ordering === '-path_app'}<i class="bi bi-caret-down-fill"></i>{/if}
|
|
|
|
</th>
|
2023-12-05 10:37:40 -03:00
|
|
|
<th>
|
|
|
|
<a href={"#"} on:click|preventDefault={() => onOrderBy('vigente')}>Vigente</a>
|
|
|
|
{#if ordering === 'vigente'}<i class="bi bi-caret-up-fill"></i>{/if}
|
|
|
|
{#if ordering === '-vigente'}<i class="bi bi-caret-down-fill"></i>{/if}
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{#each aplicaciones as app, index}
|
2024-01-07 13:16:53 -03:00
|
|
|
<tr key={index}>
|
2023-12-05 10:37:40 -03:00
|
|
|
<td class="table-light">{offset + index + 1}</td>
|
|
|
|
<td>{app.id_aplicacion}</td>
|
|
|
|
<td><a href={"#"} on:click|preventDefault={() => onEdita(app)}>{app.nombre_app}</a></td>
|
2024-01-06 12:25:39 -03:00
|
|
|
<td>{app.path_app}</td>
|
2023-12-05 10:37:40 -03:00
|
|
|
<td>{app.vigente ? '✅':'🚫'}</td>
|
|
|
|
</tr>
|
|
|
|
{/each}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="card-footer d-flex">
|
|
|
|
<a href={"#"} class="btn btn-outline-secondary me-3" on:click|preventDefault={() => onPage(page)}>
|
|
|
|
<i class="bi bi-arrow-repeat"></i>
|
|
|
|
</a>
|
|
|
|
<Paginate
|
|
|
|
{limit}
|
|
|
|
{count}
|
|
|
|
on:page={ev => page = ev.detail}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{#if aplicacion}
|
|
|
|
<ModalAplicacion
|
|
|
|
{aplicacion}
|
2024-01-07 21:25:33 -03:00
|
|
|
{escritura}
|
2023-12-05 10:37:40 -03:00
|
|
|
on:close={() => aplicacion = null}
|
|
|
|
on:refresh={() => onPage(page)}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.table-responsive {
|
|
|
|
max-height: calc(100vh - 300px);
|
|
|
|
}
|
|
|
|
</style>
|