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
220 lines
7.4 KiB
Templ
220 lines
7.4 KiB
Templ
package web
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
)
|
|
|
|
// MaintenanceView is the maintenance page: planned windows and the form to
|
|
// add or edit one.
|
|
type MaintenanceView struct {
|
|
Windows []MaintenanceRow
|
|
Pager Pager
|
|
Form MaintenanceForm
|
|
Monitors []TargetOption
|
|
Groups []TargetOption
|
|
CanWrite bool
|
|
}
|
|
|
|
// MaintenanceRow is one planned window.
|
|
type MaintenanceRow struct {
|
|
ID string
|
|
Title string
|
|
Schedule string
|
|
Targets string
|
|
Next string
|
|
Active bool
|
|
Description string
|
|
CanWrite bool
|
|
}
|
|
|
|
// MaintenanceForm holds the values of the form; ID is empty for a new window.
|
|
type MaintenanceForm struct {
|
|
ID string
|
|
Title string
|
|
Description string
|
|
Start string
|
|
TimeZone string
|
|
Duration int
|
|
Recurrence string
|
|
Every int
|
|
Weekdays map[int]bool
|
|
Until string
|
|
Monitors map[string]bool
|
|
Groups map[string]bool
|
|
}
|
|
|
|
// TargetOption is a monitor or group to choose; Depth indents groups.
|
|
type TargetOption struct {
|
|
ID string
|
|
Name string
|
|
Depth int
|
|
}
|
|
|
|
templ maintenanceList(items []MaintenanceItem) {
|
|
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
|
for _, m := range items {
|
|
<li class="py-3">
|
|
<div class="flex items-center gap-2">
|
|
@statusDot(StatusMaintenance)
|
|
<span class="font-medium">{ m.Title }</span>
|
|
if m.Active {
|
|
<span class="font-mono text-xs text-maintenance">{ i18n.T(ctx, "maintenance.in_progress") }</span>
|
|
}
|
|
</div>
|
|
<p class="ml-4 mt-0.5 font-mono text-xs text-muted">{ m.When }</p>
|
|
if m.Description != "" {
|
|
<div class="legal-text ml-4 mt-2 text-muted">
|
|
@templ.Raw(m.Description)
|
|
</div>
|
|
}
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
|
|
templ MaintenancePage(p Page, me Me, v MaintenanceView) {
|
|
@consoleShell(p, me) {
|
|
@settingsHeading("maintenance.title", "maintenance.intro")
|
|
if len(v.Windows) == 0 {
|
|
<p class="mb-10 text-sm text-muted">{ i18n.T(ctx, "maintenance.empty") }</p>
|
|
} else {
|
|
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, w := range v.Windows {
|
|
<li class="grid gap-1 py-3 sm:grid-cols-[1fr_auto]">
|
|
<div>
|
|
<div class="flex items-center gap-2">
|
|
@statusDot(StatusMaintenance)
|
|
<span class="font-medium">{ w.Title }</span>
|
|
if w.Active {
|
|
<span class="font-mono text-xs text-maintenance">{ i18n.T(ctx, "maintenance.in_progress") }</span>
|
|
}
|
|
</div>
|
|
<p class="ml-4 mt-0.5 text-xs text-muted">{ w.Schedule }</p>
|
|
<p class="ml-4 text-xs text-muted">{ w.Targets }</p>
|
|
if w.Next != "" {
|
|
<p class="ml-4 font-mono text-xs text-muted">{ i18n.T(ctx, "maintenance.next", "Time", w.Next) }</p>
|
|
}
|
|
if w.Description != "" {
|
|
<div class="legal-text ml-4 mt-2 text-muted">
|
|
@templ.Raw(w.Description)
|
|
</div>
|
|
}
|
|
</div>
|
|
if w.CanWrite {
|
|
<div class="flex items-start gap-4 text-sm">
|
|
<a href={ templ.SafeURL("/maintenance?edit=" + w.ID) } class="text-muted hover:text-ink">{ i18n.T(ctx, "common.edit") }</a>
|
|
<button type="button" data-delete={ "/org/maintenance/" + w.ID } data-confirm={ i18n.T(ctx, "maintenance.delete_confirm") } data-next="/maintenance" class="text-muted hover:text-down">{ i18n.T(ctx, "common.delete") }</button>
|
|
</div>
|
|
}
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
@pager(v.Pager, "later", "earlier")
|
|
if v.CanWrite {
|
|
@maintenanceForm(v)
|
|
}
|
|
}
|
|
}
|
|
|
|
templ maintenanceForm(v MaintenanceView) {
|
|
<section class="max-w-2xl">
|
|
if v.Form.ID == "" {
|
|
@sectionHeading("maintenance.new")
|
|
} else {
|
|
@sectionHeading("maintenance.edit")
|
|
}
|
|
<form
|
|
data-api={ maintenanceAPI(v.Form.ID) }
|
|
data-method={ maintenanceMethod(v.Form.ID) }
|
|
data-next="/maintenance"
|
|
>
|
|
@formError()
|
|
@labeled("maintenance.field_title") {
|
|
<input name="title" required maxlength="200" value={ v.Form.Title } class={ inputClass }/>
|
|
}
|
|
<div class="mb-4">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_description") }</span>
|
|
@MarkdownEditor("description", v.Form.Description, 5, 20000, MarkdownInline)
|
|
</div>
|
|
<div class="grid gap-4 sm:grid-cols-3">
|
|
@labeled("maintenance.field_start") {
|
|
<input type="datetime-local" name="start" required value={ v.Form.Start } class={ inputClass }/>
|
|
}
|
|
@labeled("maintenance.field_duration") {
|
|
<input type="number" name="duration_minutes" data-number min="1" max="43200" required value={ strconv.Itoa(v.Form.Duration) } class={ inputClass }/>
|
|
}
|
|
@labeled("maintenance.field_time_zone") {
|
|
<input name="time_zone" required list="time-zones" value={ v.Form.TimeZone } data-tz-default class={ inputClass }/>
|
|
<datalist id="time-zones">
|
|
for _, tz := range commonTimeZones {
|
|
<option value={ tz }></option>
|
|
}
|
|
</datalist>
|
|
}
|
|
</div>
|
|
<div class="grid gap-4 sm:grid-cols-3">
|
|
@labeled("maintenance.field_recurrence") {
|
|
<select name="recurrence" class={ inputClass }>
|
|
for _, r := range []string{"none", "daily", "weekly", "monthly"} {
|
|
<option value={ r } selected?={ v.Form.Recurrence == r }>{ i18n.T(ctx, "maintenance.recurrence_" + r) }</option>
|
|
}
|
|
</select>
|
|
}
|
|
@labeled("maintenance.field_every") {
|
|
<input type="number" name="every" data-number min="1" max="365" value={ strconv.Itoa(max(v.Form.Every, 1)) } class={ inputClass }/>
|
|
}
|
|
@labeled("maintenance.field_until") {
|
|
<input type="date" name="until" value={ v.Form.Until } class={ inputClass }/>
|
|
}
|
|
</div>
|
|
<fieldset class="mb-4">
|
|
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_weekdays") }</legend>
|
|
<div class="flex flex-wrap gap-3 text-sm">
|
|
for _, d := range []int{1, 2, 3, 4, 5, 6, 0} {
|
|
<label class="flex items-center gap-1.5">
|
|
<input type="checkbox" name="weekdays" data-multi value={ strconv.Itoa(d) } checked?={ v.Form.Weekdays[d] }/>
|
|
{ i18n.T(ctx, "weekday." + strconv.Itoa(d)) }
|
|
</label>
|
|
}
|
|
</div>
|
|
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "maintenance.weekdays_hint") }</span>
|
|
</fieldset>
|
|
<div class="mb-4 grid gap-6 sm:grid-cols-2">
|
|
<fieldset>
|
|
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_groups") }</legend>
|
|
<div class="max-h-60 overflow-y-auto border border-rule p-2 text-sm">
|
|
for _, g := range v.Groups {
|
|
<label class="flex items-center gap-1.5" style={ indent(g.Depth) }>
|
|
<input type="checkbox" name="group_ids" data-multi value={ g.ID } checked?={ v.Form.Groups[g.ID] }/>
|
|
{ g.Name }
|
|
</label>
|
|
}
|
|
</div>
|
|
</fieldset>
|
|
<fieldset>
|
|
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_monitors") }</legend>
|
|
<div class="max-h-60 overflow-y-auto border border-rule p-2 text-sm">
|
|
for _, m := range v.Monitors {
|
|
<label class="flex items-center gap-1.5">
|
|
<input type="checkbox" name="monitor_ids" data-multi value={ m.ID } checked?={ v.Form.Monitors[m.ID] }/>
|
|
{ m.Name }
|
|
</label>
|
|
}
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
</section>
|
|
}
|
|
|
|
templ labeled(labelID string) {
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, labelID) }</span>
|
|
{ children... }
|
|
</label>
|
|
}
|