This commit is contained in:
Lizandro Guarnizo
2026-05-15 14:26:52 -05:00
parent 70a43597f3
commit b340d29583
8 changed files with 165 additions and 41 deletions
+17 -11
View File
@@ -33,13 +33,13 @@
<td class="px-4 py-3 font-medium text-slate-800" x-text="u.nombre"></td>
<td class="px-4 py-3 text-slate-600" x-text="u.email"></td>
<td class="px-4 py-3">
<span class="badge" :class="u.rol==='partner' ? 'badge-blue' : 'badge-green'" x-text="u.rol"></span>
<span class="badge" :class="(u.role?.es_portal_partner || u.rol==='partner') ? 'badge-blue' : 'badge-green'" x-text="u.role?.name || u.rol"></span>
</td>
<td class="px-4 py-3 text-slate-500 text-xs">
<template x-if="u.rol==='cliente' && u.cliente">
<template x-if="!(u.role?.es_portal_partner || u.rol==='partner') && u.cliente">
<span x-text="u.cliente?.empresa || u.cliente?.nombre"></span>
</template>
<template x-if="u.rol==='partner'">
<template x-if="u.role?.es_portal_partner || u.rol==='partner'">
<div class="flex flex-wrap gap-1">
<template x-for="acc in (u.portal_accesos||[])" :key="acc.ID">
<span class="bg-slate-100 px-2 py-0.5 rounded text-xs flex items-center gap-1">
@@ -82,12 +82,16 @@
</div>
<div>
<label class="label">Rol</label>
<select x-model="form.rol" class="input-field w-full">
<option value="cliente">Cliente</option>
<option value="partner">Partner</option>
<select x-model.number="form.role_id" class="input-field w-full">
<option value="">Sin rol asignado</option>
<template x-for="r in portalRoles" :key="r.ID">
<option :value="r.ID">
<span x-text="r.name + (r.es_portal_partner ? ' (Partner)' : ' (Cliente)')"></span>
</option>
</template>
</select>
</div>
<div x-show="form.rol==='cliente'">
<div x-show="portalRoles.find(r => r.ID === form.role_id)?.es_portal_cliente">
<label class="label">Cliente asignado</label>
<select x-model.number="form.cliente_id" class="input-field w-full">
<option value="">Sin asignar</option>
@@ -146,11 +150,11 @@
<script>
function portalUsuariosApp() {
return {
items: [], clientes: [], loading: false, saving: false,
items: [], clientes: [], portalRoles: [], loading: false, saving: false,
showModal: false, showDelete: false, showAccesoModal: false,
editId: null, deleteId: null, error: '',
accesoUserId: null, accesoClienteId: '',
form: { nombre:'', email:'', password:'', rol:'cliente', cliente_id:'', activo:true, notas:'' },
form: { nombre:'', email:'', password:'', role_id:'', cliente_id:'', activo:true, notas:'' },
async init() { await this.load(); },
@@ -160,23 +164,25 @@ function portalUsuariosApp() {
const r = await axios.get('/app/loadportalusuarios');
this.items = r.data.items || [];
this.clientes = r.data.clientes || [];
this.portalRoles = r.data.portalRoles || [];
} finally { this.loading = false; }
},
openCreate() {
this.editId=null; this.error='';
this.form={nombre:'',email:'',password:'',rol:'cliente',cliente_id:'',activo:true,notas:''};
this.form={nombre:'',email:'',password:'',role_id:'',cliente_id:'',activo:true,notas:''};
this.showModal=true;
},
openEdit(u) {
this.editId=u.ID; this.error='';
this.form={nombre:u.nombre,email:u.email,password:'',rol:u.rol,cliente_id:u.cliente_id||'',activo:u.activo,notas:u.notas||''};
this.form={nombre:u.nombre,email:u.email,password:'',role_id:u.role_id||'',cliente_id:u.cliente_id||'',activo:u.activo,notas:u.notas||''};
this.showModal=true;
},
async save() {
this.saving=true; this.error='';
const payload={...this.form};
if(payload.cliente_id==='') payload.cliente_id=null;
if(payload.role_id==='') payload.role_id=null;
try {
if(this.editId) await axios.put(`/app/portal-usuarios/${this.editId}`, payload);
else await axios.post('/app/portal-usuarios', payload);
+51
View File
@@ -51,6 +51,7 @@
<th class="py-2 px-4 border-b w-52 ">Nombre</th>
<th class="py-2 px-4 border-b">Descripción</th>
<th class="py-2 px-4 border-b">Submodulos</th>
<th class="py-2 px-4 border-b w-28">Portal</th>
<th class="py-2 px-4 border-b w-32"></th>
</tr>
</thead>
@@ -86,6 +87,16 @@
</span>
</template>
</td>
<td class="py-3 text-xs px-4 border-b">
<div class="flex flex-col gap-1">
<template x-if="registro.es_portal_cliente">
<span class="bg-blue-100 text-blue-700 px-2 py-0.5 rounded text-xs font-medium">Usuario Final</span>
</template>
<template x-if="registro.es_portal_partner">
<span class="bg-purple-100 text-purple-700 px-2 py-0.5 rounded text-xs font-medium">Partner</span>
</template>
</div>
</td>
<td class="py-3 text-xs px-4 border-b ">
<div class="flex justify-between space-x-1">
<button
@@ -105,6 +116,8 @@
Name = registro.name;
Description = registro.description;
Submodules = [...registro.submodules];
EsPortalCliente = registro.es_portal_cliente || false;
EsPortalPartner = registro.es_portal_partner || false;
modulos.forEach(modulo => {
modulo.submodules.forEach(submodulo => {
submodulo.checked = Submodules.some(sm => sm.ID === submodulo.ID);
@@ -209,6 +222,19 @@
</div>
</template>
</div>
<div class="mt-4 p-3 border rounded-md bg-slate-50">
<p class="font-semibold text-sm mb-2">Tipo de acceso Portal</p>
<div class="flex gap-6">
<label class="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" x-model="EsPortalCliente" @change="if(EsPortalCliente) EsPortalPartner=false" class="rounded">
Usuario Final (Cliente)
</label>
<label class="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" x-model="EsPortalPartner" @change="if(EsPortalPartner) EsPortalCliente=false" class="rounded">
Partner
</label>
</div>
</div>
<div class="mt-4 flex justify-between">
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button>
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
@@ -253,6 +279,19 @@
</div>
</div>
</template>
<div class="mt-4 p-3 border rounded-md bg-slate-50">
<p class="font-semibold text-sm mb-2">Tipo de acceso Portal</p>
<div class="flex gap-6">
<label class="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" x-model="newEsPortalCliente" @change="if(newEsPortalCliente) newEsPortalPartner=false" class="rounded">
Usuario Final (Cliente)
</label>
<label class="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" x-model="newEsPortalPartner" @change="if(newEsPortalPartner) newEsPortalCliente=false" class="rounded">
Partner
</label>
</div>
</div>
<div class="mt-4 flex justify-between">
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar</button>
@@ -291,9 +330,13 @@
newName: '',
newDescription: '',
newEsPortalCliente: false,
newEsPortalPartner: false,
Name: '',
Description: '',
EsPortalCliente: false,
EsPortalPartner: false,
modulos: [],
Submodules: [],
submodulos: [],
@@ -415,6 +458,8 @@
const requestData = {
name: this.newName,
description: this.newDescription,
es_portal_cliente: this.newEsPortalCliente,
es_portal_partner: this.newEsPortalPartner,
submodules: selectedSubmodules.flatMap(modulo => modulo.submodules)
};
@@ -427,6 +472,8 @@
.then(() => {
this.newName = '';
this.newDescription = '';
this.newEsPortalCliente = false;
this.newEsPortalPartner = false;
this.modulos.forEach(modulo => {
modulo.submodules.forEach(submodulo => submodulo.checked = false); // Reset checkboxes
});
@@ -471,6 +518,8 @@
body: JSON.stringify({
name: this.Name,
description: this.Description,
es_portal_cliente: this.EsPortalCliente,
es_portal_partner: this.EsPortalPartner,
submodules: this.submodulos
})
})
@@ -478,6 +527,8 @@
.then(() => {
this.Name = '';
this.Description = '';
this.EsPortalCliente = false;
this.EsPortalPartner = false;
this.submodulos = [];
this.modulos.forEach(modulo => {
modulo.submodules.forEach(submodulo => {