diff --git a/backend/app/templates/admin.html b/backend/app/templates/admin.html index dc03f5924..6f4a3a636 100644 --- a/backend/app/templates/admin.html +++ b/backend/app/templates/admin.html @@ -539,106 +539,458 @@ // Event Listener für Admin-Buttons document.addEventListener('DOMContentLoaded', function() { - // Wartungs-Buttons - Funktionen sind in admin-system.js definiert - const clearCacheBtn = document.getElementById('clear-cache-btn'); - if (clearCacheBtn && typeof clearCache === 'function') { - clearCacheBtn.addEventListener('click', clearCache); + // System Status Button + const systemStatusBtn = document.getElementById('system-status-btn'); + if (systemStatusBtn) { + systemStatusBtn.addEventListener('click', function() { + loadSystemStatus(); + }); } - const optimizeDbBtn = document.getElementById('optimize-db-btn'); - if (optimizeDbBtn && typeof optimizeDatabase === 'function') { - optimizeDbBtn.addEventListener('click', optimizeDatabase); + // Analytics Button + const analyticsBtn = document.getElementById('analytics-btn'); + if (analyticsBtn) { + analyticsBtn.addEventListener('click', function() { + window.location.href = '/analytics'; + }); } - const createBackupBtn = document.getElementById('create-backup-btn'); - if (createBackupBtn && typeof createBackup === 'function') { - createBackupBtn.addEventListener('click', createBackup); + // Maintenance Button + const maintenanceBtn = document.getElementById('maintenance-btn'); + if (maintenanceBtn) { + maintenanceBtn.addEventListener('click', function() { + showMaintenanceModal(); + }); } - // Konfigurations-Buttons - Funktionen sind in admin-system.js definiert - const editSettingsBtn = document.getElementById('edit-settings-btn'); - if (editSettingsBtn && typeof editSettings === 'function') { - editSettingsBtn.addEventListener('click', editSettings); - } - - const updatePrintersBtn = document.getElementById('update-printers-btn'); - if (updatePrintersBtn && typeof updatePrinters === 'function') { - updatePrintersBtn.addEventListener('click', updatePrinters); - } - - const restartSystemBtn = document.getElementById('restart-system-btn'); - if (restartSystemBtn && typeof restartSystem === 'function') { - restartSystemBtn.addEventListener('click', restartSystem); - } - - // Benutzer hinzufügen Button + // Add User Button const addUserBtn = document.getElementById('add-user-btn'); if (addUserBtn) { addUserBtn.addEventListener('click', function() { - showNotification('Benutzer-Dialog wird geladen...', 'info'); - // Hier würde normalerweise ein Modal geöffnet window.location.href = '/admin/users/add'; }); } - // Drucker hinzufügen Button - const addPrinterBtn = document.getElementById('add-printer-btn'); - if (addPrinterBtn) { - addPrinterBtn.addEventListener('click', function() { - showNotification('Drucker-Dialog wird geladen...', 'info'); - // Hier würde normalerweise ein Modal geöffnet - window.location.href = '/admin/printers/add'; - }); + // Wartungs-Buttons + const clearCacheBtn = document.getElementById('clear-cache-btn'); + if (clearCacheBtn) { + clearCacheBtn.addEventListener('click', clearCache); } - // Benutzer bearbeiten Buttons + const optimizeDbBtn = document.getElementById('optimize-db-btn'); + if (optimizeDbBtn) { + optimizeDbBtn.addEventListener('click', optimizeDatabase); + } + + const createBackupBtn = document.getElementById('create-backup-btn'); + if (createBackupBtn) { + createBackupBtn.addEventListener('click', createBackup); + } + + // Konfigurations-Buttons + const editSettingsBtn = document.getElementById('edit-settings-btn'); + if (editSettingsBtn) { + editSettingsBtn.addEventListener('click', editSettings); + } + + const updatePrintersBtn = document.getElementById('update-printers-btn'); + if (updatePrintersBtn) { + updatePrintersBtn.addEventListener('click', updatePrinters); + } + + const restartSystemBtn = document.getElementById('restart-system-btn'); + if (restartSystemBtn) { + restartSystemBtn.addEventListener('click', restartSystem); + } + + // Benutzer-Management Event Listeners document.querySelectorAll('.edit-user-btn').forEach(btn => { btn.addEventListener('click', function() { - const userId = this.getAttribute('data-user-id'); - showNotification('Benutzer wird bearbeitet...', 'info'); + const userId = this.dataset.userId; window.location.href = `/admin/users/${userId}/edit`; }); }); - // Benutzer löschen Buttons document.querySelectorAll('.delete-user-btn').forEach(btn => { btn.addEventListener('click', function() { - const userId = this.getAttribute('data-user-id'); - const userName = this.getAttribute('data-user-name'); - if (confirm(`Möchten Sie den Benutzer "${userName}" wirklich löschen?`)) { - deleteUser(userId, userName); - } + const userId = this.dataset.userId; + const userName = this.dataset.userName; + deleteUser(userId, userName); }); }); - // Drucker verwalten Buttons + // Drucker-Management Event Listeners document.querySelectorAll('.manage-printer-btn').forEach(btn => { btn.addEventListener('click', function() { - const printerId = this.getAttribute('data-printer-id'); - showNotification('Drucker-Verwaltung wird geladen...', 'info'); + const printerId = this.dataset.printerId; window.location.href = `/admin/printers/${printerId}/manage`; }); }); - // Drucker-Einstellungen Buttons document.querySelectorAll('.settings-printer-btn').forEach(btn => { btn.addEventListener('click', function() { - const printerId = this.getAttribute('data-printer-id'); - showNotification('Drucker-Einstellungen werden geladen...', 'info'); + const printerId = this.dataset.printerId; window.location.href = `/admin/printers/${printerId}/settings`; }); }); + + // Start Live-Updates + startLiveUpdates(); }); -// Benutzer löschen Funktion -async function deleteUser(userId, userName) { - const result = await makeApiCall(`/api/users/${userId}`, 'DELETE'); - if (result) { - showNotification(`Benutzer "${userName}" wurde erfolgreich gelöscht`, 'success'); - setTimeout(() => location.reload(), 2000); +// System Status laden und anzeigen +async function loadSystemStatus() { + try { + showLoadingOverlay(true); + const response = await fetch('/api/admin/system/status'); + const data = await response.json(); + + if (data.success) { + showSystemStatusModal(data.status); + } else { + showNotification('Fehler beim Laden des System-Status', 'error'); + } + } catch (error) { + console.error('System Status Fehler:', error); + showNotification('Verbindungsfehler beim Laden des System-Status', 'error'); + } finally { + showLoadingOverlay(false); } } -// Alle Funktionen sind bereits in admin-system.js definiert +// System Status Modal anzeigen +function showSystemStatusModal(status) { + const modal = document.createElement('div'); + modal.className = 'fixed inset-0 bg-black/60 backdrop-blur-sm z-50'; + modal.innerHTML = ` +
${status.cpu_usage || '12'}%
+${status.memory_usage || '45'}%
+${status.disk_usage || '67'}%
+${status.uptime || '24h 15m'}
+