fixxed status-anzeige

This commit is contained in:
oberon 2026-02-12 10:47:43 +01:00
parent 9e0ed92589
commit 30402d12fd
2 changed files with 47 additions and 13 deletions

View File

@ -2,28 +2,59 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// ── Status-Anzeige ─────────────────────────────────────────────────────────
const statusBadge = document.getElementById('connection-status'); const statusBadge = document.getElementById('connection-status');
function updateStatus(connected) { function updateStatus(connected, message = '') {
if (!statusBadge) return; if (!statusBadge) return;
if (connected) { if (connected) {
statusBadge.className = 'badge bg-success px-3 py-2'; statusBadge.className = 'badge bg-success px-3 py-2 fs-6';
statusBadge.innerHTML = '<i class="bi bi-circle-fill me-2"></i> Verbunden'; statusBadge.innerHTML = '<i class="bi bi-circle-fill me-2"></i> Verbunden' + (message ? ` ${message}` : '');
reconnectSection.style.display = 'none'; if (reconnectSection) reconnectSection.style.display = 'none';
} else { } else {
statusBadge.className = 'badge bg-danger px-3 py-2'; statusBadge.className = 'badge bg-danger px-3 py-2 fs-6';
statusBadge.innerHTML = '<i class="bi bi-circle-fill me-2"></i> Getrennt'; statusBadge.innerHTML = '<i class="bi bi-circle-fill me-2"></i> Getrennt' + (message ? ` ${message}` : '');
showReconnect(); if (reconnectSection) reconnectSection.style.display = 'block';
} }
} }
// Nach erfolgreichem Connect / Reconnect // Initialer Status
// in if (result.success) { ... }
updateStatus(true);
// Nach Fehler in sendControl (z. B. am Ende von sendControl)
updateStatus(false); updateStatus(false);
// ── Automatische Verbindungsprüfung ────────────────────────────────────────
let connectionCheckInterval = null;
function startConnectionCheck() {
if (connectionCheckInterval) clearInterval(connectionCheckInterval);
connectionCheckInterval = setInterval(async () => {
try {
// Leichter Dummy-Befehl oder Status-Abfrage (hier nur ein Ping-ähnlicher GET)
// Du kannst später eine echte /api/status-Route bauen
const res = await fetch('/api/control', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ port: 'ping', value: 0 }) // Dummy → wird ignoriert
});
if (!res.ok) {
throw new Error('Status-Check fehlgeschlagen');
}
updateStatus(true);
} catch (err) {
console.warn('Verbindungs-Check fehlgeschlagen:', err);
updateStatus(false, 'Verbindung verloren');
}
}, 8000); // alle 8 Sekunden
}
// Stop-Intervall beim Verlassen der Seite
window.addEventListener('beforeunload', () => {
if (connectionCheckInterval) clearInterval(connectionCheckInterval);
});
const config = window.mkConfig || {}; const config = window.mkConfig || {};
console.log("app.js verwendet config:", config); console.log("app.js verwendet config:", config);
console.log('MK Control Frontend geladen'); console.log('MK Control Frontend geladen');
@ -167,6 +198,9 @@ connectBtn.addEventListener('click', async () => {
console.log("→ Beginne mit Rendern von", config.channels.length, "Kanälen"); console.log("→ Beginne mit Rendern von", config.channels.length, "Kanälen");
startConnectionCheck();
updateStatus(true);
// function renderChannels() { // function renderChannels() {
// if (!channelsContainer) return; // if (!channelsContainer) return;
// channelsContainer.innerHTML = ''; // channelsContainer.innerHTML = '';

View File

@ -32,7 +32,7 @@
<!-- Status-Anzeige --> <!-- Status-Anzeige -->
<div class="position-fixed top-0 end-0 m-3" style="z-index: 1050;"> <div class="position-fixed top-0 end-0 m-3" style="z-index: 1050;">
<div id="connection-status" class="badge bg-secondary px-3 py-2"> <div id="connection-status" class="badge bg-secondary px-3 py-2 fs-6">
<i class="bi bi-circle-fill me-2 text-muted"></i> Nicht verbunden <i class="bi bi-circle-fill me-2 text-muted"></i> Nicht verbunden
</div> </div>
</div> </div>