ui: alerts list page + alert row partial + nav badge

This commit is contained in:
2026-05-04 20:15:01 +01:00
parent 5d8350132c
commit 35dee98cf9
8 changed files with 320 additions and 1 deletions
+1
View File
@@ -60,6 +60,7 @@ func (s *Server) handleUIAlerts(w stdhttp.ResponseWriter, r *stdhttp.Request) {
page.Counts = computeAlertCounts(s, r)
view := s.baseView(u)
view.OpenAlerts = page.Counts.Open
view.Title = "Alerts · restic-manager"
view.Active = "alerts"
view.Page = page
+4
View File
@@ -89,6 +89,10 @@ func (s *Server) requireUIUser(w stdhttp.ResponseWriter, r *stdhttp.Request) *ui
// authenticated page. Every UI page sits under the dashboard primary
// nav today; if a future page lives under a different primary nav
// tab (e.g. Settings, Audit), accept an Active arg again.
//
// OpenAlerts is populated via a quick store count so the nav badge
// stays current on every page load without requiring a page-specific
// store call.
func (s *Server) baseView(u *ui.User) ui.ViewData {
return ui.ViewData{
User: u,
+62
View File
@@ -38,6 +38,68 @@ func funcMap() template.FuncMap {
// list packs strings into a slice — handy for inline ranges
// in templates (e.g. quick-pick cron presets).
"list": func(items ...string) []string { return items },
// dict builds a map[string]any from alternating key-value pairs.
// Useful for passing multiple named values to a sub-template:
// {{template "foo" (dict "A" $a "B" $b)}}
"dict": func(pairs ...any) map[string]any {
m := make(map[string]any, len(pairs)/2)
for i := 0; i+1 < len(pairs); i += 2 {
if k, ok := pairs[i].(string); ok {
m[k] = pairs[i+1]
}
}
return m
},
// mapGet retrieves a string value from a map[string]string by key.
// Returns "" when the key is absent or the map is nil. Used by the
// alert_row partial to resolve host_id → host name.
"mapGet": func(m map[string]string, key *string) string {
if m == nil || key == nil {
return ""
}
return m[*key]
},
// alertStatus derives the display status of an alert from its DB
// fields: "open", "acknowledged", or "resolved".
// Accepts any value — returns "" for unrecognised input so templates
// can still render safely.
"alertStatus": func(resolvedAt, acknowledgedAt any) string {
isSet := func(v any) bool {
if v == nil {
return false
}
switch t := v.(type) {
case *time.Time:
return t != nil
}
return false
}
if isSet(resolvedAt) {
return "resolved"
}
if isSet(acknowledgedAt) {
return "acknowledged"
}
return "open"
},
// stillHappening returns true when last_seen_at is within the last
// 60 seconds — used to render the "still happening · Ns ago" pill
// on alert rows where the signal is still firing.
"stillHappening": func(v any) bool {
var t time.Time
switch x := v.(type) {
case time.Time:
t = x
case *time.Time:
if x == nil {
return false
}
t = *x
default:
return false
}
return time.Since(t) < 60*time.Second
},
}
}
+1
View File
@@ -93,6 +93,7 @@ func New() (*Renderer, error) {
"templates/partials/awaiting_agent.html",
"templates/partials/host_chrome.html",
"templates/partials/tree_node.html",
"templates/partials/alert_row.html",
}
pageEntries, err := fs.Glob(web.FS, "templates/pages/*.html")