From 170950014cdda334cf926c5b7bfd558631c9da6a Mon Sep 17 00:00:00 2001 From: Rodrigo_R Date: Wed, 30 Aug 2023 00:03:29 -0400 Subject: [PATCH] Se agregan todas las pagina de roles y rolesaplicaciones --- src/layouts/Sidebar.svelte | 5 + src/pages/roles/Admin.svelte | 109 +++++++ src/pages/roles/ModalRol.svelte | 275 ++++++++++++++++++ src/pages/rolesaplicaciones/Admin.svelte | 121 ++++++++ .../ModalRolaplicacion.svelte | 95 ++++++ src/routes/user.routes.js | 5 + src/services/roles.js | 47 +++ src/services/rolesyaplicaciones.js | 58 ++++ 8 files changed, 715 insertions(+) create mode 100644 src/pages/roles/Admin.svelte create mode 100644 src/pages/roles/ModalRol.svelte create mode 100644 src/pages/rolesaplicaciones/Admin.svelte create mode 100644 src/pages/rolesaplicaciones/ModalRolaplicacion.svelte create mode 100644 src/services/roles.js create mode 100644 src/services/rolesyaplicaciones.js diff --git a/src/layouts/Sidebar.svelte b/src/layouts/Sidebar.svelte index c43b03a..6aca2e4 100644 --- a/src/layouts/Sidebar.svelte +++ b/src/layouts/Sidebar.svelte @@ -58,6 +58,11 @@ Personas + + + Roles + + diff --git a/src/pages/roles/Admin.svelte b/src/pages/roles/Admin.svelte new file mode 100644 index 0000000..7d9c147 --- /dev/null +++ b/src/pages/roles/Admin.svelte @@ -0,0 +1,109 @@ + + +Roles + +
+
+ +
+
+
+ + + + + + + + + + {#each roles as app, index} + + + + + + {/each} + +
Nro + onOrderBy('id_rol')}>ID + {#if ordering === 'id_rol'}{/if} + {#if ordering === '-id_rol'}{/if} + + onOrderBy('nombre_rol')}>Nombre + {#if ordering === 'nombre_rol'}{/if} + {#if ordering === '-nombre_rol'}{/if} +
{offset + index + 1}{app.id_rol} onEdita(app)}>{app.nombre_rol}
+
+
+ +
+ +{#if rol} + rol = null} + on:refresh={() => onPage(page)} + /> +{/if} + + \ No newline at end of file diff --git a/src/pages/roles/ModalRol.svelte b/src/pages/roles/ModalRol.svelte new file mode 100644 index 0000000..c45832b --- /dev/null +++ b/src/pages/roles/ModalRol.svelte @@ -0,0 +1,275 @@ + + +
+ dispatch('close')}> +
+
+
Rol ID
+
+ {#if rol.id_rol} + + {:else} + + {/if} +
+
+
+
Nombre Rol
+
+ +
+
+

Permiso a aplicaciones

+
+                
+               
+              
+ + +
+
+
+ + + + + + + + + + + {#each form3 as aplicacion} + + + + + + + + + {/each} + + +
AplicacionesAccesoSolo visualizar
{aplicacion.nombre_app}
+
+
+
+
+ + + + +
+
diff --git a/src/pages/rolesaplicaciones/Admin.svelte b/src/pages/rolesaplicaciones/Admin.svelte new file mode 100644 index 0000000..84bbce2 --- /dev/null +++ b/src/pages/rolesaplicaciones/Admin.svelte @@ -0,0 +1,121 @@ + + +rolesyaplicaciones +
+ {data2} + {#each data2 as rol} + {rol.id_rol} + {rol.id_aplicacion} + {/each} +
+ +
+
+ +
+
+
+ + + + + + + + + + + {#each roles as app, index} + + + + + + + {/each} + +
Nro + onOrderBy('id_aplicacion')}>ID rol + {#if ordering === 'id_aplicacion'}{/if} + {#if ordering === '-id_aplicacion'}{/if} + + onOrderBy('id_rol')}>Id app + {#if ordering === 'id_rol'}{/if} + {#if ordering === '-id_rol'}{/if} + Solo Visualizar
{offset + index + 1}{app.id_rol} onEdita(app)}>{app.id_aplicacion}{app.solo_visualizar}
+
+
+ +
+ +{#if rol} + rol = null} + on:refresh={() => onPage(page)} + /> +{/if} + + + \ No newline at end of file diff --git a/src/pages/rolesaplicaciones/ModalRolaplicacion.svelte b/src/pages/rolesaplicaciones/ModalRolaplicacion.svelte new file mode 100644 index 0000000..5589475 --- /dev/null +++ b/src/pages/rolesaplicaciones/ModalRolaplicacion.svelte @@ -0,0 +1,95 @@ + + +
+ dispatch('close')}> +
+
+
ID app
+
+ {#if rol.id_aplicacion} + + {:else} + + {/if} +
+
+
+
ID rol
+
+ +
+
+
+
+ + +
+
+
+ + + + +
+
\ No newline at end of file diff --git a/src/routes/user.routes.js b/src/routes/user.routes.js index d1f4d21..d10f84d 100644 --- a/src/routes/user.routes.js +++ b/src/routes/user.routes.js @@ -11,6 +11,8 @@ import PagePersonaCreate from '$/pages/personas/Persona.svelte' import PagePersonaModifica from '$/pages/personas/Persona.svelte' import PageMapaParaderos from '$/pages/mapas/Paraderos.svelte' import PageMapaRutas from '$/pages/mapas/Rutas.svelte' +import PageRoles from '$/pages/roles/Admin.svelte' +import PageRolesyAplicaciones from '$/pages/rolesaplicaciones/Admin.svelte' export const routes = [ { path: '/', component: PageHome }, @@ -19,6 +21,8 @@ export const routes = [ { path: '/usuarios', component: PageUsuarios }, { path: '/usuarios/nuevo', component: PageUsuarioCreate }, { path: '/usuarios/:login', component: PageUsuarioModifica }, + { path: '/roles', component: PageRoles }, + { path: '/rolesaplicaciones', component: PageRolesyAplicaciones }, { path: '/comunas', component: PageComunas }, { path: '/personas', component: PagePersonas }, { path: '/personas/nuevo', component: PagePersonaCreate }, @@ -26,4 +30,5 @@ export const routes = [ { path: '/mapas/paraderos', component: PageMapaParaderos }, { path: '/mapas/rutas', component: PageMapaRutas }, { path: '*', component: PageError }, + ] \ No newline at end of file diff --git a/src/services/roles.js b/src/services/roles.js new file mode 100644 index 0000000..e7bafe3 --- /dev/null +++ b/src/services/roles.js @@ -0,0 +1,47 @@ +import { base, getToken } from './_config' + +export async function getRoles(params) { + const query = !params ? '' : '?' + (new URLSearchParams(params).toString()); + const res = await fetch(`${base}/roles/${query}`, { + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function getRol(id) { + const res = await fetch(`${base}/roles/${id}/`, { + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function createRol(data) { + const res = await fetch(`${base}/roles/`, { + method: 'POST', + body: JSON.stringify(data), + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function updateRol({ id_rol: id, ...data }) { + const res = await fetch(`${base}/roles/${id}/`, { + method: 'PATCH', + body: JSON.stringify(data), + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function deleteRol(id) { + const res = await fetch(`${base}/roles/${id}/`, { + method: 'DELETE', + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.text() +} \ No newline at end of file diff --git a/src/services/rolesyaplicaciones.js b/src/services/rolesyaplicaciones.js new file mode 100644 index 0000000..6b2a789 --- /dev/null +++ b/src/services/rolesyaplicaciones.js @@ -0,0 +1,58 @@ +import { base, getToken } from './_config' + +export async function getRolesyaplicaciones(idRol) { + const params = idRol ? { id_rol: idRol } : null; // Preparar los parámetros de la consulta + const query = params ? '?' + new URLSearchParams(params).toString() : ''; + const res = await fetch(`${base}/rolyaplicacion/${query}`, { + headers: {"Authorization": `Bearer ${getToken()}`,"Content-Type": "application/json"} + }); + if (!res.ok) throw await res.json(); + return res.json(); +} + +export async function getRolesaplicaciones(params) { + const query = !params ? '' : '?' + (new URLSearchParams(params).toString()); + const res = await fetch(`${base}/rolyaplicacion/${query}`, { + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + + +export async function getRolyaplicacion(id) { + const res = await fetch(`${base}/rolyaplicacion/${id}/`, { + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function createRolyaplicacion(data) { + const res = await fetch(`${base}/rolyaplicacion/`, { + method: 'POST', + body: JSON.stringify(data), + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function updateRolyaplicacion({ id_rol_app: id, ...data }) { + const res = await fetch(`${base}/rolyaplicacion/${id}/`, { + method: 'PATCH', + body: JSON.stringify(data), + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.json() +} + +export async function deleteRolyaplicacion(id) { + const res = await fetch(`${base}/rolyaplicacion/${id}/`, { + method: 'DELETE', + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.json() + return res.text() +} \ No newline at end of file