up
This commit is contained in:
@@ -813,6 +813,7 @@ func SeedPortalClientes() {
|
||||
{"Facturas", "Gestión de facturas y pagos por cliente", "/app/facturas"},
|
||||
{"Portal Usuarios", "Usuarios con acceso al portal de clientes", "/app/portal-usuarios"},
|
||||
{"Tickets", "Tickets de soporte abiertos por clientes del portal", "/app/tickets"},
|
||||
{"Config. Notificaciones", "Configurar canales de notificación por evento", "/app/notif-config"},
|
||||
}
|
||||
|
||||
var insertados []models.Submodules
|
||||
|
||||
@@ -20,15 +20,84 @@
|
||||
<body class="min-h-screen flex flex-col">
|
||||
|
||||
<!-- Navbar -->
|
||||
<header class="bg-white border-b border-slate-200 sticky top-0 z-30">
|
||||
<header class="bg-white border-b border-slate-200 sticky top-0 z-30"
|
||||
x-data="{
|
||||
bellOpen: false,
|
||||
notifs: [],
|
||||
unread: 0,
|
||||
async loadNotifs() {
|
||||
try {
|
||||
const r = await axios.get('/portal/mis-notifs?no_leidas=0');
|
||||
this.notifs = r.data.items || [];
|
||||
this.unread = r.data.unread || 0;
|
||||
} catch {}
|
||||
},
|
||||
async markRead(id) {
|
||||
await axios.put('/portal/mis-notifs/' + id + '/leida');
|
||||
const n = this.notifs.find(x => x.ID === id);
|
||||
if (n) { n.leida = true; this.unread = Math.max(0, this.unread - 1); }
|
||||
},
|
||||
async markAll() {
|
||||
await axios.post('/portal/mis-notifs/marcar-todas');
|
||||
this.notifs.forEach(n => n.leida = true);
|
||||
this.unread = 0;
|
||||
}
|
||||
}"
|
||||
x-init="loadNotifs(); setInterval(() => loadNotifs(), 30000)">
|
||||
<div class="max-w-6xl mx-auto px-4 sm:px-6 h-16 flex items-center justify-between">
|
||||
<!-- Logo -->
|
||||
<a href="/portal/dashboard" class="flex items-center gap-2 font-bold text-slate-800 text-lg">
|
||||
<span class="w-7 h-7 rounded-full flex items-center justify-center text-white text-xs font-bold" style="background:#8eb02f">U</span>
|
||||
<span class="w-7 h-7 rounded-full flex items-center justify-content:center text-white text-xs font-bold flex items-center justify-center" style="background:#8eb02f">U</span>
|
||||
<span>Portal de Clientes</span>
|
||||
</a>
|
||||
<!-- User -->
|
||||
<div class="flex items-center gap-4">
|
||||
<!-- Right: bell + user -->
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- 🔔 Bell -->
|
||||
<div class="relative">
|
||||
<button @click="bellOpen = !bellOpen; if(bellOpen) loadNotifs()"
|
||||
class="relative p-2 rounded-xl hover:bg-slate-100 transition-colors focus:outline-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-slate-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0"/>
|
||||
</svg>
|
||||
<span x-show="unread > 0"
|
||||
class="absolute -top-0.5 -right-0.5 h-4 w-4 flex items-center justify-center rounded-full text-white text-[10px] font-bold"
|
||||
style="background:#8eb02f"
|
||||
x-text="unread > 9 ? '9+' : unread">
|
||||
</span>
|
||||
</button>
|
||||
<!-- Dropdown -->
|
||||
<div x-show="bellOpen" @click.outside="bellOpen = false"
|
||||
x-transition:enter="transition ease-out duration-150"
|
||||
x-transition:enter-start="opacity-0 scale-95 -translate-y-1"
|
||||
x-transition:enter-end="opacity-100 scale-100 translate-y-0"
|
||||
x-transition:leave="transition ease-in duration-100"
|
||||
x-transition:leave-start="opacity-100 scale-100 translate-y-0"
|
||||
x-transition:leave-end="opacity-0 scale-95 -translate-y-1"
|
||||
class="absolute right-0 top-12 w-72 bg-white rounded-xl shadow-lg border border-slate-200 overflow-hidden z-50">
|
||||
<div class="px-4 py-3 border-b border-slate-100 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-slate-800">Notificaciones</span>
|
||||
<button x-show="unread > 0" @click="markAll()" class="text-xs text-slate-400 hover:text-slate-600">Marcar todas leídas</button>
|
||||
</div>
|
||||
<div class="max-h-64 overflow-y-auto divide-y divide-slate-100">
|
||||
<template x-if="notifs.length === 0">
|
||||
<div class="px-4 py-6 text-center text-slate-400 text-sm">Sin notificaciones</div>
|
||||
</template>
|
||||
<template x-for="n in notifs" :key="n.ID">
|
||||
<a :href="n.url || '#'" @click="if(!n.leida) markRead(n.ID)"
|
||||
class="flex items-start gap-3 px-4 py-3 hover:bg-slate-50 transition-colors"
|
||||
:class="!n.leida ? 'bg-emerald-50/50' : ''">
|
||||
<span class="text-lg leading-none mt-0.5" x-text="n.icono || '🔔'"></span>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-slate-800 truncate" x-text="n.titulo"></p>
|
||||
<p class="text-xs text-slate-500 truncate mt-0.5" x-text="n.cuerpo"></p>
|
||||
</div>
|
||||
<div x-show="!n.leida" class="w-2 h-2 rounded-full flex-shrink-0 mt-1.5" style="background:#8eb02f"></div>
|
||||
</a>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- User name -->
|
||||
<span class="text-sm text-slate-600 hidden sm:block">
|
||||
{{ if .portalUser }}{{ .portalUser.Nombre }}{{ end }}
|
||||
</span>
|
||||
|
||||
@@ -155,78 +155,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Left: page context -->
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- Mobile logo placeholder (sidebar button is in lateral.html) -->
|
||||
<div class="md:hidden w-8"></div>
|
||||
<!-- Breadcrumb / title area -->
|
||||
<div class="hidden sm:flex items-center gap-2 text-sm text-slate-500">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"/>
|
||||
</svg>
|
||||
<span class="text-slate-400">Panel de control</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: actions + user menu -->
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- User info (desktop) -->
|
||||
<div class="hidden md:flex flex-col items-end mr-1">
|
||||
<span class="text-xs font-semibold text-slate-700 leading-tight" x-text="userName"></span>
|
||||
<span class="text-xs text-slate-400 leading-tight" x-text="roleName"></span>
|
||||
</div>
|
||||
|
||||
<!-- Avatar dropdown -->
|
||||
<div class="relative">
|
||||
<button @click="open = !open"
|
||||
class="flex items-center gap-2 p-1 rounded-xl hover:bg-slate-100 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1"
|
||||
style="--tw-ring-color:#8eb02f">
|
||||
<div class="ui-avatar ui-avatar-lg" x-text="initial"></div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-3.5 w-3.5 text-slate-400 transition-transform duration-150"
|
||||
:class="open ? 'rotate-180' : ''"
|
||||
fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Dropdown -->
|
||||
<div x-show="open"
|
||||
@click.outside="open = false"
|
||||
x-transition:enter="transition ease-out duration-150"
|
||||
x-transition:enter-start="opacity-0 scale-95 -translate-y-1"
|
||||
x-transition:enter-end="opacity-100 scale-100 translate-y-0"
|
||||
x-transition:leave="transition ease-in duration-100"
|
||||
x-transition:leave-start="opacity-100 scale-100 translate-y-0"
|
||||
x-transition:leave-end="opacity-0 scale-95 -translate-y-1"
|
||||
class="absolute right-0 top-12 w-52 bg-white rounded-xl shadow-lg border border-slate-200 overflow-hidden z-50">
|
||||
<!-- User info in dropdown -->
|
||||
<div class="px-4 py-3 border-b border-slate-100">
|
||||
<p class="text-sm font-semibold text-slate-800 truncate" x-text="userName"></p>
|
||||
<p class="text-xs text-slate-500 truncate" x-text="roleName"></p>
|
||||
</div>
|
||||
<!-- Links -->
|
||||
<div class="py-1">
|
||||
<a href="/app/profile"
|
||||
class="flex items-center gap-3 px-4 py-2.5 text-sm text-slate-700 hover:bg-slate-50 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M17.982 18.725A7.488 7.488 0 0012 15.75a7.488 7.488 0 00-5.982 2.975m11.963 0a9 9 0 10-11.963 0m11.963 0A8.966 8.966 0 0112 21a8.966 8.966 0 01-5.982-2.275M15 9.75a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
</svg>
|
||||
Mi cuenta
|
||||
</a>
|
||||
<div class="border-t border-slate-100 my-1"></div>
|
||||
<a href="/do/logout"
|
||||
class="flex items-center gap-3 px-4 py-2.5 text-sm text-red-600 hover:bg-red-50 transition-colors"
|
||||
onclick="event.preventDefault(); document.getElementById('header-logout').submit();">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75"/>
|
||||
</svg>
|
||||
Cerrar sesión
|
||||
</a>
|
||||
<form id="header-logout" action="/do/logout" method="POST" class="hidden"></form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -335,3 +335,42 @@ func PortalDownloadFactura(c *fiber.Ctx) error {
|
||||
c.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, f.OriginalName))
|
||||
return c.SendFile(clean)
|
||||
}
|
||||
|
||||
// ─── Notificaciones in-app del portal user ────────────────────────────────────
|
||||
|
||||
func PortalGetNotifs(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
soloNoLeidas := c.Query("no_leidas") == "1"
|
||||
items, err := models.GetSistemaNotifs("portal_user", u.ID, soloNoLeidas)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
count := models.CountUnreadNotifs("portal_user", u.ID)
|
||||
return c.JSON(fiber.Map{"items": items, "unread": count})
|
||||
}
|
||||
|
||||
func PortalMarcarNotifLeida(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
id, _ := c.ParamsInt("id")
|
||||
if err := models.MarcarNotifLeida(uint(id)); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
func PortalMarcarTodasLeidas(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
if err := models.MarcarTodasLeidas("portal_user", u.ID); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
@@ -29,4 +29,9 @@ func PortalRoutes(app fiber.Router) {
|
||||
// Descargas
|
||||
portal.Get("/entregables/:id/download", controllers.PortalDownloadEntregable)
|
||||
portal.Get("/facturas/:id/download", controllers.PortalDownloadFactura)
|
||||
|
||||
// Notificaciones in-app del portal user
|
||||
portal.Get("/mis-notifs", controllers.PortalGetNotifs)
|
||||
portal.Put("/mis-notifs/:id/leida", controllers.PortalMarcarNotifLeida)
|
||||
portal.Post("/mis-notifs/marcar-todas", controllers.PortalMarcarTodasLeidas)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user