// Main Dashboard Controller class Dashboard { constructor() { this.currentPage = 'overview'; this.init(); } init() { if (!window.authManager || !window.authManager.isAuthenticated) { return; } this.setupNavigation(); this.setupSidebar(); this.setupRefresh(); this.updateTime(); // Load initial page from hash or default to overview const initialPage = window.location.hash.substring(1) || 'overview'; this.loadPage(initialPage); setInterval(() => this.updateTime(), 1000); } setupNavigation() { const menuItems = document.querySelectorAll('.menu-item'); menuItems.forEach(item => { item.onclick = (e) => { e.preventDefault(); const page = item.getAttribute('data-page') || item.getAttribute('href').substring(1); this.loadPage(page); }; }); window.onhashchange = () => { const page = window.location.hash.substring(1) || 'overview'; if (page !== this.currentPage) { this.loadPage(page); } }; } setupSidebar() { const toggleBtn = document.getElementById('sidebar-toggle'); const sidebar = document.querySelector('.sidebar'); const logoutBtn = document.getElementById('logout-btn'); if (toggleBtn && sidebar) { toggleBtn.onclick = () => { sidebar.classList.toggle('collapsed'); localStorage.setItem('sidebar_collapsed', sidebar.classList.contains('collapsed')); }; if (localStorage.getItem('sidebar_collapsed') === 'true') { sidebar.classList.add('collapsed'); } } if (logoutBtn) { logoutBtn.onclick = () => { window.authManager.logout(); }; } } setupRefresh() { const refreshBtn = document.getElementById('refresh-btn'); if (refreshBtn) { refreshBtn.onclick = () => this.refreshCurrentPage(); } } updateTime() { const timeElement = document.getElementById('current-time'); if (timeElement) { timeElement.textContent = luxon.DateTime.now().toFormat('HH:mm:ss'); } } async loadPage(page) { if (window.chartManager) { window.chartManager.destroyAllCharts(); } this.currentPage = page; window.location.hash = page; window.scrollTo(0, 0); // Update menu active state document.querySelectorAll('.menu-item').forEach(item => { item.classList.toggle('active', (item.dataset.page || item.getAttribute('href').substring(1)) === page); }); const titleElement = document.getElementById('page-title'); const titles = { 'overview': 'Overview', 'analytics': 'Analytics', 'costs': 'Costs', 'clients': 'Clients', 'providers': 'Providers', 'monitoring': 'Monitoring', 'settings': 'Settings', 'logs': 'Logs' }; if (titleElement) titleElement.textContent = titles[page] || 'Dashboard'; this.showLoading(); try { const content = document.getElementById('page-content'); if (content) { content.innerHTML = await this.getPageTemplate(page); await this.initializePageScript(page); } } catch (error) { console.error(`Error loading page ${page}:`, error); this.showError(`Failed to load ${page}`); } finally { this.hideLoading(); } } showLoading() { const content = document.getElementById('page-content'); if (content) content.classList.add('loading'); } hideLoading() { const content = document.getElementById('page-content'); if (content) content.classList.remove('loading'); } async getPageTemplate(page) { // Return templates directly based on the page name switch (page) { case 'overview': return this.getOverviewTemplate(); case 'clients': return this.getClientsTemplate(); case 'providers': return this.getProvidersTemplate(); case 'logs': return this.getLogsTemplate(); case 'monitoring': return this.getMonitoringTemplate(); case 'settings': return '
${message}
| Time | Client | Provider | Model | Tokens | Status |
|---|
Manage tokens and access
| ID | Name | Token | Created | Last Used | Requests | Status | Actions |
|---|
| Timestamp | Status | Context | Request Details |
|---|
Live request activity and system metrics