/** * Navigation Component * Sidebar navigation and user menu */ const MENU_ICON = ``; const ICONS = { calendar: ``, users: ``, rules: ``, user: ``, building: ``, settings: `` }; const NAV_ITEMS = [ { href: '/presence', icon: 'calendar', label: 'La mia presenza' }, { href: '/team-calendar', icon: 'users', label: 'Calendario del team' }, { href: '/team-rules', icon: 'rules', label: 'Regole parcheggio', roles: ['admin', 'manager'] }, { href: '/admin/users', icon: 'user', label: 'Gestione Utenti', roles: ['admin'] }, { href: '/admin/offices', icon: 'building', label: 'Gestione Uffici', roles: ['admin'] }, { href: '/parking-settings', icon: 'settings', label: 'Impostazioni Ufficio', roles: ['admin', 'manager'] } ]; function getIcon(name) { return ICONS[name] || ''; } function canAccessNavItem(item, userRole) { if (!item.roles || item.roles.length === 0) return true; return userRole && item.roles.includes(userRole); } function renderNav(currentPath, userRole) { return NAV_ITEMS .filter(item => canAccessNavItem(item, userRole)) .map(item => { const isActive = item.href === currentPath || (currentPath !== '/' && item.href !== '/' && currentPath.startsWith(item.href)); const activeClass = isActive ? ' active' : ''; return ` ${getIcon(item.icon)} ${item.label} `; }).join('\n'); } async function initNav() { const navContainer = document.querySelector('.sidebar-nav'); if (!navContainer) return; const currentPath = window.location.pathname; // Get user info (works with both JWT and Authelia) const currentUser = await api.checkAuth(); // Update user info in sidebar if (currentUser) { const userNameEl = document.getElementById('userName'); const userRoleEl = document.getElementById('userRole'); if (userNameEl) userNameEl.textContent = currentUser.name || 'User'; if (userRoleEl) userRoleEl.textContent = currentUser.role || '-'; } // Setup user menu (logout) & mobile menu setupUserMenu(); setupMobileMenu(); // CHECK: Block access if user has no office (and is not admin) // Admins are allowed to access "Gestione Uffici" even without an office if (currentUser && !currentUser.office_id && currentUser.role !== 'admin') { navContainer.innerHTML = ''; // Clear nav const mainContent = document.querySelector('.main-content'); if (mainContent) { mainContent.innerHTML = `
Il tuo account ${currentUser.email} รจ attivo, ma non sei ancora stato assegnato a nessuno ufficio.