Add IP search and status filter to the Overview and Registry dashboard pages
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>
This commit is contained in:
1 parent
db97b83cd6
commit
0838abc4a2
11 files changed
+296
-13
No files matched your search
@@ -3,6 +3,7 @@ package dashboard
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type overviewData struct {
|
||||
@@ -13,6 +14,8 @@ type overviewData struct {
|
||||
Breakdown map[string]int
|
||||
LastN int
|
||||
PollSeconds int
|
||||
Query string
|
||||
StatusFilter string
|
||||
}
|
||||
|
||||
func (s *Server) loadOverview(r *http.Request) (overviewData, error) {
|
||||
@@ -25,14 +28,18 @@ func (s *Server) loadOverview(r *http.Request) (overviewData, error) {
|
||||
if err != nil {
|
||||
return overviewData{}, err
|
||||
}
|
||||
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
||||
resultFilter := r.URL.Query().Get("status")
|
||||
last := lastCompleted(ips, s.Cfg.LastCompletedCount)
|
||||
return overviewData{
|
||||
Status: status,
|
||||
CurrentItems: currentlyChecking(ips),
|
||||
LastCompleted: last,
|
||||
CurrentItems: filterQueueItems(currentlyChecking(ips), q, resultFilter),
|
||||
LastCompleted: filterQueueItems(last, q, resultFilter),
|
||||
Breakdown: resultBreakdown(last),
|
||||
LastN: s.Cfg.LastCompletedCount,
|
||||
PollSeconds: s.Cfg.OverviewPollIntervalS,
|
||||
Query: q,
|
||||
StatusFilter: resultFilter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -89,3 +96,26 @@ func resultBreakdown(items []ipQueueItem) map[string]int {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// filterQueueItems narrows items to those whose address contains q
|
||||
// (case-insensitive substring) and, if status is set, whose OverallResult
|
||||
// matches it exactly. A still-in-progress item always has an empty
|
||||
// OverallResult, so picking any specific status hides it — the intended
|
||||
// behavior for "Текущая проверка", which has no verdict yet.
|
||||
func filterQueueItems(items []ipQueueItem, q, status string) []ipQueueItem {
|
||||
if q == "" && status == "" {
|
||||
return items
|
||||
}
|
||||
q = strings.ToLower(q)
|
||||
out := make([]ipQueueItem, 0, len(items))
|
||||
for _, ip := range items {
|
||||
if q != "" && !strings.Contains(strings.ToLower(ip.IPAddress), q) {
|
||||
continue
|
||||
}
|
||||
if status != "" && ip.OverallResult != status {
|
||||
continue
|
||||
}
|
||||
out = append(out, ip)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user