ui: 30d repo-size sparkline on every dashboard host row

This commit is contained in:
2026-05-07 19:02:35 +01:00
parent 6e8a1c5b45
commit be4ac02ddd
5 changed files with 107 additions and 1 deletions
+21
View File
@@ -5,8 +5,10 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"html/template"
"io/fs"
"log/slog"
"math"
stdhttp "net/http"
"net/url"
"sort"
@@ -24,6 +26,7 @@ import (
"gitea.dcglab.co.uk/steve/restic-manager/internal/server/ws"
"gitea.dcglab.co.uk/steve/restic-manager/internal/store"
"gitea.dcglab.co.uk/steve/restic-manager/internal/version"
"gitea.dcglab.co.uk/steve/restic-manager/internal/web/sparkline"
"gitea.dcglab.co.uk/steve/restic-manager/web"
)
@@ -196,6 +199,10 @@ type dashboardHostRow struct {
// TargetVersion is the server's build version, surfaced in the
// chip's tooltip and label.
TargetVersion string
// RepoSparklineSVG is a server-rendered inline SVG showing the
// 30-day repo-size trend. Empty-state SVG (em-dash) is returned
// when no history rows exist for the host.
RepoSparklineSVG template.HTML
}
// pickRunAllSchedule returns the ID of the single schedule whose
@@ -296,6 +303,20 @@ func (s *Server) handleUIDashboard(w stdhttp.ResponseWriter, r *stdhttp.Request)
}
}
}
since := time.Now().UTC().AddDate(0, 0, -30)
pts, herr := s.deps.Store.ListHostRepoStatsHistory(r.Context(), h.ID, since)
if herr != nil {
slog.Warn("ui dashboard: list repo history", "host_id", h.ID, "err", herr)
}
sparkPoints := make([]float64, len(pts))
for i, p := range pts {
if p.TotalSizeBytes == nil {
sparkPoints[i] = math.NaN()
} else {
sparkPoints[i] = float64(*p.TotalSizeBytes)
}
}
row.RepoSparklineSVG = sparkline.RenderSparkline(sparkPoints, 88, 20)
rows = append(rows, row)
}