aboutsummaryrefslogtreecommitdiffstats
path: root/static/dashboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/dashboard.js')
-rw-r--r--static/dashboard.js55
1 files changed, 39 insertions, 16 deletions
diff --git a/static/dashboard.js b/static/dashboard.js
index c6eab3c..1f89da8 100644
--- a/static/dashboard.js
+++ b/static/dashboard.js
@@ -15,13 +15,14 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// The Dashboard tab: a top band of chips, music and spending always on, a
-// row of one to three busy modules, and the action icons. The page keeps the
+// row of chips for one to three busy modules, each opening its full slot,
+// and the action icons. The page keeps the
// trend history; the modules' APIs are the existing ones.
import { offline } from "./offline.js";
export const HISTORY = 120; // trend samples: two minutes at 1 s
-const RUNNING = ["k1c", "sbbuilder", "obs"]; // the running row's order
+const RUNNING = { k1c: "K1C", sbbuilder: "build", obs: "OBS" }; // the running row's order and chip labels
const G = { cpu: "", mem: "\u{f035b}", gpu: "\u{f08ae}", net: "\u{f04e1}",
wifi: "", charging: "\u{f0084}", tux: "", clock: "" };
@@ -90,7 +91,7 @@ export function batteryGlyph(b) {
// one that fits stays still. Only changed values are written, so the
// animation is not restarted by every poll.
function marquee(el) {
- if (!el.offsetParent) return; // another tab is in front: nothing to measure
+ if (!el.getClientRects().length) return; // not shown: nothing to measure
for (const line of el.querySelectorAll(".what, .meta")) {
const over = line.firstElementChild.offsetWidth - line.clientWidth;
line.classList.toggle("marq", over > 0);
@@ -267,25 +268,47 @@ export default {
poll("music", music.interval ?? 2, (st) => music.update(st, el));
});
- // The running row: slots are created now, in RUNNING order, and shown
- // while their module is busy.
+ // The running row: a chip per module, created now in RUNNING order and
+ // shown while it is busy. A tap opens its full slot, and the module's
+ // detail(state, el) when it has one, centred over the page; a tap
+ // outside closes it (closedby="any", Chrome 134+) without reaching what is
+ // under it, a tap inside opens the module's tab.
const row = $(".dash-running");
- for (const name of RUNNING.filter((n) => on.has(n))) {
- const el = document.createElement("div");
- el.className = `card slot slot-${name}`;
- el.hidden = true;
- row.append(el);
+ for (const name of Object.keys(RUNNING).filter((n) => on.has(n))) {
+ const chip = document.createElement("div");
+ chip.className = `chip run-${name}`;
+ chip.hidden = true;
+ chip.innerHTML = `<i class="fill"></i><i class="nf ic"></i><span class="v num"></span><span class="k"></span>`;
+ chip.querySelector(".k").textContent = RUNNING[name];
+ const pop = document.createElement("dialog");
+ pop.setAttribute("closedby", "any");
+ pop.className = "card run-pop";
+ pop.innerHTML = `<div class="slot slot-${name}"></div><div class="detail"></div>`;
+ const [slotEl, detailEl] = pop.children;
+ row.append(chip, pop);
+ chip.addEventListener("click", () => { pop.showModal(); marquee(slotEl); });
import(`./modules/${name}.js`).then((mod) => {
if (!mod.busy || !mod.slot) return;
const tab = mod.default?.tab;
- el.addEventListener("click", (e) => { if (tab && !e.target.closest("button")) open(tab); });
+ pop.addEventListener("click", (e) => {
+ if (tab && !e.target.closest("button")) { pop.close(); open(tab); }
+ });
// ponytail: the K1C and OBS tabs poll the same API; two polls a second, one cache if it matters.
poll(name, mod.interval ?? mod.default?.interval ?? 2, (st) => {
- el.hidden = !mod.busy(st);
- if (!el.hidden) mod.slot(st, el);
- row.hidden = !row.querySelector(".slot:not([hidden])");
- // a slot coming or going changes the others' widths
- for (const s of row.querySelectorAll(".slot:not([hidden])")) marquee(s);
+ chip.hidden = !mod.busy(st);
+ if (chip.hidden) { pop.close(); return; }
+ mod.slot(st, slotEl);
+ mod.detail?.(st, detailEl);
+ // ponytail: the chip mirrors the slot's icon, value and bar, so a
+ // module draws one slot; a chip(state) export if one ever needs more.
+ const bar = slotEl.querySelector(".bar");
+ chip.querySelector(".ic").textContent = slotEl.querySelector(".sic")?.textContent ?? "";
+ chip.querySelector(".v").textContent = slotEl.querySelector(".pct")?.textContent ?? "";
+ chip.querySelector(".fill").style.width = bar?.querySelector("i").style.width ?? "";
+ chip.classList.toggle("busy", !!bar?.classList.contains("busy"));
+ chip.classList.toggle("rec", !!slotEl.querySelector(".sic.rec"));
+ row.hidden = !row.querySelector(".chip:not([hidden])");
+ if (pop.open) marquee(slotEl);
});
});
}