Tracks and routes as containers of points: listed (collapsed) under them in the tree, added via a point's popup, a new note or the route planner's navigation pins, and written as course points into the FIT course
This commit is contained in:
1 parent
6aa7b34f92
commit
4265421457
10 files changed
+354
-20
No files matched your search
+21
-5
@@ -130,9 +130,11 @@ export class NoteSaveForm {
|
||||
async _populateTargets() {
|
||||
const previousValue = this._target.value;
|
||||
let folders = [];
|
||||
let lines = [];
|
||||
try {
|
||||
const tree = await (await fetch("/api/library/tree")).json();
|
||||
folders = folderPaths(tree);
|
||||
lines = this._geometry?.type === "Point" ? trackNodes(tree) : [];
|
||||
} catch (err) {
|
||||
// Tree fetch failed — still usable with the top level or a new folder.
|
||||
}
|
||||
@@ -140,8 +142,11 @@ export class NoteSaveForm {
|
||||
this._target.innerHTML =
|
||||
`<option value="">Top level</option>` +
|
||||
folders.map((path) => `<option value="${escapeAttr(path)}">${escapeText(path)}</option>`).join("") +
|
||||
`<option value="${NEW_FOLDER_VALUE}">+ New folder…</option>`;
|
||||
this._target.value = folders.includes(previousValue) || previousValue === NEW_FOLDER_VALUE ? previousValue : "";
|
||||
`<option value="${NEW_FOLDER_VALUE}">+ New folder…</option>` +
|
||||
// A point can go straight into a track/route (kept and exported with it).
|
||||
(lines.length ? `<optgroup label="Into a track / route">${lines.map(([key, label]) => `<option value="${escapeAttr(key)}">${escapeText(label)}</option>`).join("")}</optgroup>` : "");
|
||||
const values = [...this._target.options].map((o) => o.value);
|
||||
this._target.value = values.includes(previousValue) ? previousValue : "";
|
||||
this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
|
||||
}
|
||||
|
||||
@@ -170,14 +175,16 @@ export class NoteSaveForm {
|
||||
geometry: this._geometry,
|
||||
};
|
||||
|
||||
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), folder });
|
||||
const intoLine = folder.startsWith("item:");
|
||||
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), ...(intoLine ? {} : { folder }) });
|
||||
|
||||
this._saveButton.disabled = true;
|
||||
try {
|
||||
const response = await fetch("/api/library/notes", { method: "POST", body: requestBody });
|
||||
const url = intoLine ? `/api/library/node/${encodeURIComponent(folder)}/points` : "/api/library/notes";
|
||||
const response = await fetch(url, { method: "POST", body: requestBody });
|
||||
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
||||
const { path } = await response.json();
|
||||
notifyGpxStoreChanged(path);
|
||||
notifyGpxStoreChanged(intoLine ? folder : path);
|
||||
this.close();
|
||||
this._onSaved?.();
|
||||
} catch (err) {
|
||||
@@ -276,6 +283,15 @@ function folderPaths(node) {
|
||||
return (node.children || []).filter((child) => child.type === "folder").flatMap((child) => [child.path, ...folderPaths(child)]);
|
||||
}
|
||||
|
||||
// Tracks/routes of the library as [key, "folder / name"].
|
||||
function trackNodes(node, folder = "") {
|
||||
return (node.children || []).flatMap((child) => {
|
||||
if (child.type === "folder") return trackNodes(child, child.path);
|
||||
const line = child.path.startsWith("item:") && !child.layer && child.kinds?.some((k) => k === "track" || k === "route");
|
||||
return line ? [[child.path, [folder, child.name].filter(Boolean).join(" / ")]] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function escapeAttr(value) {
|
||||
return value.replace(/&/g, "&").replace(/"/g, """);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user