Files
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

216 lines
9.3 KiB
Templ
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"context"
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// LimitsView holds limits; 0 means unlimited.
type LimitsView struct {
Monitors int
StatusPages int
RegionsPerMonitor int
OwnRegionsCount bool
OrgsPerAccount int
}
// OrgsView lists organizations for platform admins.
type OrgsView struct {
Search string
Orgs []OrgRow
Pager Pager
Defaults LimitsView
// Next is the page to return to after an action.
Next string
}
// OrgRow is an organization with its usage and limits. Overrides are form
// values: empty follows the default.
type OrgRow struct {
ID, Name, Slug, Created, Suspended string
Monitors, StatusPages int
Limits LimitsView
MonitorsOverride string
StatusPagesOverride string
RegionsOverride string
OwnRegionsOverride string
Owner *ModeratedTarget
OwnerOrgs int
OwnerOrgLimit string
}
func (v OrgsView) next() string { return v.Next }
// limitText shows a limit, or "unlimited".
func limitText(ctx context.Context, n int) string {
if n == 0 {
return i18n.T(ctx, "limits.unlimited")
}
return strconv.Itoa(n)
}
templ limitsSection(d LimitsView) {
<section id="limits" class="mb-12 max-w-3xl">
@sectionHeading("limits.title")
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "limits.intro") }</p>
<form data-api="/admin/limits" data-method="put" data-next="/admin#limits">
@formError()
<div class="grid gap-x-6 sm:grid-cols-2">
@numberField(i18n.T(ctx, "limits.monitors"), "monitors", d.Monitors, 0, 1000000, "")
@numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "")
@numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "")
@numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "")
</div>
@checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount)
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_count_hint") }</p>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
</section>
}
// overrideField is a limit an organization may override: empty follows
// the default, shown as placeholder.
templ overrideField(label, name, value string, def int, max int) {
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ label }</span>
<input
type="number"
name={ name }
data-number
data-nullable
min="0"
max={ strconv.Itoa(max) }
value={ value }
placeholder={ i18n.T(ctx, "limits.default", "Value", limitText(ctx, def)) }
class="w-full border border-rule bg-transparent px-2 py-1 font-mono text-sm outline-none focus:border-ink"
/>
</label>
}
templ orgsSection(v OrgsView) {
<section id="orgs" class="mb-12">
@sectionHeading("orgs.title")
<p class="mb-4 max-w-3xl text-sm text-muted">{ i18n.T(ctx, "orgs.intro") }</p>
<form method="get" action="/admin/orgs" class="mb-4 flex max-w-xl gap-2">
<input
type="search"
name="q"
value={ v.Search }
placeholder={ i18n.T(ctx, "orgs.search") }
aria-label={ i18n.T(ctx, "orgs.search") }
class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"
/>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "moderation.search_button") }</button>
</form>
if len(v.Orgs) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "orgs.none") }</p>
} else {
<div class="overflow-x-auto">
<table class="w-full min-w-[42rem] text-left text-sm">
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
<tr>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.org") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.owner") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "limits.monitors") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "limits.status_pages") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.created") }</th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
for _, o := range v.Orgs {
<tr class="align-top">
<td class="py-2.5 pr-4">
{ o.Name }
<span class="block font-mono text-xs text-muted">{ o.Slug }</span>
@moderationState(o.Suspended, false)
</td>
<td class="py-2.5 pr-4">
if o.Owner != nil {
<span class="break-all">{ o.Owner.Name }</span>
@moderationState(o.Owner.Suspended, false)
} else {
<span class="text-muted">–</span>
}
</td>
<td class="py-2.5 pr-4 font-mono text-xs">@usage(o.Monitors, o.Limits.Monitors)</td>
<td class="py-2.5 pr-4 font-mono text-xs">@usage(o.StatusPages, o.Limits.StatusPages)</td>
<td class="py-2.5 pr-4 font-mono text-xs text-muted">{ o.Created }</td>
</tr>
<tr>
<td colspan="5" class="pb-3">
<details class="text-sm">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "orgs.manage") }</summary>
<div class="mt-3 grid gap-6 md:grid-cols-3">
<form data-api={ "/admin/orgs/" + o.ID + "/limits" } data-method="put" data-next={ v.next() }>
<h4 class="mb-2 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "orgs.limits") }</h4>
@formError()
@overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000)
@overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000)
@overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000)
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "limits.own_regions_count") }</span>
<select name="own_regions_count" class="w-full border border-rule bg-transparent px-2 py-1 text-sm">
<option value="" selected?={ o.OwnRegionsOverride == "" }>{ i18n.T(ctx, "limits.default", "Value", i18n.T(ctx, "limits.own_"+strconv.FormatBool(v.Defaults.OwnRegionsCount))) }</option>
<option value="true" selected?={ o.OwnRegionsOverride == "true" }>{ i18n.T(ctx, "limits.own_true") }</option>
<option value="false" selected?={ o.OwnRegionsOverride == "false" }>{ i18n.T(ctx, "limits.own_false") }</option>
</select>
</label>
<button type="submit" class="border border-ink px-2.5 py-1 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
@moderationActions("org", "/admin/orgs/"+o.ID, o.Suspended, o.Name, v.next())
if o.Owner != nil && o.Owner.Admin {
<p class="text-xs text-muted">{ i18n.T(ctx, "moderation.owner_is_admin") }</p>
} else if o.Owner != nil {
<div>
<form data-api={ "/admin/users/" + o.Owner.ID + "/limits" } data-method="put" data-next={ v.next() } class="mb-4">
<h4 class="mb-2 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "moderation.target_owner") }</h4>
@formError()
@overrideField(i18n.T(ctx, "orgs.owner_orgs", "Count", o.OwnerOrgs), "orgs", o.OwnerOrgLimit, v.Defaults.OrgsPerAccount, 100000)
<button type="submit" class="border border-ink px-2.5 py-1 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
@moderationActions("owner", "/admin/users/"+o.Owner.ID, o.Owner.Suspended, o.Owner.Name, v.next())
</div>
}
</div>
</details>
</td>
</tr>
}
</tbody>
</table>
</div>
}
@pager(v.Pager, "newer", "older")
</section>
}
// usage shows "used / limit", marking a reached limit.
templ usage(used, max int) {
<span class={ templ.KV("text-down", max > 0 && used >= max) }>{ strconv.Itoa(used) } / { limitText(ctx, max) }</span>
}
// UsageView is an organization's usage of its limits.
type UsageView struct {
Limits LimitsView
Monitors, StatusPages int
}
templ usageSection(u UsageView) {
<section class="mb-12 max-w-xl">
@sectionHeading("limits.org_title")
<dl class="grid grid-cols-[1fr_auto] gap-x-6 gap-y-1.5 text-sm">
<dt>{ i18n.T(ctx, "limits.monitors") }</dt>
<dd class="font-mono text-xs">@usage(u.Monitors, u.Limits.Monitors)</dd>
<dt>{ i18n.T(ctx, "limits.status_pages") }</dt>
<dd class="font-mono text-xs">@usage(u.StatusPages, u.Limits.StatusPages)</dd>
<dt>{ i18n.T(ctx, "limits.regions_per_monitor") }</dt>
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.RegionsPerMonitor) }</dd>
</dl>
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_free") }</p>
}
</section>
}