Files
uptimesebi/internal/web/testdata/regionmap.html
T
Sebastian UnterschützandClaude Opus 5.5 3562f8224e
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
feat(regions): show checker regions on a map
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
2026-11-28 20:17:27 +01:00

99 lines
5.5 KiB
HTML

<!doctype html><html><body data-msg-network="net">
<form id="monitor">
<div id="select-map" data-region-map="select" data-region-items="#monitor-regions" data-map-server="stub" hidden style="width:300px;height:200px"></div>
<div id="monitor-regions">
<label><input type="checkbox" name="regions" value="r1" data-multi checked data-lat="50.11" data-lon="8.68" data-name="Frankfurt" data-live="2"></label>
<label><input type="checkbox" name="regions" value="r2" data-multi data-lat="40.71" data-lon="-74.0" data-name="New York" data-live="0"></label>
<label><input type="checkbox" name="regions" value="r3" data-multi data-name="Office" data-live="1"></label>
</div>
</form>
<div id="edit-map" data-region-map="edit" data-region-items="#region-list" data-map-server="stub" hidden style="width:300px;height:200px"></div>
<table><tbody id="region-list">
<tr data-lat="50.11" data-lon="8.68" data-name="Frankfurt" data-live="2"><td><button type="button" id="toggle" data-location-toggle="location-r1">set</button></td></tr>
<tr id="location-r1" hidden><td><form data-api="/org/regions/r1" data-method="patch" data-next="#saved" data-location-form id="row-form">
<input name="latitude" data-number data-nullable data-location-field="latitude" value="50.11">
<input name="longitude" data-number data-nullable data-location-field="longitude" value="8.68">
<button type="submit">save</button><button type="button" id="clear" data-location-clear>clear</button>
</form></td></tr>
</tbody></table>
<form data-api="/org/regions" id="create"><div data-location-form data-location-default>
<input name="latitude" data-number data-nullable data-location-field="latitude">
<input name="longitude" data-number data-nullable data-location-field="longitude">
</div></form>
<pre id="out"></pre>
<script>
const sent = [];
window.axios = { create: () => ({ interceptors: { request: { use() {} } }, request: async (cfg) => { sent.push(cfg); return { data: {} }; } }) };
const maps = [];
window.maplibregl = {
Map: class {
constructor(opts) { this.container = opts.container; this.handlers = {}; this.style = opts.style; maps.push(this); }
on(ev, fn) { (this.handlers[ev] ??= []).push(fn); }
fire(ev, arg) { for (const fn of this.handlers[ev] ?? []) fn(arg); }
addControl() {}
resize() {}
fitBounds(b) { this.bounds = b.points; }
jumpTo(o) { this.center = o.center; }
setStyle(s) { this.style = s; }
},
Marker: class {
constructor(o) { this.el = o.element; }
setLngLat(p) { this.at = p; this.el.dataset.at = p.join(","); return this; }
addTo(map) { map.container.append(this.el); return this; }
},
NavigationControl: class {},
LngLatBounds: class {
constructor(a) { this.points = [a]; }
extend(p) { this.points.push(p); return this; }
},
};
</script>
<script src="../assets/app.js"></script>
<script>
(async () => {
const out = [];
const check = (name, got, want) => {
const g = JSON.stringify(got), w = JSON.stringify(want);
out.push((g === w ? "PASS " : "FAIL ") + name + (g === w ? "" : " got=" + g + " want=" + w));
};
await new Promise((r) => setTimeout(r, 50));
const sel = document.getElementById("select-map");
const markers = () => [...sel.querySelectorAll(".region-marker")];
const box = (v) => document.querySelector(`[value="${v}"]`);
check("select map shown", sel.hidden, false);
check("light style", maps[0].style, "stub/style-light.json");
check("markers for located regions", markers().map((m) => m.title), ["Frankfurt", "New York"]);
check("fits all markers", maps[0].bounds, [[8.68, 50.11], [-74, 40.71]]);
check("checked marker filled", markers().map((m) => m.classList.contains("is-checked")), [true, false]);
check("idle region marked", markers()[1].dataset.live, "0");
markers()[1].click();
check("marker click ticks checkbox", box("r2").checked, true);
check("marker follows", markers()[1].classList.contains("is-checked"), true);
box("r1").click();
check("checkbox untick clears marker", markers()[0].classList.contains("is-checked"), false);
const edit = maps[1];
const click = (lat, lng) => edit.fire("click", { lngLat: { lat, lng, wrap() { return { lat, lng: lng > 180 ? lng - 360 : lng }; } } });
click(48.137154, 11.576124);
const create = document.getElementById("create");
check("map click fills create form", [create.elements.latitude.value, create.elements.longitude.value], ["48.1372", "11.5761"]);
check("pick marker shown", document.querySelector("#edit-map .is-pick")?.dataset.at, "11.576124,48.137154");
document.querySelector("#edit-map .region-marker:not(.is-pick)").click();
check("marker click opens its row", document.getElementById("location-r1").hidden, false);
click(52.52, 373.4);
const row = document.getElementById("row-form");
check("map click fills open row", [row.elements.latitude.value, row.elements.longitude.value], ["52.52", "13.4"]);
check("create form untouched", create.elements.latitude.value, "48.1372");
document.getElementById("clear").click();
await new Promise((r) => setTimeout(r, 50));
check("clear sends nulls", sent.at(-1) && [sent.at(-1).method, sent.at(-1).url, sent.at(-1).data], ["patch", "/org/regions/r1", { latitude: null, longitude: null }]);
document.getElementById("toggle").click();
check("toggle closes row", document.getElementById("location-r1").hidden, true);
click(1, 2);
check("closed row falls back to create form", create.elements.latitude.value, "1");
document.getElementById("out").textContent = out.join("\n");
})();
</script>
</body></html>