Files
restic-manager/web/templates/partials/host_row.html
T
steve 86f7c17d9d P1-24: live dashboard — fleet summary tiles + host table
Server-rendered HTML view backed by:
  - new store.FleetSummary aggregating host counts + repo bytes +
    snapshot total + open alerts + last-24h job rollup in two queries.
  - GET /api/hosts (JSON list of hosts in the dashboard projection).
  - GET /api/fleet/summary (JSON aggregate, same shape as above).

The HTML page (web/templates/pages/dashboard.html) renders the four
summary tiles + host table directly from store data — no separate
fetch. Per-row state colour comes from .host-row.{degraded,failed,
offline} which paint a 3px left edge so problem hosts are scannable
without reading. HTMX is loaded into the base layout so per-row
"Run now" buttons can hx-post to /hosts/{id}/run-backup, a thin
HTML wrapper that funnels into a new dispatchJob helper shared
with the JSON /api/hosts/{id}/jobs endpoint.

Empty state (zero hosts) collapses to the "no hosts yet" prompt
with the + Add host CTA — matches the v1 mockup.

Template helpers (internal/server/ui/funcs.go) added for byte
formatting (412 GB / 3.7 TB), relative time (3m ago / 2d ago), and
comma grouping (1,847). Pure Go, no template-magic dependency.

Browser-verified end-to-end with seeded fixture data: five hosts
across all four states render with correct dots, accents, last-
backup pills, sizes, snapshot counts, alerts, tags, and the right
action button (Run now / Retry / Run first / View → / offline).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 19:29:11 +01:00

72 lines
3.1 KiB
HTML

{{define "host_row"}}
<div class="row-hover host-row hairline {{.Status}}{{if eq (deref .LastBackupStatus) "failed"}} failed{{end}}">
<div>
{{- if eq .Status "online" -}}
<span class="dot dot-online{{if .CurrentJobID}} pulse{{end}}"></span>
{{- else if eq .Status "degraded" -}}
<span class="dot dot-degraded"></span>
{{- else if eq .Status "offline" -}}
<span class="dot dot-offline"></span>
{{- else -}}
<span class="dot dot-failed"></span>
{{- end -}}
</div>
<div class="mono {{if eq .Status "offline"}}text-ink-mid{{else}}text-ink{{end}} font-medium">{{.Name}}</div>
<div class="mono text-ink-mid text-[12px]">{{.OS}}/{{.Arch}}</div>
<div class="text-xs text-ink-mid">
{{- if .CurrentJobID -}}
<span class="text-accent">backup running…</span><br>
<span class="mono text-ink-fade">started {{relTime .LastBackupAt}}</span>
{{- else if eq (deref .LastBackupStatus) "succeeded" -}}
<span class="text-ok">succeeded</span> · <span class="mono">{{relTime .LastBackupAt}}</span>
{{- else if eq (deref .LastBackupStatus) "failed" -}}
<span class="text-bad font-medium">failed</span> · <span class="mono">{{relTime .LastBackupAt}}</span>
{{- else if eq (deref .LastBackupStatus) "cancelled" -}}
<span class="text-warn">cancelled</span> · <span class="mono">{{relTime .LastBackupAt}}</span>
{{- else if eq .Status "offline" -}}
<span class="text-ink-mute">last seen <span class="mono">{{relTime .LastSeenAt}}</span></span>
{{- else -}}
<span class="text-ink-fade italic">never run</span>
{{- end -}}
</div>
<div class="text-right mono {{if eq .Status "offline"}}text-ink-mid{{else}}text-ink{{end}}">{{bytes .RepoSizeBytes}}</div>
<div class="text-right mono {{if eq .Status "offline"}}text-ink-mute{{else}}text-ink-mid{{end}}">
{{- if eq .SnapshotCount 0 -}}
<span class="text-ink-fade"></span>
{{- else -}}
{{comma .SnapshotCount}}
{{- end -}}
</div>
<div class="text-right mono {{if gt .OpenAlertCount 0}}text-bad font-medium{{else}}text-ink-mute{{end}}">
{{- if eq .OpenAlertCount 0 -}}—{{- else -}}{{.OpenAlertCount}}{{- end -}}
</div>
<div class="flex gap-1.5 flex-wrap">
{{- range .Tags -}}
<span class="tag">{{.}}</span>
{{- end -}}
</div>
<div class="text-right">
{{- if eq .Status "offline" -}}
<span class="mono text-xs text-ink-fade">offline</span>
{{- else if .CurrentJobID -}}
<a href="/hosts/{{.ID}}" class="btn btn-ghost">View →</a>
{{- else if eq (deref .LastBackupStatus) "failed" -}}
<button class="btn"
hx-post="/hosts/{{.ID}}/run-backup"
hx-swap="none"
hx-disabled-elt="this">Retry</button>
{{- else if eq .SnapshotCount 0 -}}
<button class="btn"
hx-post="/hosts/{{.ID}}/run-backup"
hx-swap="none"
hx-disabled-elt="this">Run first</button>
{{- else -}}
<button class="btn"
hx-post="/hosts/{{.ID}}/run-backup"
hx-swap="none"
hx-disabled-elt="this">Run now</button>
{{- end -}}
</div>
</div>
{{end}}