feat(regions): show checker regions on a map
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m48s
ci / test (pull_request) Successful in 12m42s
ci / build (pull_request) Canceled after 30s
ci / image (pull_request) Canceled after 0s

Regions get an optional location. Platform admins set it for platform
regions and org admins for their own, by clicking the map on the regions
page or entering the coordinates; PATCH /org/regions/:id and
/admin/regions/:id set or remove it.

The monitor form shows the located regions on a map from the
self-hosted ZB-Server Maps: a click on a marker ticks or unticks the
region, and the checkbox list stays the source of truth. MapLibre loads
only on pages with a map, and the map stays hidden if the map server
cannot be reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-28 20:17:27 +01:00
1 parent 3f260c0712
commit 3562f8224e
24 files changed
+3081 -1806

No files matched your search

+52 -3
View File
@@ -1,6 +1,10 @@
package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
import (
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// Region is a row in a region list.
type Region struct {
@@ -12,6 +16,9 @@ type Region struct {
// Manageable regions can be deleted on the current page.
Manageable bool
Instances int64
// Lat and Lon place the region on the map; both are nil without a
// location.
Lat, Lon *float64
}
// Agent is a checker or status page server.
@@ -65,6 +72,8 @@ type RegionsView struct {
templ regionsBody(v RegionsView) {
<section class="mb-12">
@sectionHeading("regions.list")
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "regions.location_pick_hint") }</p>
@regionMap("edit", "#region-list")
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
@@ -73,12 +82,20 @@ templ regionsBody(v RegionsView) {
<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 pr-4 font-medium">{ i18n.T(ctx, "regions.location") }</th>
<th class="py-2"></th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
<tbody id="region-list" class="divide-y divide-rule">
for _, r := range v.Regions {
<tr>
<tr
if r.HasLocation() {
data-lat={ coord(r.Lat) }
data-lon={ coord(r.Lon) }
}
data-name={ r.Name }
data-live={ strconv.FormatInt(r.Instances, 10) }
>
<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">
@@ -91,12 +108,41 @@ templ regionsBody(v RegionsView) {
<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 pr-4 font-mono text-xs">
if r.HasLocation() {
{ coord(r.Lat) }, { coord(r.Lon) }
} else {
<span class="text-muted">–</span>
}
if r.Manageable {
<button type="button" data-location-toggle={ "location-" + r.ID } class="ml-2 font-sans text-muted hover:text-ink">{ i18n.T(ctx, "regions.location_set") }</button>
}
</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>
if r.Manageable {
<tr id={ "location-" + r.ID } hidden>
<td colspan="6" class="py-3">
<form data-api={ v.APIBase + "/regions/" + r.ID } data-method="patch" data-next={ v.Next } data-location-form>
@formError()
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "regions.location_for", "Name", r.Name) }</p>
<div class="flex flex-wrap items-end gap-4">
@locationFields(r.Lat, r.Lon)
<div class="mb-4 flex gap-3">
<button type="submit" class="bg-ink px-3 py-1.5 text-sm font-medium text-paper hover:opacity-90 disabled:opacity-50">{ i18n.T(ctx, "common.save") }</button>
if r.HasLocation() {
<button type="button" data-location-clear class="text-sm text-muted hover:text-down">{ i18n.T(ctx, "regions.location_clear") }</button>
}
</div>
</div>
</form>
</td>
</tr>
}
}
</tbody>
</table>
@@ -109,6 +155,9 @@ templ regionsBody(v RegionsView) {
@formError()
@valueField(i18n.T(ctx, "regions.key"), "key", "", "office-berlin", true)
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Office Berlin", false)
<div data-location-form data-location-default>
@locationFields(nil, nil)
</div>
@submit(i18n.T(ctx, "regions.create"))
</form>
</section>