feat(ui): improve the records table, view state and record dialog
Test / test (push) Successful in 26m44s
Build and publish image / image (push) Successful in 27m27s

Sortable record columns, filters and sort kept in the URL on the zones,
zone and audit pages, a Show action that filters the records table to a
problem's owner, Save and add another, a highlight of the saved row, an
Audit history link on the zone page, and dialogs that keep typed input
on a backdrop click.
This commit is contained in:
bryanpedini committed 2026-11-22 17:36:46 +01:00
1 parent a67183b646
commit 440f78ce9e
9 files changed
+419 -36

No files matched your search

+29 -3
View File
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
import { $, api, busy, formatTime, h, handleError, icon } from "./common.js";
import { $, api, busy, formatTime, h, handleError, icon, readQuery, writeQuery } from "./common.js";
import { FIELD_SPECS } from "./records.js";
const state = { nextBeforeId: null, count: 0, filters: {}, counter: 0 };
const state = { nextBeforeId: null, count: 0, filters: {}, counter: 0, generation: 0 };
const SOA_FIELDS = [
{ key: "ns", label: "Primary name server" },
{ key: "MBox", label: "Hostmaster" },
@@ -211,6 +211,12 @@ async function load(append) {
const status = $("#audit-status");
const query = { ...state.filters };
if (append && state.nextBeforeId !== null) query.before_id = state.nextBeforeId;
if (append && state.nextBeforeId === null) return;
if (!append) {
state.generation += 1;
$("#audit-more").hidden = true;
}
const generation = state.generation;
if (!append) {
body.replaceChildren();
state.count = 0;
@@ -218,6 +224,7 @@ async function load(append) {
}
try {
const { data } = await api("GET", "/audit", { query });
if (generation !== state.generation) return;
const entries = data.entries || [];
for (const entry of entries) body.append(...entryRows(entry));
state.count += entries.length;
@@ -225,15 +232,30 @@ async function load(append) {
status.textContent = state.count === 0 ? "No audit rows match." : state.count + " rows shown.";
$("#audit-more").hidden = state.nextBeforeId === null;
} catch (err) {
if (generation !== state.generation) return;
status.textContent = "The audit could not be loaded.";
handleError(err);
}
}
const FILTERS = ["zone", "actor", "operation", "kind", "outcome"];
function prefill() {
const form = $("#audit-filters");
const query = readQuery();
for (const name of FILTERS) {
const value = query.get(name);
if (!value) continue;
const control = form.elements[name];
if (control.tagName === "SELECT" && ![...control.options].some((item) => item.value === value)) continue;
control.value = value;
}
}
function readFilters() {
const form = $("#audit-filters");
const filters = {};
for (const name of ["zone", "actor", "operation", "kind", "outcome"]) {
for (const name of FILTERS) {
const value = form.elements[name].value.trim();
if (value) filters[name] = value;
}
@@ -244,14 +266,18 @@ $("#audit-filters").addEventListener("submit", (event) => {
event.preventDefault();
state.filters = readFilters();
state.nextBeforeId = null;
writeQuery(state.filters);
load(false);
});
$("#audit-filters").addEventListener("reset", () => {
setTimeout(() => {
state.filters = {};
state.nextBeforeId = null;
writeQuery({});
load(false);
}, 0);
});
$("#audit-more").addEventListener("click", (event) => busy(event.target, () => load(true)));
prefill();
state.filters = readFilters();
load(false);