Files
uptimesebi/internal/web/regions.templ
Sebastian UnterschützandClaude Opus 5.5 fb03b28df7
ci / image (pull_request) Successful in 2m32s
ci / build (pull_request) Successful in 7m28s
ci / lint (pull_request) Successful in 8m54s
ci / test (pull_request) Successful in 13m7s
feat: platform admins can switch off check types
Types an installation cannot offer, such as Docker on shared cloud
checkers, can be switched off in the admin panel. They are not offered
in the editor or accepted by the API for new monitors or type changes;
existing monitors keep running and stay editable. The setting lives in
a new platform_settings table and reaches every replica at once through
the versioned cache. GET /api/v1/org/check-types lists what is offered.

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

183 lines
6.6 KiB
Templ

package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Region is a row in a region list.
type Region struct {
ID string
Key string
Name string
// Platform regions are shared by all organizations.
Platform bool
// Manageable regions can be deleted on the current page.
Manageable bool
Instances int64
}
// Agent is a checker or status page server.
type Agent struct {
ID string
Kind string
Name string
Region string
Prefix string
LastSeen string
}
// RegionsView is the data of the org regions page and the admin panel.
type RegionsView struct {
Regions []Region
Agents []Agent
// APIBase is the prefix of the endpoints the forms post to, either
// /org or /admin.
APIBase string
// Next is the page to reload after a change.
Next string
// OwnRegions are the regions agents can be created in.
OwnRegions []Region
}
templ regionsBody(v RegionsView) {
<section class="mb-12">
@sectionHeading("regions.list")
<table class="w-full 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, "sso.field.name") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "regions.key") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "regions.owner") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "regions.instances") }</th>
<th class="py-2"></th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
for _, r := range v.Regions {
<tr>
<td class="py-2.5 pr-4">{ r.Name }</td>
<td class="py-2.5 pr-4 font-mono text-xs">{ r.Key }</td>
<td class="py-2.5 pr-4">
if r.Platform {
<span class="text-muted">{ i18n.T(ctx, "regions.platform") }</span>
} else {
{ i18n.T(ctx, "regions.own") }
}
</td>
<td class="py-2.5 pr-4 font-mono text-xs">
<span class={ templ.KV("text-up", r.Instances > 0), templ.KV("text-unknown", r.Instances == 0) }>●</span> { i18n.T(ctx, "regions.live", "Count", int(r.Instances)) }
</td>
<td class="py-2.5 text-right">
if r.Manageable {
<button type="button" data-delete={ v.APIBase + "/regions/" + r.ID } data-confirm={ i18n.T(ctx, "regions.delete_confirm") } class="text-muted hover:text-down">{ i18n.T(ctx, "regions.delete") }</button>
}
</td>
</tr>
}
</tbody>
</table>
</section>
<div class="mb-12 grid gap-12 md:grid-cols-2">
<section>
@sectionHeading("regions.create")
<form data-api={ v.APIBase + "/regions" } data-next={ v.Next }>
@formError()
@valueField(i18n.T(ctx, "regions.key"), "key", "", "office-berlin", true)
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Office Berlin", false)
@submit(i18n.T(ctx, "regions.create"))
</form>
</section>
<section>
@sectionHeading("agents.create")
<form data-api={ v.APIBase + "/agents" } data-show-link>
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "checker-1", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "agents.kind") }</span>
<select name="kind" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="checker">{ i18n.T(ctx, "agents.kind_checker") }</option>
<option value="statuspage">{ i18n.T(ctx, "agents.kind_statuspage") }</option>
</select>
</label>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "agents.region") }</span>
<select name="region_id" data-nullable class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="">{ i18n.T(ctx, "agents.no_region") }</option>
for _, r := range v.OwnRegions {
<option value={ r.ID }>{ r.Name }</option>
}
</select>
</label>
@submit(i18n.T(ctx, "agents.create"))
<div data-link-output hidden class="mt-6 border border-ink p-4">
<p class="mb-2 text-sm">{ i18n.T(ctx, "agents.token_now") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
</div>
</form>
</section>
</div>
if len(v.Agents) > 0 {
<section>
@sectionHeading("agents.list")
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, a := range v.Agents {
<li class="flex items-center justify-between gap-4 py-2">
<span>
{ a.Name }
<span class="text-muted">· { i18n.T(ctx, "agents.kind_"+a.Kind) }</span>
if a.Region != "" {
<span class="text-muted">· { a.Region }</span>
}
<span class="block font-mono text-xs text-muted">{ a.Prefix }… · { a.LastSeen }</span>
</span>
<button type="button" data-delete={ v.APIBase + "/agents/" + a.ID } data-confirm={ i18n.T(ctx, "agents.revoke_confirm") } class="text-muted hover:text-down">{ i18n.T(ctx, "members.revoke") }</button>
</li>
}
</ul>
</section>
}
}
templ RegionsPage(p Page, me Me, v RegionsView) {
@consoleShell(p, me) {
@settingsHeading("regions.title", "regions.intro")
@regionsBody(v)
}
}
templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption) {
@consoleShell(p, me) {
@settingsHeading("admin.title", "admin.intro")
<p class="-mt-4 mb-8 flex gap-4 text-sm">
<a href="/admin/audit" class="underline underline-offset-2">{ i18n.T(ctx, "audit.platform_title") }</a>
<a href="/admin/legal" class="underline underline-offset-2">{ i18n.T(ctx, "legal.platform_title") }</a>
</p>
@regionsBody(v)
@checkTypesSection(checkTypes)
@storageSection(storage)
}
}
// CheckTypeOption is a check type in the admin panel.
type CheckTypeOption struct {
Type string
Enabled bool
}
templ checkTypesSection(types []CheckTypeOption) {
<section class="mt-12 max-w-3xl">
@sectionHeading("admin.check_types")
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "admin.check_types_intro") }</p>
<form data-api="/admin/check-types" data-method="put" data-next="/admin">
@formError()
<div class="mb-4 grid grid-cols-2 gap-x-6 gap-y-1.5 text-sm sm:grid-cols-3">
for _, t := range types {
<label class="flex items-center gap-2">
<input type="checkbox" name="enabled" value={ t.Type } data-multi checked?={ t.Enabled } class="accent-ink"/>
{ i18n.T(ctx, "monitors.type_"+t.Type) }
</label>
}
</div>
<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>
}