-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
67 lines (63 loc) · 2.6 KB
/
Copy pathapp.js
File metadata and controls
67 lines (63 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as store from "./core/store.js";
import { start as startWs } from "./core/ws.js";
import { get } from "./core/api.js";
import { el, clear, hhmmss } from "./core/ui.js";
import * as monitor from "./screens/monitor.js";
import * as settings from "./screens/settings.js";
import { mount as mountRunbar } from "./core/runbar.js";
const screens = { monitor, settings };
let teardown = null;
function route() {
const name = location.hash.replace("#", "") || "monitor";
const tab = screens[name] ? name : "monitor";
document.querySelectorAll(".tab").forEach((a) => a.classList.toggle("on", a.dataset.tab === tab));
const root = document.getElementById("screen");
if (typeof teardown === "function") teardown();
root.innerHTML = "";
teardown = screens[tab].mount(root) || null;
}
const ALARM_LABELS = {
sensor_fault: "Liquid probe fault", heater_probe_fault: "Heater probe fault",
safety_tripped: "Safety cutout", driver_ot: "Driver over-temp", driver_otpw: "Driver over-temp warning",
driver_stall: "Motor stall", driver_open_load: "Motor open load",
};
function fstat(k, v) {
return el("div", { class: "fstat" }, el("span", { class: "k" }, k), el("span", { class: "v" }, v));
}
// Connection lamp lives in the masthead; everything else moves to the footer.
function setConn() {
const c = document.getElementById("conn");
if (!c) return;
const on = store.isOnline();
c.className = "lamp " + (on ? "on" : "off");
c.title = on ? "Link up" : "Link down";
}
function renderShell(d) {
setConn();
const footer = document.getElementById("footer");
clear(footer);
const w = d.wifi || {};
const link = w.connected ? (w.ip || "online") : (w.mode === "ap" ? "AP" : "offline");
footer.append(
fstat("LINK", link),
fstat("VBUS", (d.system && d.system.vbus) || "—"),
fstat("SD", d.system && d.system.sdMounted ? "OK" : "—"),
fstat("UPTIME", hhmmss(d.uptimeSec || 0)),
);
const banner = document.getElementById("banner");
const al = d.alarms || [];
if (!al.length) { banner.hidden = true; banner.textContent = ""; }
else {
const crit = al.some((a) => a.severity === "critical");
banner.hidden = false;
banner.className = `banner ${crit ? "critical" : "warn"}`;
banner.textContent = al.map((a) => ALARM_LABELS[a.code] || a.code).join(" · ");
}
}
window.addEventListener("hashchange", route);
store.subscribe(renderShell);
store.subscribeConn(() => { setConn(); const d = store.getStatus(); if (d) renderShell(d); });
mountRunbar(document.getElementById("runbar"));
route();
get("/api/v1/status").then((r) => { if (r.body && r.body.apiVersion) store.setStatus(r.body); });
startWs();