diff --git a/public/css/style.css b/public/css/style.css index 052a09a..7b45868 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -142,6 +142,11 @@ html, body { position: relative; } +/* Pinned to the bottom of the rail (the sidebar is a flex column). */ +.sidebar-item--bottom { + margin-top: auto; +} + .sidebar-group-label { width: 28px; 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 { padding: 8px 12px; } diff --git a/public/js/debug.js b/public/js/debug.js new file mode 100644 index 0000000..d43f860 --- /dev/null +++ b/public/js/debug.js @@ -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 = ``; + 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 }) => ` +
+ ${url} +
${escapeHtml(text)}
+
+ `, + ) + .join(""); + } +} diff --git a/public/js/icons.js b/public/js/icons.js index 7cfd76b..fd744da 100644 --- a/public/js/icons.js +++ b/public/js/icons.js @@ -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 = ` + + + +`; + export const WIKI_ICON = ` + +