Files
uptimesebi/internal/web/checkers.templ
T
Sebastian UnterschützandClaude Opus 5.5 d7c5cd711e
ci / image (pull_request) Successful in 3m18s
ci / build (pull_request) Successful in 8m38s
ci / test (pull_request) Successful in 12m6s
ci / lint (pull_request) Successful in 15m0s
feat: page long and truncated lists
Lists that were cut off by a fixed LIMIT, or could grow without bound,
are paged by keyset: the cursor holds the sort key and an ID, so pages
neither skip nor repeat items as others are added. The audit logs had a
timestamp-only cursor that could skip entries with equal times.

The API returns at most 100 items per list (limit takes up to 500) with
next_cursor and prev_cursor, passed back as after and before. The
console shows Newer/Older (or Previous/Next) links and To the start,
without JavaScript.

Paged: incidents (optionally of one monitor), a monitor's results and
evidence, a checker's results, the audit logs, members, maintenance
windows, firing Alertmanager alerts, the monitors API and the admin
lists of status pages and organizations, which move to their own admin
pages. A monitor's page shows its latest incidents and results and links
to all of them. The dashboard caps every group at 50 of its own monitors
with a link to a paged view of the group, and gains a search by name or
target. Lists filtered by permission after reading may show fewer items
on a page.

Closes #116

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 21:40:25 +01:00

163 lines
4.6 KiB
Templ

package web
import (
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// CheckerView shows what a checker instance is doing.
type CheckerView struct {
ID string
Agent string
Region string
Platform bool
Release string
Started string
LastSeen string
Live bool
Queued int
Running []CheckerRun
OtherOrgs int
Checks int
Failed int
AvgLatency string
Recent []CheckerResult
Pager Pager
Siblings []CheckerLink
}
// CheckerRun is a check in progress.
type CheckerRun struct {
MonitorURL string
Monitor string
For string
}
// CheckerResult is a finished check of the instance.
type CheckerResult struct {
Time string
MonitorURL string
Monitor string
OK bool
Latency string
Detail string
}
// CheckerLink points to a checker instance.
type CheckerLink struct {
URL string
Label string
}
templ CheckerPage(p Page, me Me, v CheckerView) {
@consoleShell(p, me) {
<div class="mb-8">
<h1 class="flex items-center gap-2.5 text-lg font-semibold">
if v.Live {
@statusDot(StatusUp)
} else {
@statusDot(StatusUnknown)
}
{ v.Agent }
<span class="font-mono text-sm font-normal text-muted">{ v.ID[:8] }</span>
</h1>
<p class="mt-1 text-sm text-muted">
{ v.Region } ·
if v.Platform {
{ i18n.T(ctx, "regions.platform") }
} else {
{ i18n.T(ctx, "regions.own") }
}
·
if v.Live {
{ i18n.T(ctx, "checkers.live") }
} else {
{ i18n.T(ctx, "checkers.gone") }
}
</p>
</div>
<dl class="mb-10 grid grid-cols-2 gap-px border border-rule bg-rule sm:grid-cols-4">
@checkerFact("checkers.running", strconv.Itoa(len(v.Running)+v.OtherOrgs))
@checkerFact("checkers.queued", strconv.Itoa(v.Queued))
@checkerFact("checkers.last_hour", strconv.Itoa(v.Checks)+" / "+strconv.Itoa(v.Failed)+" ✕")
@checkerFact("checkers.avg_latency", v.AvgLatency)
@checkerFact("checkers.release", v.Release)
@checkerFact("checkers.started", v.Started)
@checkerFact("checkers.last_seen", v.LastSeen)
@checkerFact("checkers.instance", v.ID)
</dl>
<section class="mb-10">
@sectionHeading("checkers.now")
if len(v.Running) == 0 && v.OtherOrgs == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "checkers.idle") }</p>
} else {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, r := range v.Running {
<li class="flex justify-between gap-4 py-1.5">
<a href={ templ.SafeURL(r.MonitorURL) } class="hover:underline">{ r.Monitor }</a>
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "checkers.for", "Duration", r.For) }</span>
</li>
}
if v.OtherOrgs > 0 {
<li class="py-1.5 text-xs text-muted">{ i18n.T(ctx, "checkers.others", "Count", v.OtherOrgs) }</li>
}
</ul>
}
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "checkers.refresh_hint") }</p>
</section>
<section class="mb-10">
@sectionHeading("checkers.recent")
if len(v.Recent) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "checkers.no_recent") }</p>
} else {
<table class="w-full text-left text-sm">
<tbody class="divide-y divide-rule border-y border-rule">
for _, r := range v.Recent {
<tr>
<td class="py-1.5 pr-4 font-mono text-xs whitespace-nowrap text-muted">{ r.Time }</td>
<td class="py-1.5 pr-4"><a href={ templ.SafeURL(r.MonitorURL) } class="hover:underline">{ r.Monitor }</a></td>
<td class="py-1.5 pr-4">
if r.OK {
<span class="text-up">●</span>
} else {
<span class="text-down">●</span>
}
</td>
<td class="py-1.5 pr-4 font-mono text-xs">{ r.Latency }</td>
<td class="py-1.5 font-mono text-xs text-muted">{ r.Detail }</td>
</tr>
}
</tbody>
</table>
}
@pager(v.Pager, "newer", "older")
</section>
if len(v.Siblings) > 0 {
<section>
@sectionHeading("checkers.siblings")
<p class="flex flex-wrap gap-3 font-mono text-xs">
for _, sb := range v.Siblings {
<a href={ templ.SafeURL(sb.URL) } class="underline underline-offset-2">{ sb.Label }</a>
}
</p>
</section>
}
}
}
templ checkerFact(labelID, value string) {
<div class="bg-paper px-3 py-2">
<dt class="text-xs text-muted">{ i18n.T(ctx, labelID) }</dt>
<dd class="truncate font-mono text-sm" title={ value }>{ value }</dd>
</div>
}
templ checkerCell(l CheckerLink) {
if l.URL != "" {
<a href={ templ.SafeURL(l.URL) } class="hover:underline">{ l.Label }</a>
} else {
<span class="text-muted">{ l.Label }</span>
}
}