Add bulk recheck and auto-refresh to the IPs dashboard page
"Перепроверить выбранные" joins the existing "Удалить выбранные" / "Очистить всё" bulk actions, using the checked-row selection the same way delete already does — no control-api changes needed, since forcing a recheck of a batch of addresses (new, finished, or already-queued, skipping anything mid-check) is exactly what POST /api/v1/admin/ips (db.SubmitIPs) already does, and the dashboard's own SubmitIPs client method already backs both the top add/recheck form and the single-row recheck button. The page also now auto-refreshes every 5s (handleIPsFragment + GET /ips/fragment), mirroring the overview page's existing hx-trigger="every Ns" polling and reusing the same config-driven interval (Cfg.OverviewPollIntervalS) rather than adding a duplicate knob. Since the table now polls itself, each row's selection checkbox gets a stable id plus hx-preserve so a checked box survives the refresh (its own DOM node is kept) while the rest of the row still updates live. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6117c044b5
commit
ec44d54ac1
4 files changed
+78
-3
No files matched your search
@@ -155,6 +155,55 @@ func TestIPsDeleteSelected(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsPagePollsForFragment(t *testing.T) {
|
||||
_, caURL := newFakeControlAPI(t)
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := get(t, ts, "/ips")
|
||||
if !strings.Contains(body, `hx-get="/ips/fragment"`) || !strings.Contains(body, `hx-trigger="every 5s"`) {
|
||||
t.Fatalf("expected ips-table-wrap to auto-poll every 5s, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsFragment(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
fake.ips = []ipQueueItem{
|
||||
{IPAddress: "1.1.1.1", State: "queued", UpdatedAt: now, CreatedAt: now},
|
||||
{IPAddress: "2.2.2.2", State: "checking", UpdatedAt: now, CreatedAt: now},
|
||||
}
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := get(t, ts, "/ips/fragment")
|
||||
if !strings.Contains(body, "1.1.1.1") || !strings.Contains(body, "2.2.2.2") {
|
||||
t.Fatalf("expected both addresses in fragment, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsRecheckSelected(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
fake.ips = []ipQueueItem{
|
||||
{IPAddress: "9.9.9.9", State: "done", OverallResult: "pass", AttemptNumber: 1, AggregatedAt: &now, UpdatedAt: now, CreatedAt: now},
|
||||
{IPAddress: "1.1.1.1", State: "queued", AttemptNumber: 1, UpdatedAt: now, CreatedAt: now},
|
||||
}
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := postForm(t, ts, "POST", "/ips/recheck", map[string][]string{"addresses": {"9.9.9.9", "1.1.1.1"}})
|
||||
if !strings.Contains(body, "9.9.9.9") || !strings.Contains(body, "1.1.1.1") {
|
||||
t.Fatalf("expected both addresses still in re-rendered table, got:\n%s", body)
|
||||
}
|
||||
if fake.ips[0].State != "queued" || fake.ips[0].AttemptNumber != 2 {
|
||||
t.Fatalf("expected done address requeued with attempt_number=2, got %+v", fake.ips[0])
|
||||
}
|
||||
|
||||
// Empty selection is a client error, surfaced via the banner, not a 500.
|
||||
body = postForm(t, ts, "POST", "/ips/recheck", nil)
|
||||
if !strings.Contains(body, "alert-warning") {
|
||||
t.Fatalf("expected client error banner for empty selection, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsClear(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
|
||||
Reference in new issue
Block a user