1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(ui): a host's pages on a phone: one row of sections, tables that fit

On a phone the host's section menu wrapped to three lines, each new line
starting with a divider. It is now one row that scrolls sideways, with the
current section in sight (scroll_rows.js, which also takes over the VM page's
tab rows from instance_page.js).

The filter list, a filter's rules and the PCI and USB device tables were wider
than a phone and hid their actions and users off screen; on a phone they now
keep the name, the key column and the actions, as the other lists do.

The overview's live CPU and memory figures, the chart axes and tooltips, and
the VM page's stats now write numbers as the page's language does (a decimal
comma in Turkish), like the cards beside them.

The capacity cards said "0 bytes running"; they now say what they count:
"0 bytes in running VMs".

A pool's type is written as libvirt names it on both the list and its page,
and the device search sits where the interfaces search does.
This commit is contained in:
catborise 2026-11-22 14:40:23 +03:00
parent 701d9b1f0a
commit a2da2ab394
24 changed files with 84 additions and 55 deletions

View file

@ -129,14 +129,21 @@ th[aria-sort="ascending"]:not([data-sort-method="none"])::after {
height: 160px;
}
/* the host's sections (computes/host_nav.html) on one line in every theme:
/* the host's sections (computes/host_nav.html) on one line in every theme,
scrolled sideways on a phone:
one font size, and the divider spaced alike on its two sides (Zephyr
doubles the space after it) */
.host-nav .breadcrumb {
--bs-breadcrumb-item-padding-x: .5rem;
/* room for a link's focus outline inside the scrolling row, in a theme without padding */
padding: max(.25rem, var(--bs-breadcrumb-padding-y, 0px)) max(.25rem, var(--bs-breadcrumb-padding-x, 0px));
font-size: .875rem;
}
.host-nav .breadcrumb-item {
flex-shrink: 0;
}
.host-nav .breadcrumb-item + .breadcrumb-item::before {
padding-right: var(--bs-breadcrumb-item-padding-x);
}

View file

@ -6,11 +6,16 @@
var CHART_POINTS = 10;
// the pixels a tick's label needs from the next one
var TICK_ROOM = 60;
// a reading as the page's language writes it (a decimal comma in Turkish), one decimal at most;
// no thousands separator, as the panel's own pages
var PAGE_LANGUAGE = document.documentElement.lang || undefined;
var formatNumber = new Intl.NumberFormat(PAGE_LANGUAGE, {maximumFractionDigits: 1, useGrouping: false}).format;
(function () {
var style = getComputedStyle(document.body);
Chart.defaults.color = style.getPropertyValue("--bs-body-color").trim();
Chart.defaults.borderColor = style.getPropertyValue("--bs-border-color").trim();
Chart.defaults.locale = PAGE_LANGUAGE; // the tooltips' numbers
})();
// labels: one per line. options: max (the y axis top), tooltip(context, text)
@ -58,7 +63,8 @@ function lineChart(canvas, unit, labels, options) {
},
},
},
y: {min: 0, max: options.max, ticks: {callback: function (value) { return value + " " + unit; }}},
// the axis as Chart.js writes it (its precision, the page language), with the unit
y: {min: 0, max: options.max, ticks: {callback: function () { return Chart.Ticks.formatters.numeric.apply(this, arguments) + " " + unit; }}},
},
plugins: {
legend: {display: labels.length > 1},

View file

@ -6,7 +6,7 @@ var cpuChart = lineChart(document.getElementById("cpuChart"), "%", [state.datase
max: 100,
tooltip: function (context, text) {
var span = cpuWindows[context.dataIndex];
return span ? text + ' (' + state.dataset.averageOver + ' ' + span + ' s)' : text;
return span ? text + ' (' + state.dataset.averageOver + ' ' + formatNumber(span) + ' s)' : text;
},
});
var memChart = lineChart(document.getElementById("memChart"), "GiB", [state.dataset.usage]);
@ -42,7 +42,7 @@ pollWhileVisible(5000, function () {
if (data.memdata.total) {
memChart.options.scales.y.max = gb(data.memdata.total);
addPoint(memChart, data.timeline, [gb(data.memdata.usage)]);
memNow.textContent = gb(data.memdata.usage) + " / " + gb(data.memdata.total) + " GiB";
memNow.textContent = formatNumber(gb(data.memdata.usage)) + " / " + formatNumber(gb(data.memdata.total)) + " GiB";
} else {
addPoint(memChart, data.timeline, [null]);
}
@ -50,7 +50,7 @@ pollWhileVisible(5000, function () {
stale();
return;
}
cpuNow.textContent = data.cpudata + " %";
cpuNow.textContent = formatNumber(data.cpudata) + " %";
lastUpdate = data.timeline;
state.textContent = state.dataset.updated.replace("%(time)s", data.timeline);
state.classList.remove("text-danger");

View file

@ -298,14 +298,6 @@
migrateCompute.addEventListener("change", loadMigratePlan);
}
// the tab rows scroll sideways on a phone: the chosen tab is centred in its row, the page stays put
document.addEventListener("shown.bs.tab", function (event) {
var row = event.target.closest(".overflow-x-auto");
if (!row) return;
var tab = event.target.getBoundingClientRect(), box = row.getBoundingClientRect();
row.scrollLeft += tab.left - box.left - (box.width - tab.width) / 2;
});
// the tab a redirect points to; a template opens on its clone form
restoreInstanceTab(document, location.hash || summary.dataset.opensOn, show_tab, load_osinfo);
// none open (a template has no Power tab): the first section the page has

View file

@ -11,7 +11,7 @@
var statsSample = null;
// a reading for the line above a chart: one decimal, a dash where it is missing
function reading(value) {
return value == null ? "–" : String(Math.round(value * 10) / 10);
return value == null ? "–" : formatNumber(value);
}
stats_tab.addEventListener('hidden.bs.tab', function () {
stats_poll.stop();
@ -25,7 +25,7 @@
max: 100,
tooltip: function (context, text) {
var span = cpuWindows[context.dataIndex];
return span ? text + ' (' + pane.dataset.averageOver + ' ' + span + ' s)' : text;
return span ? text + ' (' + pane.dataset.averageOver + ' ' + formatNumber(span) + ' s)' : text;
},
});
var memChart = lineChart(document.getElementById("memChart"), "MiB", [pane.dataset.usageRss]);

12
static/js/scroll_rows.js Normal file
View file

@ -0,0 +1,12 @@
// A row of tabs or sections that scrolls sideways on a phone (overflow-x-auto)
// keeps its current item in sight: centred in the row, the page stays put.
(function () {
function centre(item) {
var row = item.closest(".overflow-x-auto");
if (!row) return;
var box = row.getBoundingClientRect(), own = item.getBoundingClientRect();
row.scrollLeft += own.left - box.left - (box.width - own.width) / 2;
}
document.addEventListener("shown.bs.tab", function (event) { centre(event.target); });
document.querySelectorAll(".overflow-x-auto [aria-current]").forEach(centre);
})();