Both pages rendered their full lists with no way to narrow them. Adds a ?q=&status= filter (substring match on address, exact match on result status) applied dashboard-side, in Go, over the already-fetched list — no control-api/db changes needed. Overview: the filter form lives outside the polling target (#overview-live) so the recurring poll never wipes out what's typed/selected; the poll and both filter inputs share hx-sync="#overview-live:queue last" (the same fix that resolved the earlier abandoned /ips auto-refresh races) and the poll now carries hx-include="#overview-filter" so it keeps honoring the current filter on every tick. Applies uniformly to both the "Текущая проверка" and "Последние N завершённых" tables, per the confirmed design: picking a specific status naturally hides in-progress rows, since they have no result yet. Registry: no polling exists there, so the filter form reuses the full page via hx-select/hx-replace-url — simpler than adding a parallel fragment endpoint, and gives a bookmarkable/shareable filtered URL. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type registryPageData struct {
|
|
PageData
|
|
Items []registryItem
|
|
Query string
|
|
StatusFilter string
|
|
}
|
|
|
|
type registryDetailData struct {
|
|
PageData
|
|
History registryHistoryResponse
|
|
}
|
|
|
|
// handleRegistryPage lists every address ever submitted to the check
|
|
// queue, with a summary of its accumulated check history — the durable
|
|
// record that survives an address being deleted from /ips and later
|
|
// re-added. See internal/db/migrations/0007_ip_registry.sql. Optional
|
|
// ?q=&status= query params narrow the list by address substring and by
|
|
// LastResult — see filterRegistryItems.
|
|
func (s *Server) handleRegistryPage(w http.ResponseWriter, r *http.Request) {
|
|
items, err := s.CA.ListRegistry(r.Context())
|
|
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
|
status := r.URL.Query().Get("status")
|
|
data := registryPageData{
|
|
Items: filterRegistryItems(items, q, status),
|
|
Query: q,
|
|
StatusFilter: status,
|
|
}
|
|
data.ActiveNav = "registry"
|
|
data.Banner = bannerFor(err)
|
|
s.renderPage(w, "registry_page", data)
|
|
}
|
|
|
|
// filterRegistryItems narrows items to those whose address contains q
|
|
// (case-insensitive substring) and, if status is set, whose LastResult
|
|
// matches it exactly — the registry list's search-by-IP and
|
|
// filter-by-status, mirroring filterQueueItems in handlers_overview.go.
|
|
func filterRegistryItems(items []registryItem, q, status string) []registryItem {
|
|
if q == "" && status == "" {
|
|
return items
|
|
}
|
|
q = strings.ToLower(q)
|
|
out := make([]registryItem, 0, len(items))
|
|
for _, it := range items {
|
|
if q != "" && !strings.Contains(strings.ToLower(it.IPAddress), q) {
|
|
continue
|
|
}
|
|
if status != "" && it.LastResult != status {
|
|
continue
|
|
}
|
|
out = append(out, it)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// handleRegistryDetail shows one address's full retained check history
|
|
// across every cycle it has ever run, not just the current attempt — see
|
|
// ip_detail_content in ip_detail.html for the attempt-scoped equivalent.
|
|
func (s *Server) handleRegistryDetail(w http.ResponseWriter, r *http.Request) {
|
|
ip := r.PathValue("ip")
|
|
history, err := s.CA.GetRegistryHistory(r.Context(), ip)
|
|
data := registryDetailData{History: history}
|
|
data.ActiveNav = "registry"
|
|
data.Banner = bannerFor(err)
|
|
s.renderPage(w, "registry_detail_page", data)
|
|
}
|