feat(collections): own order, KML/KMZ import, copy options, position search, place names on the trip map

- A list keeps its own order: drag a place by its grip (desktop and phone) or
  move it with the arrow keys. Reordering is off while a search or filter hides
  places and the list says why. New PUT /collections/:id/places/reorder and the
  MCP tool reorder_collection_places; new places go to the end. Client and
  server now order ties the same way (sort_order, oldest first, id).
- Copying saved places into a trip no longer takes their notes and tags along
  unasked. The picker offers both; a tag taken along becomes a trip tag (a trip
  tag of the same name is reused), never someone's personal tag.
- The source trip and place a saved place names are only kept when the user can
  open that trip and the place belongs to it.
- A KML or KMZ map can be read into a list: the dialog lists every placemark to
  keep or leave out and says which entries were skipped and why
  (POST /collections/map/read writes nothing; the import does).
- A saved place without coordinates says so and can be looked up on the map
  from its edit form, on the phone too, where a missing position could not be
  added at all. A typed address without a pick says it will not be on the map.
- The trip map can show the place names beside the pins (desktop and phone,
  both renderers). Names that would cover another pin or a control give way,
  the selected place and the planned stops first.
This commit is contained in:
Maurice
2026-11-29 14:57:00 +01:00
parent 177a0febe2
commit 82165855c7
148 changed files with 4219 additions and 321 deletions
@@ -81,9 +81,8 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
* per the plan's own "do not collapse" instruction for that pair).
* `saveFromTripPlaces`'s own call site passes `status: 'idea', links:
* null` explicitly, reproducing the literal exactly. `em.insert()`
* returns the generated id; `sort_order` is never in the column list
* either statement writes, so the table's own `DEFAULT 0` fills it,
* matching both legacy statements.
* returns the generated id. `sort_order` is the caller's: a new place goes
* after the last one of its list (PLC-03), read in the same transaction.
*/
async insertSavedPlace(row: {
collection_id: number;
@@ -108,6 +107,7 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
source_trip_id: number | null;
source_place_id: number | null;
links: string | null;
sort_order: number;
}): Promise<number> {
return await this.insert({
collection: row.collection_id,
@@ -132,9 +132,35 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
source_trip_id: row.source_trip_id,
source_place_id: row.source_place_id,
links: row.links,
sort_order: row.sort_order,
});
}
/** A list's place ids in the list's order: `sort_order`, then `created_at`, then `id`, as listPlaceRows reads them. */
async idsInOrder(collectionId: number): Promise<number[]> {
const rows = await this.db_()
.selectFrom('collection_places')
.select('id')
.where('collection_id', '=', collectionId)
.orderBy((eb) => eb.fn.coalesce('sort_order', eb.val(0)))
.orderBy((eb) => eb.fn.coalesce('created_at', eb.val('')))
.orderBy('id')
.execute();
return rows.map((r) => r.id);
}
/** `UPDATE collection_places SET sort_order=? WHERE id=? AND collection_id=?`, per place, inside the caller's transaction. */
async setSortOrders(collectionId: number, orderedIds: number[]): Promise<void> {
for (const [position, id] of orderedIds.entries()) {
await this.db_()
.updateTable('collection_places')
.set({ sort_order: position })
.where('id', '=', id)
.where('collection_id', '=', collectionId)
.execute();
}
}
// ---------------------------------------------------------------------
// CL47/CL48 — updatePlace
// ---------------------------------------------------------------------
@@ -180,6 +206,7 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
currency: string | null;
collection_id: number;
owner_id: number;
sort_order: number;
}>,
): Promise<void> {
if (Object.keys(write).length === 0) return;
@@ -350,20 +377,6 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
.executeTakeFirst();
}
// ---------------------------------------------------------------------
// CL67 — copyToTrip's per-source tag read (loop, TX)
// ---------------------------------------------------------------------
/** CL67 (`copyToTrip`, loop, TX) — `SELECT tag_id FROM collection_place_tags WHERE collection_place_id=?`. Pivot table, Kysely. */
async tagIdsFor(collectionPlaceId: number): Promise<number[]> {
const rows = await this.db_()
.selectFrom('collection_place_tags')
.select('tag_id')
.where('collection_place_id', '=', collectionPlaceId)
.execute();
return rows.map((r) => r.tag_id);
}
// ---------------------------------------------------------------------
// CL69 — findMembership (library-wide membership lookup)
// ---------------------------------------------------------------------