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
@@ -142,6 +142,11 @@ html, body {
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pinned to the bottom of the rail (the sidebar is a flex column). */
|
||||||
|
.sidebar-item--bottom {
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-group-label {
|
.sidebar-group-label {
|
||||||
width: 28px;
|
width: 28px;
|
||||||
height: 1px;
|
height: 1px;
|
||||||
@@ -459,6 +464,27 @@ html, body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.debug-panel__body {
|
||||||
|
padding: 8px 12px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.debug-panel__body summary {
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: monospace;
|
||||||
|
padding: 3px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.debug-panel__body pre {
|
||||||
|
margin: 2px 0 8px;
|
||||||
|
padding: 6px;
|
||||||
|
background: #f6f6f6;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
.offline-data-panel__body {
|
.offline-data-panel__body {
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// 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
|
// (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.
|
// 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 = `
|
export const WIKI_ICON = `
|
||||||
<svg viewBox="0 0 22 22" fill="currentColor">
|
<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
|
<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 { formatCoords, formatSunInfo } from "/js/sun.js";
|
||||||
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||||
import { isLoggedIn } from "/js/auth.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 HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
|
||||||
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
|
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
|
||||||
import * as maplibregl from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
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);
|
gnssControl.mount(sidebar);
|
||||||
new LiveTrackPanelControl(map).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) —
|
// 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
|
// 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
|
// itself rather than off in the page's own side rail, matching NPS's
|
||||||
|
|||||||
@@ -94,6 +94,15 @@
|
|||||||
<ul class="livetrack-panel__list"></ul>
|
<ul class="livetrack-panel__list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="debug-panel" class="basemap-panel" hidden>
|
||||||
|
<div class="basemap-panel__header">
|
||||||
|
<strong>Status / debug</strong>
|
||||||
|
<button type="button" class="basemap-panel__close" aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<!-- Filled by DebugControl (public/js/debug.js), logged-in only. -->
|
||||||
|
<div class="debug-panel__body"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="offline-data-panel" class="basemap-panel" hidden>
|
<div id="offline-data-panel" class="basemap-panel" hidden>
|
||||||
<div class="basemap-panel__header">
|
<div class="basemap-panel__header">
|
||||||
<strong>Offline data</strong>
|
<strong>Offline data</strong>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
|
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
|
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
|
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
|
||||||
|
"/js/debug.js": "/js/debug.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
|
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
|
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
|
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
|
||||||
|
|||||||
Reference in new issue
Block a user