avance manejo de roles

francisco/photos
Francisco Sandoval 2024-01-06 12:25:39 -03:00
parent 380632ce41
commit add9428eab
10 changed files with 40 additions and 21 deletions

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>...</title> <title>...</title>
<link rel="shortcut icon" href="https://www.mtt.gob.cl/wp-content/themes/mtt/images/favicon.ico" />
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -67,6 +67,11 @@
{#if ordering === 'nombre_app'}<i class="bi bi-caret-up-fill"></i>{/if} {#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} {#if ordering === '-nombre_app'}<i class="bi bi-caret-down-fill"></i>{/if}
</th> </th>
<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>
<th> <th>
<a href={"#"} on:click|preventDefault={() => onOrderBy('vigente')}>Vigente</a> <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-up-fill"></i>{/if}
@ -80,6 +85,7 @@
<td class="table-light">{offset + index + 1}</td> <td class="table-light">{offset + index + 1}</td>
<td>{app.id_aplicacion}</td> <td>{app.id_aplicacion}</td>
<td><a href={"#"} on:click|preventDefault={() => onEdita(app)}>{app.nombre_app}</a></td> <td><a href={"#"} on:click|preventDefault={() => onEdita(app)}>{app.nombre_app}</a></td>
<td>{app.path_app}</td>
<td>{app.vigente ? '✅':'🚫'}</td> <td>{app.vigente ? '✅':'🚫'}</td>
</tr> </tr>
{/each} {/each}
@ -92,7 +98,6 @@
<i class="bi bi-arrow-repeat"></i> <i class="bi bi-arrow-repeat"></i>
</a> </a>
<Paginate <Paginate
{offset}
{limit} {limit}
{count} {count}
on:page={ev => page = ev.detail} on:page={ev => page = ev.detail}

View File

@ -66,9 +66,9 @@
<div class="col-md-3">ID</div> <div class="col-md-3">ID</div>
<div class="col-md"> <div class="col-md">
{#if aplicacion.id_aplicacion} {#if aplicacion.id_aplicacion}
<input type="number" value={form.id_aplicacion} disabled class="form-control"> <input type="number" value={form.id_aplicacion} disabled class="form-control">
{:else} {:else}
<input type="number" bind:value={form.id_aplicacion} required class="form-control"> <input type="number" bind:value={form.id_aplicacion} class="form-control">
{/if} {/if}
</div> </div>
</div> </div>
@ -78,6 +78,12 @@
<input type="text" bind:value={form.nombre_app} required class="form-control"> <input type="text" bind:value={form.nombre_app} required class="form-control">
</div> </div>
</div> </div>
<div class="row mb-3">
<div class="col-md-3">Ruta URL</div>
<div class="col-md">
<input type="text" bind:value={form.path_app} required class="form-control">
</div>
</div>
<div class="mb-3"> <div class="mb-3">
<div class="form-check form-switch"> <div class="form-check form-switch">
<input class="form-check-input" type="checkbox" bind:checked={form.vigente} role="switch" id="vigente"> <input class="form-check-input" type="checkbox" bind:checked={form.vigente} role="switch" id="vigente">

View File

@ -71,16 +71,10 @@
loading = true; loading = true;
if (rol.id_rol) { if (rol.id_rol) {
form = await updateRol(form) form = await updateRol(form)
form3 = CrearEditarEliminar(rol.id_rol,form_inicio,form3) form3 = CrearEditarEliminar(rol.id_rol,form_inicio,form3)
for(const obj1 of form3){ for(const obj1 of form3){
if (obj1.opcion == "Crear"){ if (obj1.opcion == "Crear"){
await createRolyaplicacion(obj1) await createRolyaplicacion(obj1)
} }
@ -90,7 +84,6 @@
else if (obj1.opcion == "Eliminar"){ else if (obj1.opcion == "Eliminar"){
await deleteRolyaplicacion(obj1.id_rol_app) await deleteRolyaplicacion(obj1.id_rol_app)
} }
} }
} else { } else {
@ -230,14 +223,9 @@ function CrearEditarEliminar(id, arregloInicial, arregloFinal) {
<input type="text" bind:value={form.nombre_rol} required class="form-control"> <input type="text" bind:value={form.nombre_rol} required class="form-control">
</div> </div>
</div> </div>
<h4 class="h4 mb-3">Permiso a aplicaciones </h4>
<pre>
</pre>
<div class="card"> <div class="card">
<div class="card-header bg-secondary text-light">Permiso a Aplicaciones</div>
<div class="card-body"> <div class="card-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-sm table-bordered"> <table class="table table-sm table-bordered">

View File

@ -45,6 +45,7 @@
<th>Nombres</th> <th>Nombres</th>
<th>Apellido 1</th> <th>Apellido 1</th>
<th>Apellido 2</th> <th>Apellido 2</th>
<th>Rol</th>
<th>Email</th> <th>Email</th>
</tr> </tr>
</thead> </thead>
@ -55,6 +56,7 @@
<td>{row.persona.nombres}</td> <td>{row.persona.nombres}</td>
<td>{row.persona.apellido_a}</td> <td>{row.persona.apellido_a}</td>
<td>{row.persona.apellido_b}</td> <td>{row.persona.apellido_b}</td>
<td>{row.rol.nombre_rol}</td>
<td>{row.persona.email}</td> <td>{row.persona.email}</td>
</tr> </tr>
{/each} {/each}

View File

@ -1,7 +1,12 @@
<script> <script>
import { getRoles } from "$/services/roles";
export let form = {} export let form = {}
export let es_nuevo = true export let es_nuevo = true
export let clave2 = '' export let clave2 = ''
let roles = []
getRoles().then(data => roles = data).catch(error => alert(error))
</script> </script>
<div class="row"> <div class="row">
@ -9,7 +14,19 @@
Login Login
<input type="text" bind:value={form.login} class="form-control" required disabled={!es_nuevo}> <input type="text" bind:value={form.login} class="form-control" required disabled={!es_nuevo}>
</div> </div>
<div class="col-md mb-3">
Rol
<select required bind:value={form.id_rol} class="form-select">
{#each roles as rol}
<option value={rol.id_rol}>{rol.nombre_rol}</option>
{/each}
</select>
</div>
<div class="col-md mb-3 pt-3"> <div class="col-md mb-3 pt-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" bind:checked={form.superuser} id="usuario-superuser">
<label class="form-check-label" for="usuario-superuser">Super usuario</label>
</div>
<div class="form-check form-switch"> <div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" bind:checked={form.vigente} id="usuario-vigente"> <input class="form-check-input" type="checkbox" role="switch" bind:checked={form.vigente} id="usuario-vigente">
<label class="form-check-label" for="usuario-vigente">Vigente</label> <label class="form-check-label" for="usuario-vigente">Vigente</label>

View File

@ -28,7 +28,7 @@ export async function createAplicacion(data) {
return res.json() return res.json()
} }
export async function updateAplicacion({ id_aplicacion: id, ...data }) { export async function updateAplicacion({ id_aplicacion: id = null, ...data }) {
const res = await fetch(`${base}/aplicaciones/${id}/`, { const res = await fetch(`${base}/aplicaciones/${id}/`, {
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),

View File

@ -27,7 +27,7 @@ export async function createRol(data) {
return res.json() return res.json()
} }
export async function updateRol({ id_rol: id, ...data }) { export async function updateRol({ id_rol: id = null, ...data }) {
const res = await fetch(`${base}/roles/${id}/`, { const res = await fetch(`${base}/roles/${id}/`, {
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),

View File

@ -38,7 +38,7 @@ export async function createRolyaplicacion(data) {
return res.json() return res.json()
} }
export async function updateRolyaplicacion({ id_rol_app: id, ...data }) { export async function updateRolyaplicacion({ id_rol_app: id = null, ...data }) {
const res = await fetch(`${base}/rolyaplicacion/${id}/`, { const res = await fetch(`${base}/rolyaplicacion/${id}/`, {
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),

View File

@ -28,7 +28,7 @@ export async function createUsuario(data) {
return res.json() return res.json()
} }
export async function updateUsuario({ login: id, ...data }) { export async function updateUsuario({ login: id = null, ...data }) {
const res = await fetch(`${base}/usuarios/${id}/`, { const res = await fetch(`${base}/usuarios/${id}/`, {
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),