cherrypick 4a88f72491 fix the status bar i think idk ai made weird ass shit i have to fix them bugs now
This commit is contained in:
+14
-4
@@ -1,6 +1,8 @@
|
|||||||
|
import { filter_array } from "./status.js";
|
||||||
|
|
||||||
export const qs = new URLSearchParams(location.search);
|
export const qs = new URLSearchParams(location.search);
|
||||||
|
|
||||||
// not real cuh
|
// $ is normally queryselector are we fr
|
||||||
export const $ = (id) => document.getElementById(id);
|
export const $ = (id) => document.getElementById(id);
|
||||||
export const elName = $("name");
|
export const elName = $("name");
|
||||||
export const elCheck = $("check");
|
export const elCheck = $("check");
|
||||||
@@ -17,10 +19,18 @@ export function setPill(kind, text) {
|
|||||||
pill.textContent = text;
|
pill.textContent = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLink(name) {
|
export function setLink(name, clear) {
|
||||||
|
if (clear) location.search = "";
|
||||||
const url = new URL(location.href);
|
const url = new URL(location.href);
|
||||||
if (name) url.searchParams.set("name", name);
|
/* const hasExtraFilters = filter_array.some(
|
||||||
else url.searchParams.delete("name");
|
(k) => url.searchParams.getAll(k).length
|
||||||
|
);
|
||||||
|
if (hasExtraFilters) {
|
||||||
|
// jus returns whatever; they are specifying further
|
||||||
|
} else */ {
|
||||||
|
if (name) url.searchParams.set("name", name);
|
||||||
|
else url.searchParams.delete("name");
|
||||||
|
}
|
||||||
history.replaceState(null, "", url);
|
history.replaceState(null, "", url);
|
||||||
link.href = url.toString();
|
link.href = url.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function pickTarget(value) {
|
|||||||
elName.value = v;
|
elName.value = v;
|
||||||
updatePreview();
|
updatePreview();
|
||||||
saveName(v);
|
saveName(v);
|
||||||
setLink(v);
|
setLink(v, true);
|
||||||
fetchStatus(v);
|
fetchStatus(v);
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
}
|
}
|
||||||
@@ -74,10 +74,16 @@ const initial = loadName(qs);
|
|||||||
if (initial) {
|
if (initial) {
|
||||||
elName.value = initial;
|
elName.value = initial;
|
||||||
updatePreview();
|
updatePreview();
|
||||||
setLink(initial);
|
if (qs.has("name")) {
|
||||||
fetchStatus(initial);
|
setLink(initial);
|
||||||
|
fetchStatus(initial);
|
||||||
|
} else {
|
||||||
|
fetchStatus();
|
||||||
|
}
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
} else {
|
} else {
|
||||||
setPill("warn", "unknown");
|
setPill("warn", "unknown");
|
||||||
|
updatePreview();
|
||||||
|
fetchStatus();
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ const status_map = {
|
|||||||
state: "state",
|
state: "state",
|
||||||
dev: "interface",
|
dev: "interface",
|
||||||
};
|
};
|
||||||
|
export const status_array = Object.keys(status_map);
|
||||||
const filter_array = ["ip", "dev", "nud", "mac"];
|
export const filter_array = ["ip", "dev", "nud", "mac"];
|
||||||
|
|
||||||
function buildStatusUrl(name) {
|
function buildStatusUrl(name) {
|
||||||
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
|
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
|
||||||
@@ -18,7 +18,7 @@ function buildStatusUrl(name) {
|
|||||||
}
|
}
|
||||||
const u = new URL("/api/status", location.origin);
|
const u = new URL("/api/status", location.origin);
|
||||||
if (name) u.searchParams.set("name", name);
|
if (name) u.searchParams.set("name", name);
|
||||||
for (const k of Object.keys(status_map)) {
|
for (const k of filter_array) {
|
||||||
const vals = qs.getAll(k);
|
const vals = qs.getAll(k);
|
||||||
for (const v of vals) u.searchParams.append(k, v);
|
for (const v of vals) u.searchParams.append(k, v);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user