Library phase 1: SQLite item library with folders, migration of old files as layers, import split into items
This commit is contained in:
1 parent
4216211a20
commit
ad8b72c3d3
16 files changed
+897
-499
No files matched your search
+20
-26
@@ -28,7 +28,7 @@ const ICON_LABELS = {
|
||||
shop_convenience: "Convenience store",
|
||||
};
|
||||
|
||||
const NEW_LAYER_VALUE = "__new__";
|
||||
const NEW_FOLDER_VALUE = "__new__";
|
||||
|
||||
// Every hand-drawn note (from here or measure.js's "Save as note") gets one
|
||||
// of these — the only stable way to find a specific feature again for
|
||||
@@ -68,7 +68,7 @@ export class NoteSaveForm {
|
||||
</div>
|
||||
<textarea class="notes-panel__body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links"></textarea>
|
||||
<select class="notes-panel__target"></select>
|
||||
<input type="text" class="notes-panel__new-name" placeholder="Layer name" hidden>
|
||||
<input type="text" class="notes-panel__new-name" placeholder="Folder name" hidden>
|
||||
<div class="notes-panel__actions">
|
||||
<button type="button" class="notes-panel__save">Save</button>
|
||||
<button type="button" class="notes-panel__cancel">Cancel</button>
|
||||
@@ -92,7 +92,7 @@ export class NoteSaveForm {
|
||||
});
|
||||
});
|
||||
this._target.addEventListener("change", () => {
|
||||
this._newName.hidden = this._target.value !== NEW_LAYER_VALUE;
|
||||
this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
|
||||
if (!this._newName.hidden) this._newName.focus();
|
||||
});
|
||||
this._saveButton.addEventListener("click", () => this._save());
|
||||
@@ -129,20 +129,20 @@ export class NoteSaveForm {
|
||||
|
||||
async _populateTargets() {
|
||||
const previousValue = this._target.value;
|
||||
let files = [];
|
||||
let folders = [];
|
||||
try {
|
||||
const tree = await (await fetch("/api/gpx/tree")).json();
|
||||
files = geojsonFiles(tree);
|
||||
const tree = await (await fetch("/api/library/tree")).json();
|
||||
folders = folderPaths(tree);
|
||||
} catch (err) {
|
||||
// Tree fetch failed — target select just falls back to "new layer"
|
||||
// only, still usable.
|
||||
// Tree fetch failed — still usable with the top level or a new folder.
|
||||
}
|
||||
|
||||
this._target.innerHTML =
|
||||
files.map((file) => `<option value="${escapeAttr(file.path)}">${escapeText(file.path)}</option>`).join("") +
|
||||
`<option value="${NEW_LAYER_VALUE}">+ New layer…</option>`;
|
||||
this._target.value = files.some((file) => file.path === previousValue) ? previousValue : NEW_LAYER_VALUE;
|
||||
this._newName.hidden = this._target.value !== NEW_LAYER_VALUE;
|
||||
`<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 : "";
|
||||
this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
|
||||
}
|
||||
|
||||
async _save() {
|
||||
@@ -150,9 +150,9 @@ export class NoteSaveForm {
|
||||
const details = this._body.value.trim();
|
||||
if (!title || !this._geometry) return;
|
||||
|
||||
const isNewLayer = this._target.value === NEW_LAYER_VALUE;
|
||||
const name = isNewLayer ? this._newName.value.trim() : "";
|
||||
if (isNewLayer && !name) {
|
||||
const isNewFolder = this._target.value === NEW_FOLDER_VALUE;
|
||||
const folder = isNewFolder ? this._newName.value.trim() : this._target.value;
|
||||
if (isNewFolder && !folder) {
|
||||
this._newName.focus();
|
||||
return;
|
||||
}
|
||||
@@ -170,13 +170,11 @@ export class NoteSaveForm {
|
||||
geometry: this._geometry,
|
||||
};
|
||||
|
||||
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature) });
|
||||
if (isNewLayer) requestBody.set("name", name);
|
||||
else requestBody.set("path", this._target.value);
|
||||
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), folder });
|
||||
|
||||
this._saveButton.disabled = true;
|
||||
try {
|
||||
const response = await fetch("/api/gpx/notes", { method: "POST", body: requestBody });
|
||||
const response = await fetch("/api/library/notes", { method: "POST", body: requestBody });
|
||||
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
||||
const { path } = await response.json();
|
||||
notifyGpxStoreChanged(path);
|
||||
@@ -191,7 +189,7 @@ export class NoteSaveForm {
|
||||
}
|
||||
|
||||
// A quick "pin it with a note" tool — click the map, write a short note,
|
||||
// pick which .geojson "layer" file it joins (or start a new one). Point
|
||||
// pick which folder it goes into (or start a new one). Point
|
||||
// only: for a distance/area shape, draw it with the Measure tool and use
|
||||
// its own "Save as note" button instead of duplicating that click-to-place
|
||||
// UX here — see measure.js.
|
||||
@@ -274,12 +272,8 @@ export class NotesControl {
|
||||
}
|
||||
}
|
||||
|
||||
function geojsonFiles(node, results = []) {
|
||||
if (node.type === "file" && node.path.toLowerCase().endsWith(".geojson")) {
|
||||
results.push({ path: node.path });
|
||||
}
|
||||
(node.children || []).forEach((child) => geojsonFiles(child, results));
|
||||
return results;
|
||||
function folderPaths(node) {
|
||||
return (node.children || []).filter((child) => child.type === "folder").flatMap((child) => [child.path, ...folderPaths(child)]);
|
||||
}
|
||||
|
||||
function escapeAttr(value) {
|
||||
|
||||
Reference in new issue
Block a user