dev #1

Merged
alientim merged 145 commits from dev into main 2025-10-12 13:44:14 +02:00
Showing only changes of commit 225750f6bc - Show all commits

View File

@@ -15,39 +15,44 @@
</div> </div>
<script> <script>
function parseLogTimestamp(ts) {
// ts = "2025-10-08 16:48:16"
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();
}
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(); // wird nach Log-Auswertung gesetzt let lastUpdateTime = Date.now();
function fetchLog() { function fetchLog() {
fetch("{{ url_for('get_log') }}") fetch("{{ url_for('get_log') }}")
.then(response => response.text()) .then(res => res.text())
.then(data => { .then(data => {
const box = document.getElementById("log-box"); const box = document.getElementById("log-box");
const filteredLines = data const filteredLines = data
.split("\n") .split("\n")
.filter(line => !line.includes("ist erreichbar!")); .filter(line => !line.includes("ist erreichbar!"));
box.innerText = filteredLines.join("\n"); box.innerText = filteredLines.join("\n");
box.scrollTop = box.scrollHeight; box.scrollTop = box.scrollHeight;
// letzte Separator-Linie finden // letzte Separator-Linie
let lastSeparatorIndex = -1; let lastSep = -1;
for (let i = filteredLines.length - 1; i >= 0; i--) { for (let i = filteredLines.length - 1; i >= 0; i--) {
if (filteredLines[i].startsWith("--------------------------------------------------------------------")) { if (filteredLines[i].startsWith("--------------------------------------------------------------------")) {
lastSeparatorIndex = i; lastSep = i;
break; break;
} }
} }
// ersten Zeitstempel nach Separator nehmen if (lastSep >= 0 && lastSep + 1 < filteredLines.length) {
if (lastSeparatorIndex >= 0 && lastSeparatorIndex + 1 < filteredLines.length) { const firstLine = filteredLines[lastSep + 1];
const firstLine = filteredLines[lastSeparatorIndex + 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 = new Date(match[1]).getTime(); lastUpdateTime = parseLogTimestamp(match[1]);
} else { } else {
lastUpdateTime = Date.now(); lastUpdateTime = Date.now();
} }
@@ -55,7 +60,7 @@ document.addEventListener("DOMContentLoaded", () => {
lastUpdateTime = Date.now(); lastUpdateTime = Date.now();
} }
}) })
.catch(err => console.error("Fehler beim Laden der Logs:", err)); .catch(err => console.error(err));
} }
function updateTimer() { function updateTimer() {
@@ -72,6 +77,7 @@ document.addEventListener("DOMContentLoaded", () => {
setInterval(fetchLog, intervalMilliseconds); setInterval(fetchLog, intervalMilliseconds);
setInterval(updateTimer, 1000); setInterval(updateTimer, 1000);
}); });
</script> </script>
{% endblock %} {% endblock %}