This commit is contained in:
ciomek committed 2026-09-19 22:22:22 +02:00
1 parent 4bfaed6184
commit 19098610a2
9 files changed
+107 -19

No files matched your search

+12 -3
View File
@@ -26,7 +26,9 @@ function roleStates(payload) {
return payload.roles.map((role) => {
const holders = alive.filter((member) => member.roles.includes(role.name)).map(address).sort();
let state;
if (role.required === null) {
if (role.on_demand) {
state = holders.length ? "held" : "off";
} else if (role.required === null) {
state = "general";
} else if (holders.length < role.required) {
state = "unmet";
@@ -116,11 +118,17 @@ function alerts(payload) {
return out;
}
function onDemandHint(payload) {
const off = roleStates(payload).filter((role) => role.state === "off").map((role) => role.name);
if (!off.length) return "";
return "Not running (on demand): " + off.join(", ") + " · start one with: colonyctl role add " + off[0];
}
function summarize(payload) {
const states = roleStates(payload);
const alive = payload.members.filter((member) => member.alive).length;
const down = payload.members.length - alive;
const assigned = states.filter((role) => role.state !== "general");
const assigned = states.filter((role) => role.state !== "general" && role.state !== "off");
const held = assigned.filter((role) => role.state !== "unmet");
let text = alive + " node" + (alive === 1 ? "" : "s") + " alive";
if (down) text += " · " + down + " down";
@@ -351,6 +359,7 @@ if (typeof document !== "undefined") {
const box = document.getElementById("alerts");
box.replaceChildren();
alerts(payload).forEach((alert) => box.appendChild(html("span", alert.text, "alert " + alert.level)));
document.getElementById("ondemand").textContent = onDemandHint(payload);
};
let latest = null;
@@ -395,5 +404,5 @@ if (typeof document !== "undefined") {
}
if (typeof module !== "undefined") {
module.exports = { address, roleStates, layout, nodeRoles, chipLayout, chipWidth, shorten, formatAge, formatSize, formatUptime, describeStats, barLevel, alerts, summarize };
module.exports = { address, roleStates, layout, nodeRoles, chipLayout, chipWidth, shorten, formatAge, formatSize, formatUptime, describeStats, barLevel, alerts, summarize, onDemandHint };
}