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
69 lines
2.0 KiB
Templ
69 lines
2.0 KiB
Templ
package web
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
)
|
|
|
|
// MapServer serves the map tiles, styles and the MapLibre library the
|
|
// region maps load.
|
|
const MapServer = "https://maps.zb-server.de"
|
|
|
|
// coord formats a coordinate for an attribute or input, empty for none.
|
|
func coord(f *float64) string {
|
|
if f == nil {
|
|
return ""
|
|
}
|
|
return strconv.FormatFloat(*f, 'f', -1, 64)
|
|
}
|
|
|
|
// HasLocation reports whether r has a place on the map.
|
|
func (r RegionOption) HasLocation() bool { return r.Lat != nil && r.Lon != nil }
|
|
|
|
// HasLocation reports whether r has a place on the map.
|
|
func (r Region) HasLocation() bool { return r.Lat != nil && r.Lon != nil }
|
|
|
|
// regionMap is a map of the regions marked with data-lat and data-lon
|
|
// inside the element items selects. In "select" mode a click on a marker
|
|
// toggles the region's checkbox; in "edit" mode a click on the map fills
|
|
// the active [data-location-form]. The script shows it once the map loads.
|
|
templ regionMap(mode, items string) {
|
|
<div
|
|
data-region-map={ mode }
|
|
data-region-items={ items }
|
|
data-map-server={ MapServer }
|
|
hidden
|
|
class="region-map mb-3 h-72 w-full overflow-hidden border border-rule"
|
|
></div>
|
|
}
|
|
|
|
// locationFields are the coordinate inputs of a region; empty ones remove
|
|
// the location.
|
|
templ locationFields(lat, lon *float64) {
|
|
<div class="flex flex-wrap gap-3">
|
|
for _, f := range []struct {
|
|
label, name, value, min, max string
|
|
}{
|
|
{i18n.T(ctx, "regions.latitude"), "latitude", coord(lat), "-90", "90"},
|
|
{i18n.T(ctx, "regions.longitude"), "longitude", coord(lon), "-180", "180"},
|
|
} {
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ f.label }</span>
|
|
<input
|
|
type="number"
|
|
step="any"
|
|
name={ f.name }
|
|
data-number
|
|
data-nullable
|
|
data-location-field={ f.name }
|
|
value={ f.value }
|
|
min={ f.min }
|
|
max={ f.max }
|
|
class="w-36 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
|
|
/>
|
|
</label>
|
|
}
|
|
</div>
|
|
}
|