feat(dayplan): choose the travel mode per segment (#1281) (#1651)

* feat(dayplan): persist per-leg and per-day travel mode (#1281)

The day-plan route used one transport mode for the whole day, held only in
ephemeral state. Store it instead: leg_transport_mode on an assignment is
the mode of the leg leaving that stop (null = inherit the day default), and
days gains a default_transport_mode. Both nullable, so existing itineraries
are unchanged.

Adds PUT /assignments/:id/transport and PUT /days/:id/transport — their own
endpoints so setting the day default can't wipe notes/title the way the
general day update would — mirroring the assignment_time path.

* feat(dayplan): choose the travel mode per segment (#1281)

Each leg between two stops now routes with its own mode, so a day can mix
walking, driving and plugin-routed legs. Tap the connector between two
places to change that leg's mode (desktop popup / mobile sheet); the
whole-day Foot/Car picker sets the persisted day default and leaves
explicitly-set legs alone. The connector and map redraw in the chosen mode,
and each route segment is tagged with the mode it was drawn in.

New strings across all 23 locales.
This commit is contained in:
Maurice
2026-07-21 23:36:53 +02:00
committed by GitHub
parent ac723744ab
commit c5360be242
44 changed files with 348 additions and 56 deletions
+17
View File
@@ -3754,6 +3754,23 @@ function runMigrations(db: Database.Database): void {
`);
db.exec('CREATE INDEX IF NOT EXISTS idx_collection_place_ratings_place ON collection_place_ratings (collection_place_id);');
},
// Per-segment travel mode (#1281): the day-plan route can use a different
// transport mode for each leg. leg_transport_mode on an assignment is the mode
// of the leg LEAVING that stop (NULL = inherit the day default); days gains a
// persisted default_transport_mode so the whole-day choice survives a reload.
// Both nullable → existing itineraries keep today's single-mode behaviour.
() => {
try {
db.exec('ALTER TABLE day_assignments ADD COLUMN leg_transport_mode TEXT');
} catch (err: any) {
if (!err.message?.includes('duplicate column name')) throw err;
}
try {
db.exec('ALTER TABLE days ADD COLUMN default_transport_mode TEXT');
} catch (err: any) {
if (!err.message?.includes('duplicate column name')) throw err;
}
},
];
if (currentVersion < migrations.length) {
@@ -172,6 +172,24 @@ export class AssignmentOpsController {
return { assignment };
}
@Put(':id/transport')
transport(
@CurrentUser() user: User,
@Param('tripId') tripId: string,
@Param('id') id: string,
@Body() body: { transport_mode?: string | null },
@Headers('x-socket-id') socketId?: string,
) {
const trip = requireTrip(this.assignments, tripId, user);
requireEdit(this.assignments, trip, user);
if (!this.assignments.getAssignmentForTrip(id, tripId)) {
throw new HttpException({ error: 'Assignment not found' }, 404);
}
const assignment = this.assignments.setLegTransportMode(id, body.transport_mode ?? null);
this.assignments.broadcast(tripId, 'assignment:updated', { assignment }, socketId);
return { assignment };
}
@Put(':id/participants')
setParticipants(
@CurrentUser() user: User,
@@ -81,6 +81,10 @@ export class AssignmentsService {
return svc.updateTime(id, placeTime as never, endTime as never);
}
setLegTransportMode(id: string, mode: string | null) {
return svc.setLegTransportMode(id, mode);
}
setParticipants(id: string, userIds: number[]) {
return svc.setParticipants(id, userIds);
}
+18
View File
@@ -113,6 +113,24 @@ export class DaysController {
return { day };
}
@Put(':id/transport')
transport(
@CurrentUser() user: User,
@Param('tripId') tripId: string,
@Param('id') id: string,
@Body() body: { transport_mode?: string | null },
@Headers('x-socket-id') socketId?: string,
) {
const trip = this.requireTrip(tripId, user);
this.requireEdit(trip, user);
if (!this.days.getDay(id, tripId)) {
throw new HttpException({ error: 'Day not found' }, 404);
}
const day = this.days.setDefaultTransportMode(id, body.transport_mode ?? null);
this.days.broadcast(tripId, 'day:updated', { day }, socketId);
return { day };
}
@Delete(':id')
remove(
@CurrentUser() user: User,
+4
View File
@@ -51,6 +51,10 @@ export class DaysService {
return dayService.updateDay(id, current, fields);
}
setDefaultTransportMode(id: string, mode: string | null) {
return dayService.setDefaultTransportMode(id, mode);
}
remove(id: string): void {
dayService.deleteDay(id);
}
+12
View File
@@ -40,6 +40,7 @@ export function getAssignmentWithPlace(assignmentId: number | bigint) {
notes: a.notes,
assignment_time: a.assignment_time ?? null,
assignment_end_time: a.assignment_end_time ?? null,
leg_transport_mode: a.leg_transport_mode ?? null,
participants,
created_at: a.created_at,
place: {
@@ -201,6 +202,17 @@ export function updateTime(id: string | number, placeTime: string | null, endTim
return getAssignmentWithPlace(Number(id));
}
/**
* Set the travel mode of the leg leaving this stop (#1281). null clears the
* override so the leg falls back to the day's default_transport_mode. This is
* sticky by design: changing the whole-day default never touches a leg that
* carries its own explicit mode.
*/
export function setLegTransportMode(id: string | number, mode: string | null) {
db.prepare('UPDATE day_assignments SET leg_transport_mode = ? WHERE id = ?').run(mode ?? null, id);
return getAssignmentWithPlace(Number(id));
}
export function setParticipants(assignmentId: string | number, userIds: number[]) {
db.prepare('DELETE FROM assignment_participants WHERE assignment_id = ?').run(assignmentId);
if (userIds.length > 0) {
+11
View File
@@ -155,6 +155,17 @@ export function updateDay(id: string | number, current: Day, fields: { notes?: s
return { ...updatedDay, assignments: getAssignmentsForDay(id) };
}
/**
* Set the whole-day default route mode (#1281). Its own endpoint so it can't wipe
* notes/title the way the general day update would, and symmetric with the
* per-leg assignment transport setter. Per-segment leg modes still override it.
*/
export function setDefaultTransportMode(id: string | number, mode: string | null) {
db.prepare('UPDATE days SET default_transport_mode = ? WHERE id = ?').run(mode ?? null, id);
const updatedDay = db.prepare('SELECT * FROM days WHERE id = ?').get(id) as Day;
return { ...updatedDay, assignments: getAssignmentsForDay(id) };
}
export function deleteDay(id: string | number) {
db.prepare('DELETE FROM days WHERE id = ?').run(id);
}
+1
View File
@@ -95,6 +95,7 @@ function formatAssignmentWithPlace(a: AssignmentRow, tags: Partial<Tag>[], parti
notes: a.notes,
assignment_time: a.assignment_time ?? null,
assignment_end_time: a.assignment_end_time ?? null,
leg_transport_mode: a.leg_transport_mode ?? null,
participants: participants || [],
created_at: a.created_at,
place: {
+2
View File
@@ -48,6 +48,7 @@ export interface Day {
date?: string | null;
notes?: string | null;
title?: string | null;
default_transport_mode?: string | null;
}
export interface Place {
@@ -107,6 +108,7 @@ export interface DayAssignment {
reservation_datetime?: string | null;
assignment_time?: string | null;
assignment_end_time?: string | null;
leg_transport_mode?: string | null;
created_at?: string;
}