v0.38.4
This commit is contained in:
1 parent
2d0d0f12c7
commit
963ec64398
11 files changed
+114
-28
No files matched your search
+35
-13
@@ -99,32 +99,43 @@ window.rustProxyChoicePicker = (() => {
|
||||
const maxHint = el("small", t("aclPickerLimit"), "fine acl-picker-limit");
|
||||
dropdown.append(search, optionsBox, empty, maxHint); details.append(dropdown);
|
||||
const selectedTags = el("div", undefined, "acl-picker-selected"); root.append(details, selectedTags);
|
||||
const items = [...(options.items || [])], checks = new Map(), order = [];
|
||||
const addOption = (item, checked) => {
|
||||
if (checks.has(item.id)) { const box = checks.get(item.id); if (checked && !box.checked) { box.checked = true; order.push(item.id); } return box; }
|
||||
const row = el("label", undefined, "acl-picker-option"), check = el("input"); check.type = "checkbox"; check.value = item.id; check.checked = !!checked;
|
||||
// Option rows are built on the first open: long lists (countries) would
|
||||
// otherwise add thousands of DOM nodes per picker. `state` is the source of
|
||||
// truth for every option; `checks` holds only rendered checkboxes.
|
||||
const items = [...(options.items || [])], state = new Map(), checks = new Map(), order = [];
|
||||
let rendered = false;
|
||||
const isChosen = id => state.get(id) === true;
|
||||
const renderOption = item => {
|
||||
const row = el("label", undefined, "acl-picker-option"), check = el("input"); check.type = "checkbox"; check.value = item.id; check.checked = isChosen(item.id);
|
||||
const content = el("span", undefined, "acl-picker-option-content"), headingRow = el("span", undefined, "acl-picker-option-heading");
|
||||
headingRow.append(el("strong", item.title || item.id));
|
||||
if (item.title && item.title !== item.id && !item.title.startsWith(`${item.id} `)) headingRow.append(el("code", item.id, "acl-picker-id"));
|
||||
if (item.badge) headingRow.append(el("span", item.badge, `acl-picker-policy ${item.badgeClass || "is-none"}`));
|
||||
content.append(headingRow); if (item.detail) content.append(el("small", item.detail, "acl-picker-rule-preview"));
|
||||
row.append(check, content); row.dataset.search = `${item.id} ${item.title || ""} ${item.search || ""} ${item.detail || ""}`.toLocaleLowerCase();
|
||||
optionsBox.append(row); checks.set(item.id, check); if (!items.includes(item)) items.push(item); if (checked) order.push(item.id);
|
||||
return check;
|
||||
optionsBox.append(row); checks.set(item.id, check);
|
||||
};
|
||||
const addOption = (item, checked) => {
|
||||
if (!state.has(item.id)) { state.set(item.id, false); if (!items.includes(item)) items.push(item); if (rendered) renderOption(item); }
|
||||
if (checked && !isChosen(item.id)) { state.set(item.id, true); order.push(item.id); const box = checks.get(item.id); if (box) box.checked = true; }
|
||||
};
|
||||
const renderOptions = () => { if (rendered) return; rendered = true; for (const item of items) renderOption(item); syncSearch(); sync(); };
|
||||
const setChosen = (id, value) => { state.set(id, value); const box = checks.get(id); if (box) box.checked = value; };
|
||||
const selected = [...new Set(options.selected || [])];
|
||||
for (const item of items.slice()) addOption(item, false);
|
||||
for (const id of selected) addOption(items.find(item => item.id === id) || { id, title: id, detail: options.unknownDetail ? t(options.unknownDetail) : "" }, true);
|
||||
const chosen = () => order.filter(id => checks.get(id)?.checked);
|
||||
const chosen = () => order.filter(isChosen);
|
||||
const syncSearch = () => {
|
||||
const query = search.value.trim().toLocaleLowerCase(); let visible = 0;
|
||||
for (const row of optionsBox.querySelectorAll(".acl-picker-option")) { row.hidden = !!query && !row.dataset.search.includes(query); if (!row.hidden) visible++; }
|
||||
if (!rendered) visible = items.length;
|
||||
empty.hidden = visible > 0 || (!query && !items.length);
|
||||
empty.textContent = query && options.custom ? label("addHint", "choicePickerAddHint").replace("{value}", search.value.trim()) : label("noMatches", "aclPickerNoMatches");
|
||||
if (!items.length && !query) { empty.hidden = false; empty.textContent = label("empty", "choicePickerEmpty"); }
|
||||
};
|
||||
const sync = () => {
|
||||
for (const [id, box] of checks) { const index = order.indexOf(id); if (box.checked && index < 0) order.push(id); if (!box.checked && index >= 0) order.splice(index, 1); }
|
||||
for (const [id, box] of checks) state.set(id, box.checked);
|
||||
for (const [id, value] of state) { const index = order.indexOf(id); if (value && index < 0) order.push(id); if (!value && index >= 0) order.splice(index, 1); }
|
||||
const ids = chosen(), full = ids.length >= limit;
|
||||
counter.textContent = `${ids.length}/${limit}`;
|
||||
heading.textContent = ids.length ? label("selected", "aclPickerSelected").replace("{count}", ids.length) : label("choose", "aclPickerChoose");
|
||||
@@ -134,7 +145,7 @@ window.rustProxyChoicePicker = (() => {
|
||||
const text = el("span", item?.title || id); text.title = item?.detail || id;
|
||||
if (index === 0 && options.markFirst) tag.title = t(options.markFirst);
|
||||
const remove = el("button", "×", "acl-picker-remove"); remove.type = "button"; remove.setAttribute("aria-label", `${t("remove")} ${item?.title || id}`);
|
||||
remove.addEventListener("click", () => { const box = checks.get(id); box.checked = false; box.dispatchEvent(new Event("change", { bubbles: true })); });
|
||||
remove.addEventListener("click", () => { const box = checks.get(id); if (box) { box.checked = false; box.dispatchEvent(new Event("change", { bubbles: true })); return; } setChosen(id, false); sync(); root.dispatchEvent(new Event("change", { bubbles: true })); });
|
||||
tag.append(text);
|
||||
if (index > 0 && options.markFirst && options.makeFirst) {
|
||||
const promote = el("button", "★", "acl-picker-promote"); promote.type = "button"; promote.dataset.uiIconName = "none"; promote.title = t(options.makeFirst); promote.setAttribute("aria-label", `${t(options.makeFirst)}: ${item?.title || id}`);
|
||||
@@ -153,11 +164,13 @@ window.rustProxyChoicePicker = (() => {
|
||||
for (const value of values) {
|
||||
let item; try { item = options.custom(value); } catch (error) { toast(error.message, true); return; }
|
||||
if (!item) continue;
|
||||
if (chosen().length >= limit && !checks.get(item.id)?.checked) { toast(t("aclPickerLimit"), true); break; }
|
||||
const box = addOption(items.find(entry => entry.id === item.id) || item, false); box.checked = true;
|
||||
if (chosen().length >= limit && !isChosen(item.id)) { toast(t("aclPickerLimit"), true); break; }
|
||||
addOption(items.find(entry => entry.id === item.id) || item, false); setChosen(item.id, true);
|
||||
}
|
||||
search.value = ""; syncSearch(); sync(); root.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
};
|
||||
details.addEventListener("toggle", () => { if (details.open) renderOptions(); });
|
||||
search.addEventListener("focus", renderOptions);
|
||||
optionsBox.addEventListener("change", event => { if (event.target.matches('input[type="checkbox"]')) sync(); });
|
||||
search.addEventListener("input", syncSearch);
|
||||
search.addEventListener("keydown", event => {
|
||||
@@ -167,7 +180,7 @@ window.rustProxyChoicePicker = (() => {
|
||||
search.addEventListener("blur", () => { if (options.custom && search.value.trim()) addCustom(); });
|
||||
root.read = chosen;
|
||||
root.setDisabled = disabled => { root.classList.toggle("is-disabled", disabled); details.open = details.open && !disabled; summary.tabIndex = disabled ? -1 : 0; summary.setAttribute("aria-disabled", String(disabled)); };
|
||||
root.select = ids => { for (const [id, box] of checks) box.checked = ids.includes(id); order.length = 0; order.push(...ids.filter(id => checks.has(id))); sync(); };
|
||||
root.select = ids => { for (const id of state.keys()) setChosen(id, ids.includes(id)); order.length = 0; order.push(...ids.filter(id => state.has(id))); sync(); };
|
||||
syncSearch(); sync(); return root;
|
||||
}
|
||||
return { create, read: root => root?.read?.() || [] };
|
||||
@@ -210,7 +223,16 @@ window.rustProxyChipInput = (() => {
|
||||
|
||||
window.rustProxyCountryPicker = (() => {
|
||||
const CODES = "AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS XK YE YT ZA ZM ZW".split(" ");
|
||||
const nameOf = code => { try { return new Intl.DisplayNames([document.documentElement.lang || "en"], { type: "region" }).of(code) || code; } catch { return code; } };
|
||||
// Country names are resolved once per language: constructing Intl.DisplayNames
|
||||
// for every lookup was a large part of rendering many country pickers.
|
||||
const countryNames = new Map();
|
||||
const nameOf = code => {
|
||||
const lang = document.documentElement.lang || "en";
|
||||
let names = countryNames.get(lang);
|
||||
if (!names) { let display = null; try { display = new Intl.DisplayNames([lang], { type: "region" }); } catch { /* unsupported locale */ } names = { display, cache: new Map() }; countryNames.set(lang, names); }
|
||||
if (!names.cache.has(code)) { let name = code; try { name = names.display?.of(code) || code; } catch { /* unknown region */ } names.cache.set(code, name); }
|
||||
return names.cache.get(code);
|
||||
};
|
||||
const parse = text => [...new Set(String(text || "").split(/[\s,;]+/).map(value => value.trim().toUpperCase()).filter(Boolean))];
|
||||
function attach(textarea, options = {}) {
|
||||
if (!textarea || textarea.dataset.countryPicker) return null;
|
||||
|
||||
@@ -30,6 +30,17 @@ let adminAuthChannel = null; try { adminAuthChannel = new BroadcastChannel("rust
|
||||
let languagePacks = new Map(), defaultLanguage = null;
|
||||
function activePack() { return languagePacks.get(language) || languagePacks.get(defaultLanguage); }
|
||||
function locale() { try { return Intl.getCanonicalLocales(activePack()?.meta.locale || "und")[0]; } catch { return "und"; } }
|
||||
// Sorting calls a comparator O(n log n) times; String#localeCompare with a
|
||||
// locale/options argument builds a new collator on every call, which made
|
||||
// periodic table re-renders slow. Collators are cached per language.
|
||||
const textCollators = new Map();
|
||||
function textCollator(numeric = true) {
|
||||
const key = `${activePack()?.meta.locale || "und"}|${numeric}`;
|
||||
let collator = textCollators.get(key);
|
||||
if (!collator) { collator = new Intl.Collator(locale(), numeric ? { numeric: true, sensitivity: "base" } : { sensitivity: "base" }); textCollators.set(key, collator); }
|
||||
return collator;
|
||||
}
|
||||
function compareText(a, b, numeric = true) { return textCollator(numeric).compare(String(a), String(b)); }
|
||||
function t(key) { const pack = activePack()?.translations; const fallback = languagePacks.get(defaultLanguage)?.translations; return (pack && Object.hasOwn(pack, key) ? pack[key] : fallback?.[key]) ?? key; }
|
||||
async function loadLanguages() {
|
||||
const bundle = await api("/assets/langs.json");
|
||||
@@ -170,6 +181,7 @@ function setPanel(name, navigate = true) {
|
||||
if (name === "web-server" && latestStatus) window.rustProxyWebServer?.renderLive?.(latestStatus, false);
|
||||
if (name === "settings") window.rustProxySettings?.syncLocation?.();
|
||||
window.rustProxyRefresh?.setPanel(name);
|
||||
if (name === "overview") window.rustProxyVhosts?.flushOverviewViews?.();
|
||||
if (name === "overview" && previousPanel !== name && typeof latestStatus !== "undefined" && latestStatus) { window.rustProxyStreamDashboard?.render?.(latestStatus, null, false); window.rustProxyDockerDashboard?.render?.(latestStatus, null, false); window.rustProxyBackendDashboard?.render?.(latestStatus, null, false); window.rustProxyExtraOverview?.render?.(latestStatus, false); window.rustProxyWideOverview?.render?.(latestStatus, false); window.rustProxyWebOverview?.render?.(latestStatus, false); }
|
||||
if (name === "docker-vhosts" && previousPanel !== name && authenticated && envelope) void window.rustProxyRefresh?.manual("docker");
|
||||
if (name === "tls") window.rustProxyAcme?.syncLocation?.();
|
||||
|
||||
@@ -1115,7 +1115,6 @@
|
||||
|
||||
.docker-agent-security,
|
||||
.docker-toolbar,
|
||||
.docker-service-editor>summary,
|
||||
.security-editor>summary,
|
||||
.function-live-chart-footer,
|
||||
.certificate-api-credential-row {
|
||||
@@ -1123,6 +1122,21 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* Keep the disclosure arrow and the title on one line; the route hint
|
||||
wraps below them. A column layout put the arrow on its own row and let
|
||||
the summary items spread vertically, leaving large empty gaps. */
|
||||
details.docker-service-editor>summary {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
row-gap: 2px;
|
||||
}
|
||||
|
||||
details.docker-service-editor>summary .docker-config-hint {
|
||||
flex: 1 1 100%;
|
||||
padding-left: 28px;
|
||||
}
|
||||
|
||||
.docker-toolbar input[type=search],
|
||||
.docker-service-actions button,
|
||||
.security-page-heading>button,
|
||||
|
||||
@@ -367,7 +367,7 @@
|
||||
const member = poolIndex.get(route.pool_id)?.members?.[0];
|
||||
out.push({ agent, route, service, member, hosts: route.hosts });
|
||||
}
|
||||
return out.sort((a, b) => `${a.agent.name}\u0000${a.hosts[0]}`.localeCompare(`${b.agent.name}\u0000${b.hosts[0]}`, locale(), { numeric: true, sensitivity: "base" }));
|
||||
return out.sort((a, b) => compareText(`${a.agent.name}\u0000${a.hosts[0]}`, `${b.agent.name}\u0000${b.hosts[0]}`));
|
||||
}
|
||||
function revealService(agentId, serviceKey) {
|
||||
const row = [...document.querySelectorAll("#docker-discovery-list .docker-service-row")].find(item => item.dataset.viewKey === viewKey(agentId, serviceKey)); if (!row) return;
|
||||
@@ -1119,14 +1119,14 @@
|
||||
}
|
||||
function sortRowsIn(holder) {
|
||||
const rows = [...holder.querySelectorAll(":scope > .docker-service-row")];
|
||||
rows.sort((left, right) => { const a = left.dockerSort?.[listPrefs.sort] ?? "", b = right.dockerSort?.[listPrefs.sort] ?? ""; const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" }); return listPrefs.descending ? -result : result; });
|
||||
rows.sort((left, right) => { const a = left.dockerSort?.[listPrefs.sort] ?? "", b = right.dockerSort?.[listPrefs.sort] ?? ""; const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b); return listPrefs.descending ? -result : result; });
|
||||
for (const row of rows) holder.append(row);
|
||||
}
|
||||
function sortServiceRows(card) {
|
||||
const holder = card.querySelector(".docker-service-list"); if (!holder) return;
|
||||
for (const group of holder.querySelectorAll(":scope > .docker-service-group")) { const body = group.querySelector(".docker-service-group-rows"); sortRowsIn(body); group.dockerSort = body.querySelector(".docker-service-row")?.dockerSort; }
|
||||
const rows = [...holder.querySelectorAll(":scope > .docker-service-row, :scope > .docker-service-group")];
|
||||
rows.sort((left, right) => { const a = left.dockerSort?.[listPrefs.sort] ?? "", b = right.dockerSort?.[listPrefs.sort] ?? ""; const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" }); return listPrefs.descending ? -result : result; });
|
||||
rows.sort((left, right) => { const a = left.dockerSort?.[listPrefs.sort] ?? "", b = right.dockerSort?.[listPrefs.sort] ?? ""; const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b); return listPrefs.descending ? -result : result; });
|
||||
for (const row of rows) holder.append(row);
|
||||
}
|
||||
function applyViewFilters() {
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
}
|
||||
function orderedColumns() {
|
||||
const preferred = defaultColumnIds.filter(id => availableColumns.has(id));
|
||||
const rest = [...availableColumns].filter(id => !defaultColumnIds.includes(id)).sort((a, b) => a.localeCompare(b, locale(), { sensitivity: "base" }));
|
||||
const rest = [...availableColumns].filter(id => !defaultColumnIds.includes(id)).sort((a, b) => compareText(a, b, false));
|
||||
return [...preferred, ...rest];
|
||||
}
|
||||
function applyFields(fields = []) {
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
if (!envelope) return; const query = ($("notfound-search").value || "").trim().toLowerCase();
|
||||
const entries = (envelope.config.not_found_hosts || []).filter(item => !query || [item.id, item.name, ...(item.frontend?.hosts || [])].join(" ").toLowerCase().includes(query));
|
||||
const sortValue = item => ({ id: String(item.id || "").toLowerCase(), name: String(item.name || item.id || "").toLowerCase(), hostname: String(item.frontend?.hosts?.[0] || "").toLowerCase(), status: Number(item.page?.status ?? 404), mode: String(item.page?.kind || "welcome"), listeners: (item.frontend?.listener_ids || []).join(" ").toLowerCase(), certificate: String(item.certificate_id || "").toLowerCase() }[listPrefs.sort]);
|
||||
entries.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" }); return listPrefs.descending ? -result : result; });
|
||||
entries.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b); return listPrefs.descending ? -result : result; });
|
||||
list.replaceChildren(...entries.map(item => {
|
||||
const card = el("article", undefined, "vhost-card redirect-card"), head = el("div", undefined, "vhost-card-head"), identity = el("div", undefined, "vhost-card-identity"), title = el("div", undefined, "vhost-title-line");
|
||||
title.append(el("strong", item.name || item.id, "entity-title")); if (item.enabled === false) title.append(el("span", t("vhDisabled"), "pill")); identity.append(title); head.append(identity);
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
listeners: (item.frontend?.listener_ids || []).join(" ").toLowerCase(),
|
||||
certificate: String(item.certificate_id || "").toLowerCase(),
|
||||
}[listPrefs.sort]);
|
||||
entries.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" }); return listPrefs.descending ? -result : result; });
|
||||
entries.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b); return listPrefs.descending ? -result : result; });
|
||||
list.replaceChildren(...entries.map(item => {
|
||||
const card = el("article", undefined, "vhost-card redirect-card"); const head = el("div", undefined, "vhost-card-head"), identity = el("div", undefined, "vhost-card-identity"), title = el("div", undefined, "vhost-title-line");
|
||||
title.append(el("strong", item.name || item.id, "entity-title")); if (item.enabled === false) title.append(el("span", t("vhDisabled"), "pill")); identity.append(title); head.append(identity);
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
const live = active.get(stream.id), same = live && JSON.stringify(live) === JSON.stringify(stream);
|
||||
return ({ name: String(stream.name || stream.id || "").toLowerCase(), id: String(stream.id || "").toLowerCase(), protocol: String(stream.protocol || "tcp"), listen: String(stream.listen || "").toLowerCase(), upstream: String(stream.upstream || "").toLowerCase(), status: stream.enabled === false ? 2 : same ? 0 : 1, maxConnections: Number(stream.max_connections || 0), idleTimeout: Number(stream.idle_timeout_seconds || 0) })[listPrefs.sort];
|
||||
};
|
||||
streams.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" }); return listPrefs.descending ? -result : result; });
|
||||
streams.sort((left, right) => { const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b); return listPrefs.descending ? -result : result; });
|
||||
const cards = streams.map(stream => {
|
||||
const box = el("article", undefined, "vhost-card stream-card"); box.dataset.streamCard = stream.id;
|
||||
const head = el("div", undefined, "vhost-card-head"), identity = el("div", undefined, "vhost-card-identity"), title = el("div", undefined, "vhost-title-line");
|
||||
|
||||
@@ -220,7 +220,14 @@ function syncPoolSortDirection() {
|
||||
control.setAttribute("aria-label", t(poolTablePrefs.descending ? "backendSortDescending" : "backendSortAscending"));
|
||||
}
|
||||
}
|
||||
// The backend pool and backend overview tables live on Overview. Rebuilding
|
||||
// them on every live snapshot while another panel is shown cost tens of
|
||||
// milliseconds per update; defer them until Overview is shown again.
|
||||
let overviewViewsPending = false;
|
||||
const overviewViewsHidden = () => typeof currentPanel !== "undefined" && currentPanel !== "overview";
|
||||
function flushOverviewViews() { if (!overviewViewsPending) return; overviewViewsPending = false; applyPoolTableView(); }
|
||||
function applyPoolTableView() {
|
||||
if (overviewViewsHidden()) { overviewViewsPending = true; return; }
|
||||
for (const id of ["pool-sort", "bo-sort"]) { const control = $(id); if (control && control.value !== poolTablePrefs.sort) control.value = poolTablePrefs.sort; }
|
||||
applyBackendOverviewView();
|
||||
const body = $("pool-rows"); if (!body) return;
|
||||
@@ -229,7 +236,7 @@ function applyPoolTableView() {
|
||||
const rows = [...body.querySelectorAll("tr")];
|
||||
rows.sort((left, right) => {
|
||||
const a = left.poolSort?.[key] ?? "", b = right.poolSort?.[key] ?? "";
|
||||
const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" });
|
||||
const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b);
|
||||
return poolTablePrefs.descending ? -result : result;
|
||||
});
|
||||
body.replaceChildren(...rows);
|
||||
@@ -371,7 +378,7 @@ function boTrafficChart(inSamples, outSamples) {
|
||||
}
|
||||
return svg;
|
||||
}
|
||||
function renderBackendOverview(items, hasProxy, snapshot = null) {
|
||||
function renderBackendOverview(items, hasProxy, snapshot = null, apply = true) {
|
||||
boItems = items; boHasProxy = hasProxy !== false;
|
||||
const seen = new Set(), sample = snapshot === null || snapshot !== boSnapshot;
|
||||
boSnapshot = snapshot;
|
||||
@@ -389,7 +396,7 @@ function renderBackendOverview(items, hasProxy, snapshot = null) {
|
||||
for (const key of boSeries.keys()) if (!seen.has(key)) boSeries.delete(key);
|
||||
for (const key of boOpen) if (!seen.has(key)) boOpen.delete(key);
|
||||
$("backend-overview-card")?.classList.toggle("is-no-proxy", !boHasProxy);
|
||||
applyBackendOverviewView();
|
||||
if (apply) applyBackendOverviewView();
|
||||
}
|
||||
function boStack(parts) {
|
||||
const track = el("div", undefined, "bo-stack"), total = parts.reduce((sum, [value]) => sum + value, 0);
|
||||
@@ -453,6 +460,7 @@ const BO_EXTRA_CELLS = {
|
||||
},
|
||||
};
|
||||
function applyBackendOverviewView() {
|
||||
if (overviewViewsHidden()) { overviewViewsPending = true; return; }
|
||||
const body = $("bo-rows"); if (!body) return;
|
||||
const visibleColumns = new Set(poolTablePrefs.columns);
|
||||
const query = ($("bo-search")?.value || "").trim().toLowerCase();
|
||||
@@ -473,7 +481,7 @@ function applyBackendOverviewView() {
|
||||
const list = boItems.filter(item => (boFilter === "all" || item.group === boFilter) && (!query || item.search.includes(query)));
|
||||
list.sort((left, right) => {
|
||||
const a = left.sort[key] ?? "", b = right.sort[key] ?? "";
|
||||
const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" });
|
||||
const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b);
|
||||
return poolTablePrefs.descending ? -result : result;
|
||||
});
|
||||
const showIdentity = visibleColumns.has("vhost") || visibleColumns.has("backend"), showEvent = visibleColumns.has("lastFailure") || visibleColumns.has("lastRecovery");
|
||||
@@ -607,7 +615,7 @@ function render() {
|
||||
backends: Number(v.backends?.length || 0),
|
||||
}[vhostListPrefs.sort]);
|
||||
visibleVhosts.sort((left, right) => {
|
||||
const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : String(a).localeCompare(String(b), locale(), { numeric: true, sensitivity: "base" });
|
||||
const a = sortValue(left), b = sortValue(right); const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b);
|
||||
return vhostListPrefs.descending ? -result : result;
|
||||
});
|
||||
const cards = visibleVhosts.map(v => {
|
||||
@@ -840,7 +848,7 @@ function renderStatus(status) {
|
||||
vhost.source?.type !== "web_server" || (vhost.routes || []).some(route => !route.response && (route.source?.type || "reverse_proxy") === "reverse_proxy")
|
||||
);
|
||||
$("pool-rows").replaceChildren(...rows);
|
||||
renderBackendOverview(overviewItems, hasConfiguredProxySource, status);
|
||||
renderBackendOverview(overviewItems, hasConfiguredProxySource, status, false);
|
||||
const backendDiagnosticsCard = $("backend-diagnostics-card");
|
||||
backendDiagnosticsCard?.classList.toggle("is-no-proxy", !hasConfiguredProxySource);
|
||||
applyPoolTableView();
|
||||
@@ -939,5 +947,5 @@ $("pool-open").addEventListener("click", () => setPanel("vhosts"));
|
||||
initPoolTableTools();
|
||||
$("location-help-close")?.addEventListener("click", () => $("location-help-dialog")?.close());
|
||||
window.rustProxyDrafts.register("vhost", { labelKey: "vhosts", isOpen: () => dialog.open, isDirty: () => dirty, suspend: suspendDraft, restore: restoreDraft, close: () => { dirty = false; if (dialog.open) dialog.close(); } });
|
||||
window.rustProxyVhosts = { render, renderStatus, applyPreferences, reset() { closeVhostBackendPopup(); dialog.close(); draftEpoch++; stagedCertificates = []; uploading = false; editing = null; revision = null; dirty = false; initialized = false; backendHealthEditorControl = null; poolTablePrefs = defaultPoolTablePrefs(); vhostListPrefs = defaultVhostListPrefs(); poolPreferenceSaveRunning = false; poolPreferenceSaveQueued = false; chartHistory.clear(); backendTrafficHistory.clear(); backendRequestHistory.clear(); vhostTrafficHistory.clear(); container.replaceChildren(); $("vhost-search").value = ""; if ($("pool-search")) $("pool-search").value = ""; $("vhost-list").replaceChildren(); $("pool-rows").replaceChildren(); const sort = $("pool-sort"); if (sort) sort.value = poolTablePrefs.sort; const vhostSort = $("vhost-sort"); if (vhostSort) vhostSort.value = vhostListPrefs.sort; syncVhostSortDirection(); applyPoolTableView(); } };
|
||||
window.rustProxyVhosts = { render, renderStatus, applyPreferences, flushOverviewViews, reset() { closeVhostBackendPopup(); dialog.close(); draftEpoch++; stagedCertificates = []; uploading = false; editing = null; revision = null; dirty = false; initialized = false; backendHealthEditorControl = null; poolTablePrefs = defaultPoolTablePrefs(); vhostListPrefs = defaultVhostListPrefs(); poolPreferenceSaveRunning = false; poolPreferenceSaveQueued = false; chartHistory.clear(); backendTrafficHistory.clear(); backendRequestHistory.clear(); vhostTrafficHistory.clear(); container.replaceChildren(); $("vhost-search").value = ""; if ($("pool-search")) $("pool-search").value = ""; $("vhost-list").replaceChildren(); $("pool-rows").replaceChildren(); const sort = $("pool-sort"); if (sort) sort.value = poolTablePrefs.sort; const vhostSort = $("vhost-sort"); if (vhostSort) vhostSort.value = vhostListPrefs.sort; syncVhostSortDirection(); applyPoolTableView(); } };
|
||||
if (envelope) render(); if (latestStatus) renderStatus(latestStatus);
|
||||
Reference in new issue
Block a user