feat(ui): add Cockpit service with provider + Open actions; improve Zigbee2MQTT access; unify device header (Updated inside ID/Hostname block)
This commit is contained in:
parent
af34c2eb02
commit
30a3460ab0
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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 `
|
||||
<article class="panel card wideCard">
|
||||
<div class="cardTop">
|
||||
<div>
|
||||
<h2>Health Overview</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="splitMeta">
|
||||
<section>
|
||||
<div class="listTitle">Summary</div>
|
||||
<div class="meta compactMeta">${renderKeyValueRows(metrics)}</div>
|
||||
</section>
|
||||
<section>
|
||||
<div class="listTitle">Thermals</div>
|
||||
<div class="meta compactMeta">${renderKeyValueRows(thermalRows)}</div>
|
||||
</section>
|
||||
</div>
|
||||
</article>
|
||||
`;
|
||||
}
|
||||
|
||||
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 `
|
||||
<div class="list">
|
||||
<div class="listTitle">Actions</div>
|
||||
<div class="actionRow serviceActionRow">
|
||||
${action.disabled
|
||||
? `<button class="actionBtn" type="button" disabled title="${esc(action.title)}">${esc(action.label)}</button>`
|
||||
: `<a class="actionBtn" href="${esc(action.href)}" target="_blank" rel="noopener noreferrer" title="${esc(action.title)}">${esc(action.label)}</a>`
|
||||
}
|
||||
${action.badge ? `<span class="actionBadge">${esc(action.badge)}</span>` : ""}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
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 `
|
||||
<article class="panel card">
|
||||
<article class="panel card serviceCard">
|
||||
<div class="cardTop">
|
||||
<div>
|
||||
<h2>${esc(card.title)}</h2>
|
||||
${card.subtitle ? `<p class="cardSubtitle">${esc(card.subtitle)}</p>` : ""}
|
||||
<div class="badge"><span class="dot ${tone}"></span>${esc(card.status_text || card.state || "Unknown")}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -386,6 +458,7 @@
|
|||
${boolPill("Active", !!card.active)}
|
||||
</div>
|
||||
</div>
|
||||
${renderServiceActions(card)}
|
||||
${warnings.length ? `<div class="list"><div class="listTitle">Warnings</div><ul class="msgList">${warnings.map((x) => `<li>${esc(x)}</li>`).join("")}</ul></div>` : ""}
|
||||
${errors.length ? `<div class="list"><div class="listTitle">Errors</div><ul class="msgList">${errors.map((x) => `<li>${esc(x)}</li>`).join("")}</ul></div>` : ""}
|
||||
</article>
|
||||
|
|
@ -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 `
|
||||
<section class="tabPanel">
|
||||
<div class="panel summaryGrid">
|
||||
<div class="summaryItem"><span class="label">Providers</span><strong>${esc(String((payload.providers || []).length))}</strong></div>
|
||||
<div class="summaryItem"><span class="label">Cards</span><strong>${esc(String((payload.services || []).length))}</strong></div>
|
||||
<div class="summaryItem"><span class="label">Updated</span><strong>${esc(formatUtc(payload.generated_at))}</strong></div>
|
||||
</div>
|
||||
|
||||
<div class="cards">
|
||||
${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)}
|
||||
</div>
|
||||
|
||||
<div class="sectionHead">
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@
|
|||
<span class="label">Hostname</span>
|
||||
<strong id="hostName">-</strong>
|
||||
</div>
|
||||
<div class="identityItem identityItemWide">
|
||||
<span class="label">Updated</span>
|
||||
<strong id="updatedAt">-</strong>
|
||||
</div>
|
||||
</section>
|
||||
<div class="actions">
|
||||
<button id="refreshBtn" type="button">Refresh</button>
|
||||
|
|
|
|||
|
|
@ -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://<host>: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://<host>:9090"},
|
||||
],
|
||||
}]
|
||||
Loading…
Reference in New Issue