diff --git a/js/layout.js b/js/layout.js index 09daf2b..8004ce0 100644 --- a/js/layout.js +++ b/js/layout.js @@ -1,135 +1,136 @@ // CONFIGURACIÓN GLOBAL -const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' - ? 'http://localhost:3000' - : 'https://integrarepara-api.integrarepara.es'; +const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' +? 'http://localhost:3000' +: 'https://integrarepara-api.integrarepara.es'; document.addEventListener("DOMContentLoaded", () => { - // 1. Verificar Token - const token = localStorage.getItem("token"); - if (!token) { - if (!window.location.pathname.endsWith("index.html") && window.location.pathname !== "/") { - window.location.href = "index.html"; - return; - } - } +// 1. Verificar Token +const token = localStorage.getItem("token"); +if (!token) { +if (!window.location.pathname.endsWith("index.html") && window.location.pathname !== "/") { +window.location.href = "index.html"; +return; +} +} - // 2. Generar Sidebar y Header - renderSidebar(); - renderHeader(); +// 2. Generar Sidebar y Header +renderSidebar(); +renderHeader(); - // 3. Inicializar Iconos - if (window.lucide) lucide.createIcons(); +// 3. Inicializar Iconos +if (window.lucide) lucide.createIcons(); - // 4. Datos usuario - if (token) setupUserInfo(token); +// 4. Datos usuario +if (token) setupUserInfo(token); }); // --- GENERADOR DE BARRA LATERAL (CON EL NUEVO ENLACE) --- function renderSidebar() { - const container = document.getElementById('sidebar-container'); - if (!container) return; +const container = document.getElementById('sidebar-container'); +if (!container) return; - const path = window.location.pathname.split("/").pop() || "index.html"; +const path = window.location.pathname.split("/").pop() || "index.html"; - const menuItems = [ - { name: "Dashboard", link: "panel.html", icon: "layout-dashboard" }, - { name: "Servicios", link: "servicios.html", icon: "briefcase" }, - { name: "Citas / Bloqueos", link: "agenda.html", icon: "calendar-clock" }, - { name: "Proveedores", link: "proveedores.html", icon: "building-2" }, - { name: "Calendario", link: "calendario.html", icon: "calendar" }, - // --- NUEVO APARTADO --- - { name: "Planes de Protección", link: "proteccion.html", icon: "shield-check" }, - // ---------------------- - { name: "Clientes", link: "clientes.html", icon: "users" }, - { name: "Contabilidad", link: "contabilidad.html", icon: "wallet" }, - { name: "Trazabilidad", link: "trazabilidad.html", icon: "activity" }, - { name: "Usuarios", link: "usuarios.html", icon: "user-cog" }, - { name: "Automatizaciones", link: "automatizaciones.html", icon: "zap" }, - { name: "Configuración", link: "configuracion.html", icon: "settings" }, - ]; +const menuItems = [ +{ name: "Dashboard", link: "panel.html", icon: "layout-dashboard" }, +{ name: "Servicios", link: "servicios.html", icon: "briefcase" }, +{ name: "Citas / Bloqueos", link: "agenda.html", icon: "calendar-clock" }, +{ name: "Proveedores", link: "proveedores.html", icon: "building-2" }, +{ name: "Calendario", link: "calendario.html", icon: "calendar" }, +// --- NUEVO APARTADO --- +{ name: "Planes de Protección", link: "proteccion.html", icon: "shield-check" }, +// ---------------------- +{ name: "Clientes", link: "clientes.html", icon: "users" }, +{ name: "Contabilidad", link: "contabilidad.html", icon: "wallet" }, +{ name: "Trazabilidad", link: "trazabilidad.html", icon: "activity" }, +{ name: "Usuarios", link: "usuarios.html", icon: "user-cog" }, +{ name: "Automatizaciones", link: "automatizaciones.html", icon: "zap" }, +{ name: "Recordatorios", link: "recordatorios-automaticos.html", icon: "bell-ring" }, +{ name: "Configuración", link: "configuracion.html", icon: "settings" }, +]; - const linksHtml = menuItems.map(item => { - const isActive = path === item.link; - const baseClasses = "nav-item flex items-center gap-3 px-4 py-3 rounded-lg transition-all text-sm font-medium"; - const activeClasses = isActive - ? "bg-blue-600 text-white shadow-lg shadow-blue-500/30" - : "text-slate-400 hover:text-white hover:bg-slate-800"; +const linksHtml = menuItems.map(item => { +const isActive = path === item.link; +const baseClasses = "nav-item flex items-center gap-3 px-4 py-3 rounded-lg transition-all text-sm font-medium"; +const activeClasses = isActive +? "bg-blue-600 text-white shadow-lg shadow-blue-500/30" +: "text-slate-400 hover:text-white hover:bg-slate-800"; - return ` - - - ${item.name} - - `; - }).join(""); +return ` + + +${item.name} + +`; +}).join(""); - // El resto del código de renderSidebar permanece igual... - container.innerHTML = ` - - `; +// El resto del código de renderSidebar permanece igual... +container.innerHTML = ` + +`; } // --- GENERADOR DE CABECERA (HEADER) --- function renderHeader() { - const container = document.getElementById('header-container'); - if (!container) return; +const container = document.getElementById('header-container'); +if (!container) return; - // Fecha actual - const dateStr = new Date().toLocaleDateString('es-ES', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); - const dateCapitalized = dateStr.charAt(0).toUpperCase() + dateStr.slice(1); +// Fecha actual +const dateStr = new Date().toLocaleDateString('es-ES', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); +const dateCapitalized = dateStr.charAt(0).toUpperCase() + dateStr.slice(1); - container.innerHTML = ` -
-
- - ${dateCapitalized} -
- -
- -
- U -
-
-
- `; +container.innerHTML = ` +
+
+ +${dateCapitalized} +
+ +
+ +
+U +
+
+
+`; } // --- UTILIDADES --- function setupUserInfo(token) { - try { - const payload = JSON.parse(atob(token.split('.')[1])); - const nameEl = document.getElementById("headerUserName"); - const roleEl = document.getElementById("headerUserRole"); - const avatarEl = document.getElementById("headerUserAvatar"); +try { +const payload = JSON.parse(atob(token.split('.')[1])); +const nameEl = document.getElementById("headerUserName"); +const roleEl = document.getElementById("headerUserRole"); +const avatarEl = document.getElementById("headerUserAvatar"); - if (nameEl) nameEl.innerText = payload.email || "Usuario"; - if (roleEl) roleEl.innerText = (payload.role || "Operario").toUpperCase(); - if (avatarEl) avatarEl.innerText = (payload.email?.[0] || "U").toUpperCase(); - } catch (e) { - localStorage.removeItem("token"); - } +if (nameEl) nameEl.innerText = payload.email || "Usuario"; +if (roleEl) roleEl.innerText = (payload.role || "Operario").toUpperCase(); +if (avatarEl) avatarEl.innerText = (payload.email?.[0] || "U").toUpperCase(); +} catch (e) { +localStorage.removeItem("token"); +} } function logout() { - if(confirm("¿Cerrar sesión?")) { - localStorage.removeItem("token"); - window.location.href = "index.html"; - } -} \ No newline at end of file +if(confirm("¿Cerrar sesión?")) { +localStorage.removeItem("token"); +window.location.href = "index.html"; +} +}