mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
- binary_size filter (common_tags): every size on the pages is B/KiB/MiB/GiB/TiB with the language's decimal mark; Django's filesizeformat said GB for GiB, so a page showed "512,0 MB / 3,8 GB" beside "0,4 / 3,8 GiB" and a disk "20,0 GB" next to a GiB field - percent filter and Intl percent in charts.js, the job panel and the new-VM dialog: 13% in English, %13 in Turkish (pages had "13 %", "%11" and "13%") - the Jobs page and panel say in whole sentences that the job worker is not running and that jobs wait for it, instead of a sentence glued to a date - job state badges start with a capital, as the VM state badges (CSS, so the label stays lowercase inside sentences) - profile card shows the username under the name only when there is a full name - Turkish: hostname, revert snapshot, snapshot count, API token and worker texts
53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
// The new-VM dialog's CPU bars and capacity lines, read when the
|
|
// dialog opens, two reads at a time: a CPU read holds a worker for
|
|
// a second, a capacity read while it reads the host's VMs. Answers
|
|
// of an earlier opening are ignored.
|
|
const addInstance = document.getElementById("AddInstance");
|
|
let opening = 0, queue = [], reading = 0;
|
|
|
|
// a percentage as the page's language writes it: 13% in English, %13 in Turkish
|
|
const percentFormat = new Intl.NumberFormat(document.documentElement.lang || undefined, {style: "percent"});
|
|
|
|
function setCpuUsage(cell, percent, text) {
|
|
const meter = cell.querySelector(".progress");
|
|
cell.querySelector(".progress-bar").style.width = (percent || 0) + "%";
|
|
if (percent === null) {
|
|
meter.removeAttribute("aria-valuenow");
|
|
} else {
|
|
meter.setAttribute("aria-valuenow", percent);
|
|
}
|
|
cell.querySelector(".cpu-usage-value").textContent = text;
|
|
}
|
|
|
|
// data: the answer, or null when the read failed
|
|
function show(element, data) {
|
|
if (element.classList.contains("compute-capacity")) {
|
|
element.textContent = data === null ? "" : data.trim();
|
|
return;
|
|
}
|
|
const usage = data !== null && typeof data.cpudata === "number" ? Math.round(data.cpudata) : null;
|
|
setCpuUsage(element, usage, usage === null ? "—" : percentFormat.format(usage / 100));
|
|
}
|
|
|
|
function readNext() {
|
|
while (reading < 2 && queue.length) {
|
|
const element = queue.shift(), current = opening;
|
|
reading++;
|
|
$.get(element.dataset.url)
|
|
.done((data) => { if (current === opening) show(element, data); })
|
|
.fail(() => { if (current === opening) show(element, null); })
|
|
.always(() => { reading--; readNext(); });
|
|
}
|
|
}
|
|
|
|
addInstance.addEventListener("show.bs.modal", function () {
|
|
opening++;
|
|
addInstance.querySelectorAll(".cpu-usage").forEach((cell) => setCpuUsage(cell, null, "…"));
|
|
// host by host, as the list shows them
|
|
queue = Array.from(addInstance.querySelectorAll(".cpu-usage, .compute-capacity"));
|
|
readNext();
|
|
});
|
|
addInstance.addEventListener("hide.bs.modal", function () {
|
|
opening++;
|
|
queue = [];
|
|
});
|