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
@@ -9,6 +9,7 @@ type ipsPageData struct {
|
||||
PageData
|
||||
Items []ipQueueItem
|
||||
FIPSettleSeconds int
|
||||
PollSeconds int
|
||||
}
|
||||
|
||||
type ipDetailData struct {
|
||||
@@ -22,12 +23,20 @@ func (s *Server) handleIPsPage(w http.ResponseWriter, r *http.Request) {
|
||||
if err == nil {
|
||||
err = settingsErr
|
||||
}
|
||||
data := ipsPageData{Items: items, FIPSettleSeconds: settings.FIPSettleSeconds}
|
||||
data := ipsPageData{Items: items, FIPSettleSeconds: settings.FIPSettleSeconds, PollSeconds: s.Cfg.OverviewPollIntervalS}
|
||||
data.ActiveNav = "ips"
|
||||
data.Banner = bannerFor(err)
|
||||
s.renderPage(w, "ips_page", data)
|
||||
}
|
||||
|
||||
// handleIPsFragment re-renders just the ips_table fragment, for the
|
||||
// periodic auto-refresh poll (see ips_content's hx-trigger="every Ns") —
|
||||
// identical to a mutating action's post-update render, just with no
|
||||
// actionErr of its own.
|
||||
func (s *Server) handleIPsFragment(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderIPsTable(w, r, nil)
|
||||
}
|
||||
|
||||
func (s *Server) handleIPDetail(w http.ResponseWriter, r *http.Request) {
|
||||
ip := r.PathValue("ip")
|
||||
detail, err := s.CA.GetIP(r.Context(), ip)
|
||||
@@ -99,6 +108,20 @@ func (s *Server) handleIPsDeleteSelected(w http.ResponseWriter, r *http.Request)
|
||||
s.renderIPsTable(w, r, err)
|
||||
}
|
||||
|
||||
func (s *Server) handleIPsRecheckSelected(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
s.renderIPsTable(w, r, fmt.Errorf("invalid form: %w", err))
|
||||
return
|
||||
}
|
||||
addresses := r.Form["addresses"]
|
||||
if len(addresses) == 0 {
|
||||
s.renderIPsTable(w, r, &apiErr{Status: http.StatusBadRequest, Message: "ничего не выбрано"})
|
||||
return
|
||||
}
|
||||
_, err := s.CA.SubmitIPs(r.Context(), addresses)
|
||||
s.renderIPsTable(w, r, err)
|
||||
}
|
||||
|
||||
func (s *Server) handleIPsClear(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := s.CA.ClearQueue(r.Context())
|
||||
s.renderIPsTable(w, r, err)
|
||||
|
||||
Reference in new issue
Block a user