Files
vardkey/static/app.js
T
2026-10-01 22:16:18 +00:00

74 lines
2.2 KiB
JavaScript

"use strict";
const keyList = document.querySelector("#key-list");
const keyCount = document.querySelector("#key-count");
const lastCheckTitle = document.querySelector("#last-check-title");
const nextCheckTitle = document.querySelector("#next-check-title");
function createKeyCard(key) {
const card = document.createElement("article");
card.className = "key-card";
const top = document.createElement("div");
top.className = "key-card-top";
const number = document.createElement("span");
number.className = "key-number";
number.textContent = String(key.key_number).padStart(2, "0");
const status = document.createElement("span");
status.className = "status status-neutral";
status.textContent = "Profile configured";
const name = document.createElement("h3");
name.textContent = key.name;
const type = document.createElement("p");
type.textContent = key.type === "cloud" ? "Cloud key" : "Hardware key";
top.append(number, status);
card.append(top, name, type);
return card;
}
async function loadKeys() {
try {
const response = await fetch("/api/keys", { headers: { Accept: "application/json" } });
if (!response.ok) {
throw new Error("The key profiles could not be loaded.");
}
const keys = await response.json();
keyList.replaceChildren(...keys.map(createKeyCard));
keyCount.textContent = `${keys.length} keys`;
} catch {
keyList.replaceChildren();
const message = document.createElement("p");
message.className = "empty-state";
message.textContent = "Key profiles are unavailable. Please reload the page or contact the service administrator.";
keyList.append(message);
keyCount.textContent = "Unavailable";
}
}
async function loadSummary() {
try {
const response = await fetch("/api/health-checks", { headers: { Accept: "application/json" } });
if (!response.ok) {
throw new Error("Saved checks are unavailable.");
}
const checks = await response.json();
if (checks.length) {
lastCheckTitle.textContent = checks[0].checked_at;
nextCheckTitle.textContent = checks[0].next_check_due;
}
} catch {
lastCheckTitle.textContent = "Unavailable";
nextCheckTitle.textContent = "Unavailable";
}
}
loadKeys();
loadSummary();