srv/poe_manager/templates/index.html aktualisiert
This commit is contained in:
@@ -34,16 +34,9 @@
|
|||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
const intervalMinutes = {{ interval | int }};
|
const intervalMinutes = {{ interval | int }};
|
||||||
const intervalMilliseconds = intervalMinutes * 60 * 1000;
|
const intervalMilliseconds = intervalMinutes * 60 * 1000;
|
||||||
let lastUpdateTime = Date.now();
|
let lastUpdateTime = Date.now(); // Startpunkt beim Laden der Seite
|
||||||
let reloadCountdown = null;
|
let reloadCountdown = null;
|
||||||
let reloadTriggered = false; // verhindert endlose Reloads
|
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();
|
||||||
@@ -63,13 +56,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
reloadCountdown--;
|
reloadCountdown--;
|
||||||
|
|
||||||
if (reloadCountdown < 0) {
|
if (reloadCountdown < 0) {
|
||||||
reloadTriggered = true; // Reload nur einmal ausführen
|
reloadTriggered = true;
|
||||||
window.location.reload(); // Seite neu laden
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initiale Synchronisierung mit letzter Log-Zeit optional
|
||||||
function fetchLastLog() {
|
function fetchLastLog() {
|
||||||
fetch("{{ url_for('get_log') }}")
|
fetch("{{ url_for('get_log') }}")
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
@@ -85,7 +79,12 @@ 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) lastUpdateTime = parseLogTimestamp(match[1]);
|
if (match) {
|
||||||
|
const logTime = new Date(match[1]).getTime();
|
||||||
|
// Nur Offset setzen, damit Haupt-Timer beim Laden nicht sofort abläuft
|
||||||
|
const offset = Math.min(Date.now() - logTime, intervalMilliseconds);
|
||||||
|
lastUpdateTime = Date.now() - offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.error("Fehler beim Laden der Logs:", err));
|
.catch(err => console.error("Fehler beim Laden der Logs:", err));
|
||||||
@@ -96,5 +95,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user