diff --git a/apps/dashboard/assets/js/renderers/network-health.js b/apps/dashboard/assets/js/renderers/network-health.js index c69bd7c..4c17602 100644 --- a/apps/dashboard/assets/js/renderers/network-health.js +++ b/apps/dashboard/assets/js/renderers/network-health.js @@ -1,84 +1,69 @@ export function renderNetworkHealth(state) { - _renderAdGuard(state.adguard || {}); - _renderScrutiny(state.scrutiny || {}); + renderAdGuard(state.adguard || {}); + renderScrutiny(state.scrutiny || {}); } -function _renderAdGuard(d) { - const online = d.source_status === "online"; +function renderAdGuard(data) { + const online = data.source_status === "online"; + setPill("adguard-pill", online ? "ONLINE" : "OFFLINE", online ? "pill-online" : "pill-offline"); - const pill = document.getElementById("adguard-pill"); - if (pill) { - pill.textContent = online ? "ONLINE" : "OFFLINE"; - pill.className = "status-pill " + (online ? "pill-online" : "pill-offline"); - } + setText("adguard-total", online ? fmtCompact(data.total_queries) : "\u2014"); + setText("adguard-blocked", online ? fmtCompact(data.blocked_queries) : "\u2014"); + setText("adguard-blocked-pct", online ? `${Math.round(data.blocked_percent ?? 0)}%` : "\u2014"); + setText("adguard-latency", online ? `${Math.round(data.avg_processing_ms ?? 0)}ms` : "\u2014"); - const set = (id, val) => { const el = document.getElementById(id); if (el) el.textContent = val; }; - - if (online) { - set("adguard-total", fmtK(d.total_queries)); - set("adguard-blocked", fmtK(d.blocked_queries)); - set("adguard-blocked-pct", `${d.blocked_percent ?? 0}%`); - set("adguard-latency", `${d.avg_processing_ms ?? 0}ms`); - - const bar = document.getElementById("adguard-bar-fill"); - if (bar) bar.style.width = `${Math.min(d.blocked_percent ?? 0, 100)}%`; - } else { - ["adguard-total", "adguard-blocked", "adguard-blocked-pct", "adguard-latency"].forEach(id => set(id, "—")); - const bar = document.getElementById("adguard-bar-fill"); - if (bar) bar.style.width = "0%"; + const fill = document.getElementById("adguard-bar-fill"); + if (fill) { + fill.style.width = `${online ? Math.min(data.blocked_percent ?? 0, 100) : 0}%`; } } -function _renderScrutiny(d) { - const online = d.source_status === "online"; +function renderScrutiny(data) { + const online = data.source_status === "online"; + setPill("scrutiny-pill", online ? "ONLINE" : "OFFLINE", online ? "pill-online" : "pill-offline"); - const pill = document.getElementById("scrutiny-pill"); - if (pill) { - pill.textContent = online ? "ONLINE" : "OFFLINE"; - pill.className = "status-pill " + (online ? "pill-online" : "pill-offline"); - } + const total = data.total_count ?? 0; + const failed = data.failed_count ?? 0; + const passed = Math.max(total - failed, 0); - // stat blocks - const set = (id, val) => { const el = document.getElementById(id); if (el) el.textContent = val; }; - if (online) { - set("scrutiny-total", d.total_count ?? 0); - set("scrutiny-failed", d.failed_count ?? 0); - const passedEl = document.getElementById("scrutiny-passed"); - if (passedEl) { - passedEl.textContent = (d.total_count ?? 0) - (d.failed_count ?? 0); - } - } else { - set("scrutiny-total", "—"); - set("scrutiny-failed", "—"); - set("scrutiny-passed", "—"); - } + setText("scrutiny-total", online ? total : "\u2014"); + setText("scrutiny-passed", online ? passed : "\u2014"); + setText("scrutiny-failed", online ? failed : "\u2014"); - // disk list const list = document.getElementById("scrutiny-list"); if (!list) return; - if (!online || !d.devices || d.devices.length === 0) { - list.innerHTML = `