Files
Aruba-PoE/srv/poe_manager/templates/logs.html

64 lines
2.0 KiB
HTML

{% extends "base.html" %}
{% block content %}
<h2>Live Log</h2>
<button id="refresh-btn" class="btn btn-success mb-3">
<span style="font-size: 1.2rem; color: white;"></span> Logs aktualisieren
</button>
<div id="log-container">
<div id="log-box"></div>
<div id="refresh-timer">
Nächstes Update in <span id="timer"></span> Sekunden
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
// --- Seitentitel setzen ---
const baseTitle = document.title.split(" - ")[0];
document.title = baseTitle + " - Live Log";
// --- Intervallwerte ---
const intervalMinutes = {{ interval | int }};
const intervalMilliseconds = intervalMinutes * 60 * 1000;
let lastUpdateTime = Date.now();
// --- Log laden ---
function fetchLog() {
fetch("{{ url_for('get_log') }}")
.then(response => response.text())
.then(data => {
const box = document.getElementById("log-box");
const filteredLines = data
.split("\n")
.filter(line => !line.includes("ist erreichbar!"))
.join("\n");
box.innerText = filteredLines;
box.scrollTop = box.scrollHeight;
lastUpdateTime = Date.now();
})
.catch(err => console.error("Fehler beim Laden der Logs:", err));
}
// --- Timer aktualisieren ---
function updateTimer() {
const now = Date.now();
const remainingMs = intervalMilliseconds - (now - lastUpdateTime);
const remainingSec = Math.max(Math.ceil(remainingMs / 1000), 0);
document.getElementById("timer").innerText = remainingSec;
}
// --- Button klick ---
document.getElementById("refresh-btn").addEventListener("click", fetchLog);
// --- Initial starten ---
setInterval(updateTimer, 1000);
fetchLog();
setInterval(fetchLog, intervalMilliseconds);
});
</script>
{% endblock %}