From 30a3460ab0675ef94ca6ec7ec6687be33e0af8ca Mon Sep 17 00:00:00 2001 From: Andrei Smaliak Date: Wed, 18 Mar 2026 07:18:38 +0400 Subject: [PATCH] feat(ui): add Cockpit service with provider + Open actions; improve Zigbee2MQTT access; unify device header (Updated inside ID/Hostname block) --- stage_ui/console_core/frontend/console.css | 30 ++++- stage_ui/console_core/frontend/console.js | 114 +++++++++++++++--- stage_ui/console_core/frontend/index.html | 4 + stage_ui/console_core/providers/10_cockpit.py | 80 ++++++++++++ 4 files changed, 210 insertions(+), 18 deletions(-) create mode 100644 stage_ui/console_core/providers/10_cockpit.py diff --git a/stage_ui/console_core/frontend/console.css b/stage_ui/console_core/frontend/console.css index 590befb..067a291 100644 --- a/stage_ui/console_core/frontend/console.css +++ b/stage_ui/console_core/frontend/console.css @@ -38,7 +38,18 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;padding:14px 16px;min-width:300px; } .identityItem{display:flex;flex-direction:column;gap:4px} +.identityItemWide{ + grid-column:1 / -1; + padding-top:6px; +} .identityItem strong{font-size:15px} +.actions{ + display:flex; + align-items:center; + justify-content:flex-end; + gap:12px; + flex-wrap:wrap; +} .actions button{ border:0;border-radius:999px;background:var(--ink);color:#fff;padding:12px 18px;font-weight:700;cursor:pointer; box-shadow:var(--shadow); @@ -94,18 +105,17 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e .sectionHead{display:flex;justify-content:space-between;gap:12px;align-items:flex-end;flex-wrap:wrap} .sectionHead h2{margin:0;font-size:22px} .sectionHead p{margin:0;color:var(--muted)} -.summaryGrid{ - display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;padding:16px 18px; -} -.summaryItem{display:flex;flex-direction:column;gap:4px} .label{font-size:12px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)} .cards{ display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:16px; } .wideCard{grid-column:span 2} .card{padding:18px} +.cards > .card{height:100%} .cardTop{display:flex;justify-content:space-between;gap:12px;align-items:flex-start} +.serviceCard{display:flex;flex-direction:column} .card h2{margin:0;font-size:19px} +.cardSubtitle{margin:6px 0 0;color:var(--muted);font-size:13px} .badge{ display:inline-flex;align-items:center;gap:8px;border-radius:999px;padding:7px 10px;font-size:12px;font-weight:700; background:#edf4f0;color:var(--ink); @@ -116,8 +126,13 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e .dot.error{background:var(--error)} .meta{display:grid;grid-template-columns:140px 1fr;gap:8px 10px;margin-top:16px;font-size:13px} .compactMeta{margin-top:0} +.splitMeta{ + display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px;margin-top:16px; +} +.splitMeta section{min-width:0} .meta .key{color:var(--muted)} .list{margin-top:14px;padding-top:14px;border-top:1px solid var(--line)} +.serviceCard .list:last-of-type{margin-top:auto} .listTitle{font-size:12px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);margin-bottom:8px} .pillRow{display:flex;gap:8px;flex-wrap:wrap} .pill{ @@ -155,11 +170,17 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e .actionRow{display:flex;gap:10px;flex-wrap:wrap} .actionBtn{ border:0;border-radius:12px;background:var(--ink);color:#fff;padding:10px 14px;font-weight:700;cursor:pointer; + display:inline-flex;align-items:center;justify-content:center;text-decoration:none; } .actionBtn:hover:not(:disabled){background:#22302b} .actionBtn.secondary{background:#eef3f1;color:var(--ink);border:1px solid var(--line)} .actionBtn.secondary:hover:not(:disabled){background:#e4ece8} .actionBtn:disabled{opacity:.5;cursor:not-allowed} +.serviceActionRow{align-items:center} +.actionBadge{ + display:inline-flex;align-items:center;border-radius:999px;padding:6px 10px; + background:#edf3f1;color:var(--muted);font-size:12px;font-weight:700; +} .apForm{display:grid;gap:12px} .field{display:grid;gap:6px;font-size:13px;color:var(--ink)} .field input{ @@ -224,6 +245,7 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e @media (max-width:720px){ .summaryGrid{grid-template-columns:1fr} .meta{grid-template-columns:1fr 1fr} + .splitMeta{grid-template-columns:1fr} .brandLogo{width:58px;height:58px} .wideCard,.displayCard,.accessPointCard{grid-column:auto} .displayHeroText{font-size:18px} diff --git a/stage_ui/console_core/frontend/console.js b/stage_ui/console_core/frontend/console.js index 17dd254..858a8e9 100644 --- a/stage_ui/console_core/frontend/console.js +++ b/stage_ui/console_core/frontend/console.js @@ -7,6 +7,7 @@ edgeId: document.getElementById("edgeId"), hostName: document.getElementById("hostName"), osLabel: document.getElementById("osLabel"), + updatedAt: document.getElementById("updatedAt"), content: document.getElementById("tabContent") }; @@ -127,6 +128,32 @@ `; } + function renderHealthOverviewPanel(metrics, temps) { + const thermalRows = temps.length + ? temps.map((item) => ({ label: item.name, value: item.label || "not available" })) + : [{ label: "Sensors", value: "not available" }]; + + return ` +
+
+
+

Health Overview

+
+
+
+
+
Summary
+
${renderKeyValueRows(metrics)}
+
+
+
Thermals
+
${renderKeyValueRows(thermalRows)}
+
+
+
+ `; + } + function renderDisplayCard(card) { const tone = statusTone(card); const warnings = Array.isArray(card.warnings) ? card.warnings : []; @@ -355,6 +382,50 @@ `; } + function currentHostName() { + return textValue(state.status && state.status.identity && state.status.identity.hostname, window.location.hostname || "localhost"); + } + + function serviceOpenTarget(card) { + const host = currentHostName(); + if (card.id === "zigbee2mqtt") { + return { + label: "Open", + href: `http://${host}:8081`, + disabled: !card.installed, + title: "Open Zigbee2MQTT Web UI", + badge: ":8081" + }; + } + if (card.id === "cockpit") { + return { + label: "Open", + href: `https://${host}:9090`, + disabled: !card.installed, + title: "Open Cockpit Web UI", + badge: ":9090" + }; + } + return null; + } + + function renderServiceActions(card) { + const action = serviceOpenTarget(card); + if (!action) return ""; + return ` +
+
Actions
+
+ ${action.disabled + ? `` + : `${esc(action.label)}` + } + ${action.badge ? `${esc(action.badge)}` : ""} +
+
+ `; + } + function renderServiceCard(card) { if (card.id === "display") return renderDisplayCard(card); if (card.id === "access_point") return renderAccessPointCard(card); @@ -365,10 +436,11 @@ const details = Array.isArray(card.details) ? card.details : []; return ` -
+

${esc(card.title)}

+ ${card.subtitle ? `

${esc(card.subtitle)}

` : ""}
${esc(card.status_text || card.state || "Unknown")}
@@ -386,6 +458,7 @@ ${boolPill("Active", !!card.active)} + ${renderServiceActions(card)} ${warnings.length ? `
Warnings
    ${warnings.map((x) => `
  • ${esc(x)}
  • `).join("")}
` : ""} ${errors.length ? `
Errors
    ${errors.map((x) => `
  • ${esc(x)}
  • `).join("")}
` : ""}
@@ -401,23 +474,29 @@ { label: "Disk usage", value: health.disk && health.disk.used_percent !== undefined ? `${health.disk.used_percent}% used` : "Not available" } ]; const temps = Array.isArray(health.temperatures) ? health.temperatures : []; - const serviceCards = (payload.services || []).filter((card) => card.id !== "access_point"); + const serviceCards = (payload.services || []) + .filter((card) => card.id !== "access_point") + .sort((left, right) => { + const order = { + itscreen: 10, + mosquitto: 20, + mqtt_bridge: 30, + zigbee2mqtt: 40, + cockpit: 50, + reverse_tunnel: 60, + display: 70, + edge_api: 80 + }; + const leftOrder = order[left.id] ?? 1000; + const rightOrder = order[right.id] ?? 1000; + if (leftOrder !== rightOrder) return leftOrder - rightOrder; + return (left.title || left.id || "").localeCompare(right.title || right.id || ""); + }); return `
-
-
Providers${esc(String((payload.providers || []).length))}
-
Cards${esc(String((payload.services || []).length))}
-
Updated${esc(formatUtc(payload.generated_at))}
-
-
- ${renderSimplePanel("Health Summary", metrics, "wideCard")} - ${renderSimplePanel( - "Thermals", - temps.length ? temps.map((item) => ({ label: item.name, value: item.label || "not available" })) : [{ label: "Sensors", value: "not available" }], - "wideCard" - )} + ${renderHealthOverviewPanel(metrics, temps)}
@@ -636,6 +715,12 @@ nodes.osLabel.textContent = safe.os_label || "IOMATEX Edge OS"; } + function updateHeaderMeta(payload) { + if (nodes.updatedAt) { + nodes.updatedAt.textContent = formatUtc(payload && payload.generated_at); + } + } + async function fetchJson(url, options) { const response = await fetch(url, options || { cache: "no-store" }); const payload = await response.json().catch(() => ({})); @@ -648,6 +733,7 @@ async function loadStatus() { state.status = await fetchJson("/api/status", { cache: "no-store" }); updateIdentity(state.status.identity || {}); + updateHeaderMeta(state.status); } async function loadHealth() { diff --git a/stage_ui/console_core/frontend/index.html b/stage_ui/console_core/frontend/index.html index f58e080..8ce9cf8 100644 --- a/stage_ui/console_core/frontend/index.html +++ b/stage_ui/console_core/frontend/index.html @@ -28,6 +28,10 @@ Hostname -
+
+ Updated + - +
diff --git a/stage_ui/console_core/providers/10_cockpit.py b/stage_ui/console_core/providers/10_cockpit.py new file mode 100644 index 0000000..e854e0c --- /dev/null +++ b/stage_ui/console_core/providers/10_cockpit.py @@ -0,0 +1,80 @@ +def _systemctl_flag(ctx, unit_name, command): + rc, stdout, stderr = ctx["run"](["systemctl", command, unit_name], timeout=8) + text = (stdout or stderr or "").strip().lower() + if rc == 0: + return True, text or "enabled" + return False, text + + +def _which(ctx, binary_name): + rc, stdout, _ = ctx["run"](["which", binary_name], timeout=8) + return rc == 0 and bool((stdout or "").strip()) + + +def _cockpit_status(socket_unit, service_unit): + if socket_unit["active_state"] == "failed" or service_unit["active_state"] == "failed": + return "failed", "Error" + if socket_unit["active"] or service_unit["active"]: + return "active", "Active" + return "inactive", "Not running" + + +def get_cards(ctx): + socket_unit = ctx["systemd_unit"]("cockpit.socket") + service_unit = ctx["systemd_unit"]("cockpit.service") + cockpit_ws_present = _which(ctx, "cockpit-ws") + installed = bool(cockpit_ws_present or socket_unit["installed"] or service_unit["installed"]) + + if not installed: + return [{ + "id": "cockpit", + "title": "Cockpit", + "subtitle": "System administration", + "installed": False, + "configured": False, + "active": False, + "state": "not installed", + "status_text": "Not installed", + "warnings": [], + "errors": [], + "details": [ + {"label": "Listener", "value": "cockpit.socket"}, + {"label": "Enabled", "value": "No"}, + {"label": "Web UI", "value": "https://:9090"}, + ], + }] + + enabled, enabled_text = _systemctl_flag(ctx, "cockpit.socket", "is-enabled") + active = bool(socket_unit["active"] or service_unit["active"]) + state, status_text = _cockpit_status(socket_unit, service_unit) + listener = "cockpit.socket" if socket_unit["installed"] else "cockpit.service" + errors = [] + warnings = [] + + if state == "failed": + errors.append("Cockpit unit failed") + elif not active: + warnings.append("Cockpit web service is not running") + + if not enabled and enabled_text and enabled_text not in ("disabled", "masked"): + warnings.append(f"socket state: {enabled_text}") + + return [{ + "id": "cockpit", + "title": "Cockpit", + "subtitle": "System administration", + "installed": True, + "configured": True, + "active": active, + "state": state, + "status_text": status_text, + "warnings": warnings[:2], + "errors": errors[:2], + "details": [ + {"label": "Listener", "value": listener}, + {"label": "socket state", "value": socket_unit["active_state"] or "inactive"}, + {"label": "service state", "value": service_unit["active_state"] or "inactive"}, + {"label": "Enabled", "value": "Yes" if enabled else "No"}, + {"label": "Web UI", "value": "https://:9090"}, + ], + }]