srv/poe_manager/templates/index.html aktualisiert
This commit is contained in:
@@ -32,37 +32,24 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
const intervalMinutes = {{ interval | int }};
|
const intervalMinutes = {{ interval | int }}; // aus DB
|
||||||
const intervalMilliseconds = intervalMinutes * 60 * 1000;
|
const intervalMilliseconds = intervalMinutes * 60 * 1000;
|
||||||
let lastUpdateTime = Date.now(); // Standard: jetzt
|
let lastUpdateTime = Date.now();
|
||||||
let reloadCountdown = null;
|
|
||||||
let reloadTriggered = false;
|
function parseLogTimestamp(ts) {
|
||||||
|
const parts = ts.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
||||||
|
if (!parts) return Date.now();
|
||||||
|
const [, year, month, day, hour, minute, second] = parts.map(Number);
|
||||||
|
return new Date(year, month - 1, day, hour, minute, second).getTime();
|
||||||
|
}
|
||||||
|
|
||||||
function updateTimer() {
|
function updateTimer() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const elapsed = now - lastUpdateTime;
|
const elapsed = now - lastUpdateTime;
|
||||||
const timerElem = document.getElementById("dashboard-timer");
|
const remainingMs = intervalMilliseconds - (elapsed % intervalMilliseconds);
|
||||||
|
const remainingSec = Math.ceil(remainingMs / 1000);
|
||||||
if (elapsed < intervalMilliseconds) {
|
document.getElementById("dashboard-timer").innerText =
|
||||||
// Haupt-Timer läuft
|
`Nächste Prüfung in ${remainingSec} Sekunden`;
|
||||||
const remainingSec = Math.ceil((intervalMilliseconds - elapsed) / 1000);
|
|
||||||
timerElem.innerText = `Nächste Prüfung in ${remainingSec} Sekunden`;
|
|
||||||
timerElem.classList.remove("reload");
|
|
||||||
} else {
|
|
||||||
// Haupt-Timer abgelaufen → Reload-Timer starten
|
|
||||||
if (reloadCountdown === null) reloadCountdown = 10;
|
|
||||||
|
|
||||||
if (!reloadTriggered) {
|
|
||||||
timerElem.innerText = `Aktualisieren der Seite in ${reloadCountdown} Sekunden`;
|
|
||||||
timerElem.classList.add("reload");
|
|
||||||
reloadCountdown--;
|
|
||||||
|
|
||||||
if (reloadCountdown < 0) {
|
|
||||||
reloadTriggered = true;
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchLastLog() {
|
function fetchLastLog() {
|
||||||
@@ -80,21 +67,16 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
if (lastSepIndex >= 0 && lastSepIndex + 1 < lines.length) {
|
if (lastSepIndex >= 0 && lastSepIndex + 1 < lines.length) {
|
||||||
const firstLine = lines[lastSepIndex + 1];
|
const firstLine = lines[lastSepIndex + 1];
|
||||||
const match = firstLine.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/);
|
const match = firstLine.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/);
|
||||||
if (match) {
|
if (match) lastUpdateTime = parseLogTimestamp(match[1]);
|
||||||
const logTime = new Date(match[1]).getTime();
|
|
||||||
// Wenn Log älter als Intervall → Timer jetzt starten
|
|
||||||
if (Date.now() - logTime < intervalMilliseconds) {
|
|
||||||
lastUpdateTime = logTime;
|
|
||||||
} else {
|
|
||||||
lastUpdateTime = Date.now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.error("Fehler beim Laden der Logs:", err));
|
.catch(err => console.error("Fehler beim Laden der Logs:", err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timer alle 1 Sekunde aktualisieren
|
||||||
setInterval(updateTimer, 1000);
|
setInterval(updateTimer, 1000);
|
||||||
|
|
||||||
|
// einmal beim Laden die letzte Log-Zeit setzen
|
||||||
fetchLastLog();
|
fetchLastLog();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user