Library as on the artboard (after Locus Map), renamed from Tracks & Points: find on top (text, kind chips with counts, shown on the map only, Folders | List), one folder level at a time with ← up and the path (the up button takes a dragged item a level up), folders first, an eye per row (● shown, ◐ some of a folder, ○ none; a folder's eye shows or hides everything in it), a track's points open from its ›; while searching or in List every match flat with its folder; totals and Hide all at the foot; uploads, new folders and drops on blank space go to the folder open. The elevation profile docked under the map: the map gives up its height; a route shows its own profile once the terrain is sampled (not while driving) and hides it when cleared
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-12-03 09:39:19 +01:00
1 parent fc8564fe3b
commit 91fa9cec41
6 files changed
+545 -155

No files matched your search

+267 -152
View File
@@ -4,9 +4,6 @@ import {
GPX_ICON,
NEW_FOLDER_ICON,
UPLOAD_ICON,
WAYPOINT_ICON,
TRACK_ICON,
ROUTE_ICON,
DOWNLOAD_ICON,
SYNC_ICON,
MAP_MARKER_ICON,
@@ -38,7 +35,15 @@ const BADGE_IMAGE_PREFIX = "badge-"; // one registered image per distinct badge
// one — both land on the same drop targets, told apart by this.
const MOVE_MIME = "application/x-gpx-path";
const GPX_VISIBLE_KEY = "gpxVisible";
const FOLDER_DRAG_PREFIX = "folder:"; // a dragged folder's MOVE_MIME payload, vs. a node key
// The kinds the Library filters by: chip label, a row's word for one, glyph and colour.
const KINDS = {
waypoint: { label: "Points", one: "points", glyph: "●", color: "#12bedf" },
track: { label: "Tracks", one: "track", glyph: "〰", color: "#c2410c" },
route: { label: "Routes", one: "route", glyph: "↝", color: "#1d6fdc" },
layer: { label: "Layers", one: "layer", glyph: "▤", color: "#6b6b66" },
};
const FOLDER_DRAG_PREFIX = "folder:";
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`; // a dragged folder's MOVE_MIME payload, vs. a node key
// A sidebar icon that opens a side panel for uploading GPX files (via
// drag & drop, stored server-side in a folder hierarchy the user can add to
@@ -119,7 +124,7 @@ export class GpxPanelControl {
mount(sidebar) {
this._container = document.createElement("div");
this._container.className = "sidebar-item";
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Tracks &amp; Points" aria-label="Tracks &amp; Points">${GPX_ICON}</button>`;
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Library" aria-label="Library">${GPX_ICON}</button>`;
this._icon = this._container.querySelector(".sidebar-icon");
this._icon.addEventListener("click", () => this._togglePanel());
@@ -162,6 +167,7 @@ export class GpxPanelControl {
// panels.
document.addEventListener("click", () => this._closeDownloadMenu());
this._setupFind();
this._setupToolbarActions();
this._setupRootDropTarget();
this._setupMapDropTarget();
@@ -184,13 +190,13 @@ export class GpxPanelControl {
_setupToolbarActions() {
const fileInput = this._panel.querySelector(".gpx-file-input");
fileInput.addEventListener("change", () => {
this._uploadFiles(fileInput.files, "");
this._uploadFiles(fileInput.files, this._cwd);
fileInput.value = "";
});
this._panel.querySelector('[data-action="upload"]').addEventListener("click", () => fileInput.click());
this._panel.querySelector('[data-action="new-folder"]').addEventListener("click", async () => {
const path = window.prompt("New folder name (e.g. Hiking/2026):");
const path = window.prompt("New folder name (e.g. Hiking/2026):", this._cwd ? `${this._cwd}/` : "");
if (!path || !path.trim()) return;
const response = await fetch(FOLDER_URL, {
@@ -223,11 +229,11 @@ export class GpxPanelControl {
event.preventDefault();
this._treeContainer.classList.remove("gpx-drop-hover");
if (event.dataTransfer.files?.length > 0) {
this._uploadFiles(event.dataTransfer.files, "");
this._uploadFiles(event.dataTransfer.files, this._cwd);
return;
}
const from = event.dataTransfer.getData(MOVE_MIME);
if (from) this._moveFile(from, "");
if (from) this._moveFile(from, this._cwd);
});
}
@@ -258,67 +264,266 @@ export class GpxPanelControl {
this._renderTree(tree);
}
// The Design canvas' Library (after Locus Map): find on top — the text,
// what kinds, only the shown ones — then one folder level at a time (← up,
// the path), or, while searching or in List view, every match flat with
// the folder it lives in. An eye per row: ● shown, ◐ some (a folder), ○ not.
_renderTree(node) {
this._root = node;
this._files = new Map();
const index = (n) => (n.children || []).forEach((c) => (c.type === "folder" ? index(c) : this._files.set(c.path, c)));
index(node);
this._treeContainer.innerHTML = "";
this._treeContainer.appendChild(this._renderChildren(node.children));
}
_renderChildren(children) {
const ul = document.createElement("ul");
if (children.length === 0) {
const li = document.createElement("li");
li.className = "gpx-tree__empty";
li.textContent = "No files yet";
ul.appendChild(li);
return ul;
}
children.forEach((child) => {
const li = document.createElement("li");
if (child.type === "folder") {
li.appendChild(this._renderFolder(child));
} else if (child.points) {
li.appendChild(this._renderTrackWithPoints(child));
this._folders = new Map([["", node]]);
const index = (n) => (n.children || []).forEach((c) => {
if (c.type === "folder") {
this._folders.set(c.path, c);
index(c);
} else {
li.appendChild(this._renderFile(child));
c.folder = n.path;
this._files.set(c.path, c);
}
ul.appendChild(li);
});
return ul;
index(node);
if (!this._folders.has(this._cwd ?? "")) this._cwd = "";
if (this._openTrack && !this._files.has(this._openTrack)) this._openTrack = null;
this._renderView();
}
// A track/route holding points: collapsed by default (there can be many),
// each point zooms to itself and can be taken out again.
_renderTrackWithPoints(file) {
this._openTracks ||= new Set();
const details = document.createElement("details");
details.className = "gpx-tree__track";
details.open = this._openTracks.has(file.path);
details.addEventListener("toggle", () => (details.open ? this._openTracks.add(file.path) : this._openTracks.delete(file.path)));
const summary = document.createElement("summary");
summary.appendChild(this._renderFile(file));
details.appendChild(summary);
_setupFind() {
this._cwd = "";
this._query = "";
this._mode = "folders";
this._kindsOn = new Set(Object.keys(KINDS));
this._shownOnly = false;
const find = this._panel.querySelector(".lib-find");
const input = find.querySelector(".lib-find__input");
input.addEventListener("input", () => {
this._query = input.value.trim().toLowerCase();
this._renderView();
});
find.querySelector(".lib-find__kinds").addEventListener("click", (event) => {
const chip = event.target.closest("[data-kind]");
if (!chip) return;
const kind = chip.dataset.kind;
if (this._kindsOn.has(kind) && this._kindsOn.size > 1) this._kindsOn.delete(kind);
else this._kindsOn.add(kind);
this._renderView();
});
find.querySelector('[data-find="shown"]').addEventListener("click", () => {
this._shownOnly = !this._shownOnly;
this._renderView();
});
find.querySelectorAll("[data-mode]").forEach((button) => button.addEventListener("click", () => {
this._mode = button.dataset.mode;
this._renderView();
}));
this._crumb = this._panel.querySelector(".lib-crumb");
this._footer = this._panel.querySelector(".lib-foot__text");
this._panel.querySelector('[data-action="hide-all"]').addEventListener("click", () => {
[...this._visible].forEach((path) => this._toggleFileOnly(path, false));
this._saveVisible();
this._renderView();
});
}
_kindOf(file) {
if (file.layer) return "layer";
if (file.kinds?.includes("route")) return "route";
if (file.kinds?.includes("track")) return "track";
return "waypoint";
}
_matches(file) {
if (!this._kindsOn.has(this._kindOf(file))) return false;
if (this._shownOnly && !this._visible.has(file.path)) return false;
return !this._query || `${file.folder} ${file.name}`.toLowerCase().includes(this._query);
}
// Every file under a folder (all levels).
_filesUnder(path) {
return [...this._files.values()].filter((f) => f.folder === path || f.folder.startsWith(`${path}/`) || path === "");
}
_renderView() {
if (!this._root) return;
const find = this._panel.querySelector(".lib-find");
const counts = {};
this._files.forEach((f) => (counts[this._kindOf(f)] = (counts[this._kindOf(f)] || 0) + 1));
find.querySelector(".lib-find__kinds").innerHTML = Object.entries(KINDS)
.map(([kind, { label, color }]) => `<button type="button" class="lib-chip" data-kind="${kind}" aria-pressed="${this._kindsOn.has(kind)}"><span style="color: ${color}">●</span> ${label} <small>${counts[kind] || 0}</small></button>`)
.join("");
find.querySelector('[data-find="shown"]').setAttribute("aria-pressed", this._shownOnly);
const flat = this._mode === "list" || this._query;
find.querySelectorAll("[data-mode]").forEach((button) => button.setAttribute("aria-pressed", (button.dataset.mode === "list") === Boolean(flat)));
const ul = document.createElement("ul");
ul.className = "gpx-tree__points";
file.points.forEach((point) => {
const li = document.createElement("li");
li.className = "gpx-tree__point";
const name = document.createElement("button");
name.type = "button";
name.className = "gpx-tree__point-name";
name.textContent = point.name;
name.addEventListener("click", () => this._goToPoint(file.path, point));
li.appendChild(name);
if (isLoggedIn()) li.appendChild(this._deleteButton(() => this._removePoint(file, point)));
ul.appendChild(li);
ul.className = "lib-list";
if (flat) {
this._crumb.hidden = true;
if (this._query) {
[...this._folders.values()]
.filter((f) => f.path && f.name.toLowerCase().includes(this._query))
.forEach((f) => ul.appendChild(this._folderRow(f, true)));
}
[...this._files.values()].filter((f) => this._matches(f)).forEach((f) => ul.appendChild(this._fileRow(f, true)));
} else if (this._openTrack) {
const track = this._files.get(this._openTrack);
this._renderCrumb(track.folder, track.name, plural(track.points.length, "point"), () => (this._openTrack = null));
track.points.forEach((point) => ul.appendChild(this._pointRow(track, point)));
} else {
const folder = this._folders.get(this._cwd);
const subfolders = folder.children.filter((c) => c.type === "folder");
const files = folder.children.filter((c) => c.type !== "folder" && this._matches(c));
if (this._cwd) {
const parent = this._cwd.includes("/") ? this._cwd.slice(0, this._cwd.lastIndexOf("/")) : "";
this._renderCrumb(parent, folder.name, `${plural(subfolders.length, "folder")} · ${plural(files.length, "item")}`, () => (this._cwd = parent), parent);
} else {
this._crumb.hidden = true;
}
subfolders.forEach((f) => ul.appendChild(this._folderRow(f)));
files.forEach((f) => ul.appendChild(this._fileRow(f)));
}
if (!ul.children.length) {
ul.innerHTML = `<li class="gpx-tree__empty">${this._query ? "Nothing found" : "Nothing here yet"}</li>`;
}
this._treeContainer.innerHTML = "";
this._treeContainer.appendChild(ul);
this._footer.textContent = `${plural(this._folders.size - 1, "folder")} · ${plural(this._files.size, "item")} · ${this._visible.size} shown`;
}
// ← up, the path to here and its name; `dropTo` (the parent) also takes a
// dragged item, to move it a level up.
_renderCrumb(path, name, meta, up, dropTo) {
this._crumb.hidden = false;
this._crumb.innerHTML = "";
const back = Object.assign(document.createElement("button"), { type: "button", className: "lib-crumb__up", textContent: "←", title: "Up" });
back.addEventListener("click", () => {
up();
this._renderView();
});
details.appendChild(ul);
return details;
if (dropTo !== undefined && isLoggedIn()) this._wireFolderDropTarget(back, dropTo);
const where = Object.assign(document.createElement("span"), { className: "lib-crumb__path", textContent: path ? `${path.replaceAll("/", " › ")} › ` : "" });
this._crumb.append(back, where, Object.assign(document.createElement("b"), { textContent: name }), Object.assign(document.createElement("small"), { textContent: meta }));
}
_row({ icon, color, name, meta, aside, eye, onOpen, onEye, bold }) {
const li = document.createElement("li");
li.className = "lib-row";
li.innerHTML = `<span class="lib-row__icon" aria-hidden="true"></span><span class="lib-row__text"><span class="lib-row__name"></span><small class="lib-row__meta"></small></span><span class="lib-row__aside"></span>`;
const iconEl = li.querySelector(".lib-row__icon");
iconEl.textContent = icon;
iconEl.style.color = color || "";
li.querySelector(".lib-row__name").textContent = name;
li.querySelector(".lib-row__name").classList.toggle("lib-row__name--folder", Boolean(bold));
li.querySelector(".lib-row__meta").textContent = meta || "";
li.querySelector(".lib-row__aside").textContent = aside || "";
li.querySelector(".lib-row__text").addEventListener("click", onOpen);
if (eye) {
const button = Object.assign(document.createElement("button"), { type: "button", className: `lib-eye lib-eye--${eye}`, textContent: { all: "●", some: "◐", none: "○" }[eye] });
button.title = eye === "none" ? "Show on the map" : "Hide from the map";
button.setAttribute("aria-label", button.title);
button.setAttribute("aria-pressed", eye !== "none");
button.addEventListener("click", onEye);
li.appendChild(button);
}
return li;
}
_folderRow(folder, withPath = false) {
const files = this._filesUnder(folder.path);
const shown = files.filter((f) => this._visible.has(f.path)).length;
const subfolders = folder.children.filter((c) => c.type === "folder").length;
const items = folder.children.length - subfolders;
const parent = folder.path.includes("/") ? folder.path.slice(0, folder.path.lastIndexOf("/")).replaceAll("/", " › ") : "";
const li = this._row({
icon: "▣",
name: folder.name,
bold: true,
meta: [withPath && parent, subfolders && plural(subfolders, "folder"), plural(items, "item")].filter(Boolean).join(" · "),
aside: "›",
eye: files.length ? (shown === 0 ? "none" : shown === files.length ? "all" : "some") : null,
onOpen: () => {
this._cwd = folder.path;
this._openTrack = null;
this._query = "";
this._mode = "folders";
this._panel.querySelector(".lib-find__input").value = "";
this._renderView();
},
onEye: async () => {
const show = shown === 0;
await Promise.all(files.map((f) => this._toggleFileOnly(f.path, show)));
this._saveVisible();
this._renderView();
},
});
if (isLoggedIn()) {
li.appendChild(this._menuButton("⋯", "Actions", [
{ label: "Rename…", run: () => this._renameFolder(folder) },
...this._exportEntries(folder.path, folder.name),
{ label: "Delete…", run: () => this._deleteFolder(folder.path) },
]));
li.draggable = true;
li.addEventListener("dragstart", (event) => {
event.dataTransfer.setData(MOVE_MIME, `${FOLDER_DRAG_PREFIX}${folder.path}`);
event.dataTransfer.effectAllowed = "move";
});
this._wireFolderDropTarget(li, folder.path);
}
return li;
}
_fileRow(file, withPath = false) {
const kind = this._kindOf(file);
const visible = this._visible.has(file.path);
const li = this._row({
icon: KINDS[kind].glyph,
color: file.color || KINDS[kind].color,
name: file.name,
meta: [withPath && (file.folder ? file.folder.replaceAll("/", " › ") : "Top level"), KINDS[kind].one, file.points && plural(file.points.length, "point")].filter(Boolean).join(" · "),
aside: file.points ? "›" : "",
eye: visible ? "all" : "none",
// the name zooms to it, shown first if needed; a track's points open
// from its ›
onOpen: async (event) => {
if (file.points && event.target.closest(".lib-row__aside, .lib-row__meta")) {
this._openTrack = file.path;
return this._renderView();
}
if (!this._visible.has(file.path)) await this._toggleFile(file.path, true);
if (this._visible.has(file.path)) this._zoomTo(file.path);
this._renderView();
},
onEye: async () => {
await this._toggleFile(file.path, !visible);
this._renderView();
},
});
if (file.points) {
li.querySelector(".lib-row__aside").addEventListener("click", () => {
this._openTrack = file.path;
this._renderView();
});
}
li.draggable = true;
li.addEventListener("dragstart", (event) => {
event.dataTransfer.setData(MOVE_MIME, file.path);
event.dataTransfer.effectAllowed = "move";
});
// Every action behind one ⋯ menu (as OsmAnd does), shown only once
// logged in: they all require login (app.rb).
if (isLoggedIn()) li.appendChild(this._fileMenu(file));
return li;
}
_pointRow(track, point) {
const li = this._row({
icon: "●",
color: KINDS.waypoint.color,
name: point.name,
meta: "point",
onOpen: () => this._goToPoint(track.path, point),
});
if (isLoggedIn()) li.appendChild(this._deleteButton(() => this._removePoint(track, point)));
return li;
}
async _goToPoint(path, point) {
@@ -347,95 +552,6 @@ export class GpxPanelControl {
await this._reloadFile(target);
}
_renderFolder(folder) {
const details = document.createElement("details");
details.open = true;
const summary = document.createElement("summary");
const row = document.createElement("span");
row.className = "gpx-tree__folder-row";
const name = document.createElement("span");
name.textContent = folder.name;
row.appendChild(name);
if (isLoggedIn()) {
row.appendChild(
this._menuButton("⋯", "Actions", [
{ label: "Rename…", run: () => this._renameFolder(folder) },
...this._exportEntries(folder.path, folder.name),
{ label: "Delete…", run: () => this._deleteFolder(folder.path) },
]),
);
// Dragged onto another folder (or the tree's blank space) moves it.
summary.draggable = true;
summary.addEventListener("dragstart", (event) => {
event.dataTransfer.setData(MOVE_MIME, `${FOLDER_DRAG_PREFIX}${folder.path}`);
event.dataTransfer.effectAllowed = "move";
});
}
summary.appendChild(row);
this._wireFolderDropTarget(summary, folder.path);
details.appendChild(summary);
details.appendChild(this._renderChildren(folder.children));
return details;
}
_renderFile(file) {
const row = document.createElement("div");
row.className = "gpx-tree__file";
row.draggable = true;
row.addEventListener("dragstart", (event) => {
event.dataTransfer.setData(MOVE_MIME, file.path);
event.dataTransfer.effectAllowed = "move";
});
const label = document.createElement("label");
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = this._visible.has(file.path);
checkbox.dataset.path = file.path;
checkbox.addEventListener("change", () => this._toggleFile(file.path, checkbox.checked, checkbox));
const loggedIn = isLoggedIn();
const name = document.createElement("span");
name.className = "gpx-tree__file-name";
name.textContent = file.name;
label.appendChild(checkbox);
(file.kinds || []).forEach((kind) => label.appendChild(this._kindIcon(kind)));
label.appendChild(name);
// The name zooms to it (showing it first if needed); the checkbox
// alone shows/hides.
name.addEventListener("click", async (event) => {
event.preventDefault();
if (!checkbox.checked) {
checkbox.checked = true;
await this._toggleFile(file.path, true, checkbox);
}
if (checkbox.checked) this._zoomTo(file.path);
});
row.appendChild(label);
// Every action behind one ⋯ menu (as OsmAnd does), shown only once
// logged in: they all require login (app.rb).
if (loggedIn) row.appendChild(this._fileMenu(file));
return row;
}
_kindIcon(kind) {
const icon = document.createElement("span");
icon.className = "gpx-tree__kind-icon";
if (kind === "waypoint") {
icon.innerHTML = WAYPOINT_ICON;
icon.title = "Has waypoints";
} else if (kind === "route") {
icon.innerHTML = ROUTE_ICON;
icon.title = "Has a route";
} else {
icon.innerHTML = TRACK_ICON;
icon.title = "Has a track";
}
return icon;
}
_fileMenu(file) {
const geojsonUrl = `${gpxFileUrl(file.path)}?${new URLSearchParams({ download: "geojson", name: file.name })}`;
// A folder's "Points (N)" node has no name or color of its own.
@@ -585,9 +701,8 @@ export class GpxPanelControl {
// that isn't shown yet — same as ticking its box in the tree by hand.
async show(path) {
if (this._visible.has(path)) return;
const checkbox = [...this._treeContainer.querySelectorAll("input[data-path]")].find((input) => input.dataset.path === path);
if (checkbox) checkbox.checked = true;
await this._toggleFile(path, true, checkbox);
await this._toggleFile(path, true);
this._renderView();
}
// Search result picked: show its file, then open the matching point's
+1 -1
View File
@@ -515,7 +515,7 @@ new LiveTrackPanelControl(map).mount(sidebar);
if (isLoggedIn()) new DebugControl().mount(sidebar);
if (isLoggedIn()) setupUpdate(document.querySelector(".topbar__update"), document.querySelector(".debug-panel__update-check"));
// A short name under each icon (CSS ::after), the title stays the tooltip.
const RAIL_LABELS = { "Tracks & Points": "Library", "Import plugins": "Import", "Offline data": "Offline", LiveTrack: "Live", "Status / debug": "Status" };
const RAIL_LABELS = { "Import plugins": "Import", "Offline data": "Offline", LiveTrack: "Live", "Status / debug": "Status" };
sidebar.querySelectorAll(".sidebar-icon").forEach((icon) => (icon.dataset.label = RAIL_LABELS[icon.title] ?? icon.title));
setupSidePanelModes();
+11 -1
View File
@@ -111,7 +111,10 @@ export class RoutePanelControl {
this._editingNote = this._panel.querySelector(".route-panel__editing");
this._saveButton.addEventListener("click", () => this._save());
this._profileButton = this._panel.querySelector(".route-panel__profile");
this._profileButton.addEventListener("click", () => this._profilePanel.show(this._profileProperties()));
this._profileButton.addEventListener("click", () => {
this._profileShown = this._profileProperties();
this._profilePanel.show(this._profileShown);
});
this._reachStatus = this._panel.querySelector(".route-panel__reach-status");
this._reachClear = this._panel.querySelector('[data-action="reach-clear"]');
this._panel.querySelector('[data-action="reach"]').addEventListener("click", () => this._showReach());
@@ -507,6 +510,8 @@ export class RoutePanelControl {
this._showCountries(route?.properties.countries);
this._renderTotals(route);
this._summary.textContent = message;
if (this._profileShown && this._profilePanel.shown === this._profileShown) this._profilePanel.hide();
this._profileShown = null;
if (!route) return;
const { maneuvers } = route.properties;
@@ -530,6 +535,11 @@ export class RoutePanelControl {
route.elevation = profile;
this._renderTotals(route);
this._profileButton.hidden = false;
// the route's profile docked under the map while planning (not driving)
if (!document.documentElement.classList.contains("driving")) {
this._profileShown = this._profileProperties();
this._profilePanel.show(this._profileShown);
}
}
// What TrackProfilePanel (and a library track) reads.
+9
View File
@@ -45,11 +45,18 @@ export class TrackProfilePanel {
this._stats = this._panel.querySelector(".profile-panel__stats");
this._chartsContainer = this._panel.querySelector(".profile-panel__charts");
this._panel.querySelector(".profile-panel__close").addEventListener("click", () => this.hide());
// Docked under the map (the Design canvas' Desktop): the map gives up
// the profile's height instead of being covered by it.
new ResizeObserver(() => {
const height = this._panel.hidden ? 0 : this._panel.offsetHeight;
document.documentElement.style.setProperty("--profile-h", `${height}px`);
}).observe(this._panel);
}
show(properties) {
const profile = properties.profile;
if (!profile || profile.length === 0) return;
this.shown = properties; // whose profile this is (route.js hides its own)
this._profile = profile.map((point) => ({ ...point, speed_kmh: typeof point.speed_mps === "number" ? point.speed_mps * 3.6 : null }));
addMovingTime(this._profile);
@@ -204,7 +211,9 @@ export class TrackProfilePanel {
}
hide() {
this.shown = null;
this._panel.hidden = true;
document.documentElement.style.setProperty("--profile-h", "0px");
this._plots?.removeEventListener("pointermove", this._onPointerMove);
this._plots?.removeEventListener("pointerleave", this._onPointerLeave);
this._marker.remove();