srv/poe_manager/templates/index.html aktualisiert
This commit is contained in:
@@ -29,11 +29,18 @@
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const intervalMinutes = {{ interval | int }};
|
||||
const intervalMinutes = {{ interval | int }}; // aus DB
|
||||
const intervalMilliseconds = intervalMinutes * 60 * 1000;
|
||||
let lastUpdateTime = Date.now(); // optional: vom letzten Refresh / Log-Eintrag
|
||||
let lastUpdateTime = Date.now();
|
||||
|
||||
function updateDashboardTimer() {
|
||||
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() {
|
||||
const now = Date.now();
|
||||
const elapsed = now - lastUpdateTime;
|
||||
const remainingMs = intervalMilliseconds - (elapsed % intervalMilliseconds);
|
||||
@@ -41,13 +48,33 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
document.getElementById("dashboard-timer").innerText = remainingSec + " s";
|
||||
}
|
||||
|
||||
// Optional: reset timer beim manuellen Refresh
|
||||
// lastUpdateTime = Date.now();
|
||||
function fetchLastLog() {
|
||||
fetch("{{ url_for('get_log') }}")
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const lines = data.split("\n").filter(line => !line.includes("ist erreichbar!"));
|
||||
let lastSepIndex = -1;
|
||||
for (let i = lines.length - 1; i >= 0; i--) {
|
||||
if (lines[i].startsWith("--------------------------------------------------------------------")) {
|
||||
lastSepIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastSepIndex >= 0 && lastSepIndex + 1 < lines.length) {
|
||||
const firstLine = lines[lastSepIndex + 1];
|
||||
const match = firstLine.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/);
|
||||
if (match) lastUpdateTime = parseLogTimestamp(match[1]);
|
||||
}
|
||||
})
|
||||
.catch(err => console.error("Fehler beim Laden der Logs:", err));
|
||||
}
|
||||
|
||||
setInterval(updateDashboardTimer, 1000);
|
||||
updateDashboardTimer(); // direkt beim Laden
|
||||
// Timer aktualisieren jede Sekunde
|
||||
setInterval(updateTimer, 1000);
|
||||
|
||||
// einmal beim Laden die letzte Log-Zeit setzen
|
||||
fetchLastLog();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user