From 91fa9cec41d072c464c9670d428d7cfa427a6f9c Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Thu, 3 Dec 2026 09:39:19 +0100 Subject: [PATCH] =?UTF-8?q?Library=20as=20on=20the=20artboard=20(after=20L?= =?UTF-8?q?ocus=20Map),=20renamed=20from=20Tracks=20&=20Points:=20find=20o?= =?UTF-8?q?n=20top=20(text,=20kind=20chips=20with=20counts,=20shown=20on?= =?UTF-8?q?=20the=20map=20only,=20Folders=20|=20List),=20one=20folder=20le?= =?UTF-8?q?vel=20at=20a=20time=20with=20=E2=86=90=20up=20and=20the=20path?= =?UTF-8?q?=20(the=20up=20button=20takes=20a=20dragged=20item=20a=20level?= =?UTF-8?q?=20up),=20folders=20first,=20an=20eye=20per=20row=20(=E2=97=8F?= =?UTF-8?q?=20shown,=20=E2=97=90=20some=20of=20a=20folder,=20=E2=97=8B=20n?= =?UTF-8?q?one;=20a=20folder's=20eye=20shows=20or=20hides=20everything=20i?= =?UTF-8?q?n=20it),=20a=20track's=20points=20open=20from=20its=20=E2=80=BA?= =?UTF-8?q?;=20while=20searching=20or=20in=20List=20every=20match=20flat?= =?UTF-8?q?=20with=20its=20folder;=20totals=20and=20Hide=20all=20at=20the?= =?UTF-8?q?=20foot;=20uploads,=20new=20folders=20and=20drops=20on=20blank?= =?UTF-8?q?=20space=20go=20to=20the=20folder=20open.=20The=20elevation=20p?= =?UTF-8?q?rofile=20docked=20under=20the=20map:=20the=20map=20gives=20up?= =?UTF-8?q?=20its=20height;=20a=20route=20shows=20its=20own=20profile=20on?= =?UTF-8?q?ce=20the=20terrain=20is=20sampled=20(not=20while=20driving)=20a?= =?UTF-8?q?nd=20hides=20it=20when=20cleared?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/style.css | 239 +++++++++++++++++++++ public/js/gpx.js | 419 +++++++++++++++++++++++-------------- public/js/map.js | 2 +- public/js/route.js | 12 +- public/js/track_profile.js | 9 + views/index.erb | 19 +- 6 files changed, 545 insertions(+), 155 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index 104ac7c..6999efe 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -4370,3 +4370,242 @@ html.follow-3d .maplibregl-ctrl-overview-map { display: none; } padding: 0; min-height: 0; } + +/* ---- Library, as on the artboard (gpx.js): find on top, one level of + folders or a flat list, an eye per row, totals and Hide all at the foot. */ +.lib-find { + display: flex; + flex-direction: column; + gap: 10px; + padding: 12px 16px 10px; + border-bottom: 1px solid var(--ui-line); +} + +.lib-find__input { + height: 40px; + padding: 0 12px; + border: 2px solid var(--accent); + border-radius: 8px; + background: var(--ui-bg); + color: var(--ui-fg); + font-family: inherit; + font-size: 15px; +} + +.lib-find__kinds, +.lib-find__bar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; +} + +.gpx-panel .lib-chip { + min-height: 30px; + height: 30px; + padding: 0 10px; + border: 1px solid var(--ui-line); + border-radius: 15px; + background: var(--ui-bg); + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +.gpx-panel .lib-chip[aria-pressed="true"] { + border-color: var(--accent); + background: var(--accent-bg); + color: var(--accent); +} + +.lib-chip small { + opacity: 0.7; +} + +.lib-seg { + display: flex; + margin-left: auto; + border: 1px solid var(--ui-line); + border-radius: 6px; + overflow: hidden; +} + +.gpx-panel .lib-seg button { + min-height: 30px; + height: 30px; + padding: 0 12px; + border: none; + background: none; + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +.gpx-panel .lib-seg button[aria-pressed="true"] { + background: var(--accent); + color: #fff; +} + +.lib-crumb { + display: flex; + align-items: center; + gap: 8px; + padding: 8px 16px; + border-bottom: 1px solid var(--ui-line); + font-size: 14px; +} + +.lib-crumb[hidden] { + display: none; +} + +.gpx-panel .lib-crumb__up { + min-height: 32px; + width: 32px; + border: 1px solid var(--ui-line); + border-radius: 6px; + background: none; + color: var(--ui-fg); + font-size: 16px; + cursor: pointer; +} + +.lib-crumb__path { + color: var(--ui-muted); +} + +.lib-crumb b { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.lib-crumb small { + margin-left: auto; + color: var(--ui-muted); + font-size: 12px; + white-space: nowrap; +} + +.gpx-panel .gpx-tree { + padding: 0; +} + +.lib-list { + list-style: none; + margin: 0; + padding: 0; +} + +.lib-row { + display: flex; + align-items: center; + gap: 10px; + min-height: 52px; + padding: 0 8px 0 16px; + border-bottom: 1px solid var(--ui-line); +} + +.lib-row:hover { + background: var(--ui-bg-2); +} + +.lib-row.gpx-drop-hover { + background: var(--accent-bg); +} + +.lib-row__icon { + width: 26px; + flex: none; + text-align: center; + font-size: 18px; + color: var(--ui-muted); +} + +.lib-row__text { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + cursor: pointer; +} + +.lib-row__name { + font-size: 15px; + font-weight: 600; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.lib-row__name--folder { + font-weight: 700; +} + +.lib-row__meta { + font-size: 12px; + color: var(--ui-muted); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.lib-row__aside { + color: var(--ui-muted); + font-size: 16px; + cursor: pointer; +} + +.gpx-panel .lib-eye { + width: 36px; + min-height: 36px; + flex: none; + border: none; + background: none; + color: var(--accent); + font-size: 18px; + cursor: pointer; +} + +.gpx-panel .lib-eye--none { + color: var(--ui-muted); +} + +.lib-foot { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + margin-top: auto; + padding: 8px 16px; + border-top: 1px solid var(--ui-line); + font-size: 13px; + color: var(--ui-muted); +} + +.gpx-panel .lib-foot button { + min-height: 32px; + padding: 0 12px; + border: 1px solid var(--ui-line); + border-radius: 6px; + background: none; + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +/* the profile docked under the map: the map ends above it (track_profile.js) */ +#map { + margin-bottom: var(--profile-h, 0px); +} + +html.driving #map { + margin-bottom: 0; +} diff --git a/public/js/gpx.js b/public/js/gpx.js index 0f3a861..5112b64 100644 --- a/public/js/gpx.js +++ b/public/js/gpx.js @@ -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 = ``; + this._container.innerHTML = ``; 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 }]) => ``) + .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 = `
  • ${this._query ? "Nothing found" : "Nothing here yet"}
  • `; + } + 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 = ``; + 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 diff --git a/public/js/map.js b/public/js/map.js index 9e0af5c..bfc6430 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -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(); diff --git a/public/js/route.js b/public/js/route.js index fd38fbc..f3290cd 100644 --- a/public/js/route.js +++ b/public/js/route.js @@ -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. diff --git a/public/js/track_profile.js b/public/js/track_profile.js index 4566c5f..63afa88 100644 --- a/public/js/track_profile.js +++ b/public/js/track_profile.js @@ -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(); diff --git a/views/index.erb b/views/index.erb index 2b5e578..4a45a08 100644 --- a/views/index.erb +++ b/views/index.erb @@ -49,7 +49,7 @@
    >
    - Tracks & Points + Library
    @@ -60,8 +60,25 @@ + +
    + +
    +
    + + + + + +
    +
    +
    +
    + + +