Add a logged-in-only status/debug panel at the bottom of the sidebar
Dumps every read-only status endpoint (health, offline/terrain build status, regions, caches, hiking trails, kiwix, plugins, GNSS, LiveTrack) as JSON, refreshed every 5s while open so a running build's progress shows live.
This commit is contained in:
1 parent
0051a0337c
commit
cf483d183c
6 files changed
+137
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import { DEBUG_ICON } from "/js/icons.js";
|
||||
import { escapeHtml } from "/js/gpx.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||
|
||||
// Every read-only status endpoint, dumped as raw JSON. No check-update
|
||||
// routes here — those reach out to Geofabrik/the internet, not just report
|
||||
// local state.
|
||||
const ENDPOINTS = [
|
||||
"/api/health",
|
||||
"/api/offline-tiles",
|
||||
"/api/offline-tiles/build-status",
|
||||
"/api/offline-regions",
|
||||
"/api/offline-tiles/cache",
|
||||
"/api/terrain-tiles",
|
||||
"/api/terrain-tiles/build-status",
|
||||
"/api/hiking-trails",
|
||||
"/api/kiwix",
|
||||
"/api/plugins",
|
||||
"/api/gnss/position",
|
||||
"/api/livetrack/sessions",
|
||||
];
|
||||
const REFRESH_MS = 5000; // while open — a running build's progress shows up live
|
||||
|
||||
// Sidebar icon pinned to the bottom of the rail, logged-in only (map.js).
|
||||
export class DebugControl {
|
||||
mount(sidebar) {
|
||||
this._container = document.createElement("div");
|
||||
this._container.className = "sidebar-item sidebar-item--bottom";
|
||||
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Status / debug" aria-label="Status / debug">${DEBUG_ICON}</button>`;
|
||||
this._icon = this._container.querySelector(".sidebar-icon");
|
||||
this._icon.addEventListener("click", () => this._togglePanel());
|
||||
|
||||
this._panel = document.getElementById("debug-panel");
|
||||
this._body = this._panel.querySelector(".debug-panel__body");
|
||||
this._panel.querySelector(".basemap-panel__close").addEventListener("click", () => this._togglePanel(false));
|
||||
onlyOneSidePanelOpen(this._panel, () => this._stop());
|
||||
|
||||
sidebar.appendChild(this._container);
|
||||
}
|
||||
|
||||
_togglePanel(force) {
|
||||
const open = force === undefined ? this._panel.hidden : force;
|
||||
this._panel.hidden = !open;
|
||||
if (!open) return this._stop();
|
||||
|
||||
this._icon.classList.add("active");
|
||||
notifySidePanelOpen(this._panel);
|
||||
this._refresh();
|
||||
this._timer = setInterval(() => this._refresh(), REFRESH_MS);
|
||||
}
|
||||
|
||||
_stop() {
|
||||
this._icon.classList.remove("active");
|
||||
clearInterval(this._timer);
|
||||
}
|
||||
|
||||
async _refresh() {
|
||||
const sections = await Promise.all(
|
||||
ENDPOINTS.map(async (url) => {
|
||||
let text;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const body = await response.text();
|
||||
try {
|
||||
text = JSON.stringify(JSON.parse(body), null, 2);
|
||||
} catch {
|
||||
text = body;
|
||||
}
|
||||
if (!response.ok) text = `HTTP ${response.status}\n${text}`;
|
||||
} catch (error) {
|
||||
text = `request failed: ${error.message}`;
|
||||
}
|
||||
return { url, text };
|
||||
}),
|
||||
);
|
||||
if (this._panel.hidden) return;
|
||||
|
||||
// Keep whichever sections the user collapsed collapsed across refreshes.
|
||||
const closed = new Set([...this._body.querySelectorAll("details:not([open])")].map((el) => el.dataset.url));
|
||||
this._body.innerHTML = sections
|
||||
.map(
|
||||
({ url, text }) => `
|
||||
<details data-url="${url}" ${closed.has(url) ? "" : "open"}>
|
||||
<summary>${url}</summary>
|
||||
<pre>${escapeHtml(text)}</pre>
|
||||
</details>
|
||||
`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
}
|
||||
@@ -436,6 +436,13 @@ export const OFFLINE_DATA_ICON = `
|
||||
// OSM/p4n2gpx category and doubles as the note icon-picker's option list
|
||||
// (notes.js), neither of which applies here — every point on this layer
|
||||
// gets the same one glyph, there's no per-feature category to key it by.
|
||||
// A bug — the status/debug panel (debug.js).
|
||||
export const DEBUG_ICON = `
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
|
||||
<rect x="7" y="7" width="10" height="13" rx="5"/>
|
||||
<path d="M9 7a3 3 0 0 1 6 0M12 11v9M3 13h4M17 13h4M4 7l3 2M20 7l-3 2M4 19l3-2M20 19l-3-2"/>
|
||||
</svg>`;
|
||||
|
||||
export const WIKI_ICON = `
|
||||
<svg viewBox="0 0 22 22" fill="currentColor">
|
||||
<path d="M16.6,20.7c-0.6,0-0.9-0.4-0.9-0.9c0-0.5,0.3-0.9,0.9-0.9c0.3,0,0.5-0.2,0.5-0.5
|
||||
|
||||
@@ -20,6 +20,7 @@ import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON } f
|
||||
import { formatCoords, formatSunInfo } from "/js/sun.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { DebugControl } from "/js/debug.js";
|
||||
import HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
|
||||
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
|
||||
import * as maplibregl from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
@@ -568,6 +569,8 @@ sidebar.insertAdjacentHTML("beforeend", `<div class="sidebar-group-label" title=
|
||||
gnssControl.mount(sidebar);
|
||||
new LiveTrackPanelControl(map).mount(sidebar);
|
||||
|
||||
if (isLoggedIn()) new DebugControl().mount(sidebar);
|
||||
|
||||
// The sidebar already has a "Base map" icon (opens the same panel) —
|
||||
// this is a second entry point for it, grouped with Home/zoom on the map
|
||||
// itself rather than off in the page's own side rail, matching NPS's
|
||||
|
||||
Reference in new issue
Block a user