Trim duplicated UI helpers

This commit is contained in:
ajp_anton committed 2026-07-15 19:34:42 +00:00
1 parent a4bb9a98c2
commit 2968412374
5 files changed
+52 -56

No files matched your search

@@ -61,6 +61,40 @@
el.style.color = error ? "#ff9b9b" : "";
}
function prop(obj, pascal, camel, fallback) {
if (!obj) return fallback;
if (obj[pascal] !== undefined) return obj[pascal];
if (obj[camel] !== undefined) return obj[camel];
return fallback;
}
function formatBytes(bytes) {
bytes = Number(bytes || 0);
if (bytes < 1024) return bytes + " B";
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KiB";
if (bytes < 1024 * 1024 * 1024) return (bytes / 1024 / 1024).toFixed(1) + " MiB";
return (bytes / 1024 / 1024 / 1024).toFixed(1) + " GiB";
}
function showModal(id) {
document.getElementById(id).hidden = false;
}
function hideModals(selector) {
[...document.querySelectorAll(selector || ".ml-modal")].forEach((modal) => { modal.hidden = true; });
}
function downloadBlob(blob, name) {
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
function chip(label) {
const el = document.createElement("span");
el.className = "ml-chip";
@@ -105,6 +139,11 @@
authHeaders,
splitList,
setStatus,
prop,
formatBytes,
showModal,
hideModals,
downloadBlob,
chip,
bucketValues,
renderBucket,