mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
Give GPX tracks their own colour (#776)
Imported tracks all render in the same blue: the GPX/KML importers never assign a category, so category_color is null for every one of them and several walks in the same area are impossible to tell apart. Adds a nullable route_color on places, kept out of the COALESCE group in updatePlace so an explicit null can reset a track back to inheriting its category colour. The hex is validated in the Nest controller rather than in the shared contract: the update body is an open record on purpose, and tightening it would mean removing PlacesController.update from the ratchet-only body-contract allow-list. The importers now hand each new track a colour of its own, picked from the palette entries the trip is not already using. That happens in the Nest service over the injected DatabaseService — the colour assignment is new logic, and new logic does not belong in the legacy place service (see server/src/nest/README.md). The field itself is only threaded through the existing update/create statements, which the proportionality rule covers. Also fixes duplicateTrip, whose explicit column list has been silently dropping route_geometry all along, so a duplicated trip lost its tracks.
This commit is contained in:
@@ -125,26 +125,28 @@ export function createPlace(
|
||||
place_time?: string; end_time?: string;
|
||||
duration_minutes?: number; notes?: string; image_url?: string;
|
||||
google_place_id?: string; google_ftid?: string; osm_id?: string; website?: string; phone?: string;
|
||||
transport_mode?: string; tags?: number[];
|
||||
transport_mode?: string; route_geometry?: string; route_color?: string; tags?: number[];
|
||||
},
|
||||
) {
|
||||
const {
|
||||
name, description, lat, lng, address, category_id, price, currency,
|
||||
place_time, end_time,
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, osm_id, website, phone,
|
||||
transport_mode, tags = [],
|
||||
transport_mode, route_geometry, route_color, tags = [],
|
||||
} = body;
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO places (trip_id, name, description, lat, lng, address, category_id, price, currency,
|
||||
place_time, end_time,
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, osm_id, website, phone, transport_mode)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, osm_id, website, phone, transport_mode,
|
||||
route_geometry, route_color)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
tripId, name, description || null, lat || null, lng || null, address || null,
|
||||
category_id || null, price || null, currency || null,
|
||||
place_time || null, end_time || null, duration_minutes || 60, notes || null, image_url || null,
|
||||
google_place_id || null, google_ftid || null, osm_id || null, website || null, phone || null, transport_mode || 'walking',
|
||||
route_geometry || null, route_color || null,
|
||||
);
|
||||
|
||||
const placeId = result.lastInsertRowid;
|
||||
@@ -182,7 +184,7 @@ export function updatePlace(
|
||||
place_time?: string; end_time?: string;
|
||||
duration_minutes?: number; notes?: string; image_url?: string;
|
||||
google_place_id?: string; google_ftid?: string; osm_id?: string; website?: string; phone?: string;
|
||||
transport_mode?: string; tags?: number[];
|
||||
transport_mode?: string; route_color?: string | null; tags?: number[];
|
||||
},
|
||||
ifMatch?: string,
|
||||
): ReturnType<typeof getPlaceWithTags> | UpdateConflict | null {
|
||||
@@ -200,7 +202,7 @@ export function updatePlace(
|
||||
name, description, lat, lng, address, category_id, price, currency,
|
||||
place_time, end_time,
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, osm_id, website, phone,
|
||||
transport_mode, tags,
|
||||
transport_mode, route_color, tags,
|
||||
} = body;
|
||||
|
||||
db.prepare(`
|
||||
@@ -224,6 +226,7 @@ export function updatePlace(
|
||||
website = ?,
|
||||
phone = ?,
|
||||
transport_mode = COALESCE(?, transport_mode),
|
||||
route_color = ?,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
`).run(
|
||||
@@ -246,6 +249,9 @@ export function updatePlace(
|
||||
website !== undefined ? website : existingPlace.website,
|
||||
phone !== undefined ? phone : existingPlace.phone,
|
||||
transport_mode || null,
|
||||
// Deliberately not COALESCE: an explicit null is how the picker resets a
|
||||
// track back to its category colour (#776).
|
||||
route_color !== undefined ? route_color : existingPlace.route_color,
|
||||
placeId,
|
||||
);
|
||||
|
||||
|
||||
@@ -917,14 +917,15 @@ export function copyTripById(sourceTripId: string | number, newOwnerId: number,
|
||||
const insertPlace = db.prepare(`
|
||||
INSERT INTO places (trip_id, name, description, lat, lng, address, category_id, price, currency,
|
||||
reservation_status, reservation_notes, reservation_datetime, place_time, end_time,
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, website, phone, transport_mode, osm_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
duration_minutes, notes, image_url, google_place_id, google_ftid, website, phone, transport_mode, osm_id,
|
||||
route_geometry, route_color)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
for (const p of oldPlaces) {
|
||||
const r = insertPlace.run(newTripId, p.name, p.description, p.lat, p.lng, p.address, p.category_id,
|
||||
p.price, p.currency, p.reservation_status, p.reservation_notes, p.reservation_datetime,
|
||||
p.place_time, p.end_time, p.duration_minutes, p.notes, p.image_url, p.google_place_id,
|
||||
p.google_ftid, p.website, p.phone, p.transport_mode, p.osm_id);
|
||||
p.google_ftid, p.website, p.phone, p.transport_mode, p.osm_id, p.route_geometry, p.route_color);
|
||||
placeMap.set(p.id, r.lastInsertRowid);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user