diff --git a/README.md b/README.md index c76b156..ae0f616 100644 --- a/README.md +++ b/README.md @@ -106,9 +106,9 @@ Falls weder Kommandozeilenparameter noch Umgebungsvariable gesetzt sind, wird Po - Das System sendet automatisch ein Wake-on-LAN Paket ### Online-Status prüfen (Ping) -- Klicken Sie auf den Button "Status aktualisieren" in der Tabelle -- Die Online/Offline-Badges werden pro Gerät aktualisiert -- Optional kann ein automatisches Intervall ergänzt werden (siehe Entwicklung) +- Beim Laden der Seite wird automatisch der Status abgefragt +- Alle 30 Sekunden wird der Status automatisch aktualisiert +- Zusätzlich können Sie manuell über den Button "Status aktualisieren" aktualisieren ### PC löschen - Klicken Sie auf den "Löschen"-Button neben dem gewünschten PC diff --git a/web/static/script.js b/web/static/script.js index bc41684..24b45c7 100644 --- a/web/static/script.js +++ b/web/static/script.js @@ -5,12 +5,15 @@ class PCManager { this.allPCs = []; // Alle PCs im Speicher this.filteredPCs = []; // Gefilterte PCs this.searchTerm = ''; // Aktueller Suchbegriff + this.statusTimer = null; // Intervall für Auto-Status + this.refreshing = false; // Guard gegen parallele Status-Requests this.init(); } init() { this.loadPCs(); this.setupEventListeners(); + this.startAutoStatus(); } setupEventListeners() { @@ -55,6 +58,8 @@ class PCManager { this.allPCs = data.pcs; this.filteredPCs = [...this.allPCs]; this.displayPCs(); + // Ersten Status direkt nach dem Laden abfragen + this.refreshStatus(); } else { this.showNotification('Fehler', data.message, 'danger'); } @@ -63,6 +68,15 @@ class PCManager { } } + startAutoStatus() { + if (this.statusTimer) { + clearInterval(this.statusTimer); + } + this.statusTimer = setInterval(() => { + this.refreshStatus(); + }, 30000); // alle 30 Sekunden + } + searchPCs(searchTerm) { this.searchTerm = searchTerm.toLowerCase().trim(); @@ -304,6 +318,8 @@ class PCManager { } async refreshStatus() { + if (this.refreshing) return; + this.refreshing = true; try { const response = await fetch('/api/pcs/status'); const data = await response.json(); @@ -327,6 +343,8 @@ class PCManager { } } catch (error) { this.showNotification('Fehler', 'Fehler beim Aktualisieren des Online-Status', 'danger'); + } finally { + this.refreshing = false; } }