feat(tours): show a multi-day tour's stages in the list and put each on a day

A multi-day tour in the planner's list of the trip's tours now unfolds into
its stages (MDT-02), so the stages can be seen together and fitted into the
trip without leaving the one route they are cut from.

- The fold beside a multi-day tour lists its stages in route order, each
  from stop to stop with its distance, climb, descent and moving time, read
  off the saved tour the way the planner reads them, and below them what the
  whole tour adds up to. A value no stage tells is left out, a total some
  stages do not tell is marked as at least that much and says for how many,
  and a stage whose route is not planned yet says so.
- Each stage has its own day: a pill opens the trip's days, moves the stage
  to another one or takes it off again. A stage without a day shows a dashed
  "No day" pill. A day holds a tour, or one of its stages, once, and a stage
  is on one day at most; the plan's own offline path writes it.
- A stage opens in the planner: the tour opens as any tour does and the
  stage is shown once its points are in.
- The day plan names the stage a day holds with its own figures, and the
  day's route runs to that stage's start and on from its end; the trip map
  draws that stretch only. The tour list still counts a tour once, however
  many days hold it or its stages.
- A saved change that takes a stage away (its stage end gone, the tour a day
  tour again, back to the recorded track) takes it off its day in the same
  write and tells every client; the planner says so before the save.
- REST and the assign_place_to_day tool take the stage by the key of the
  stop it starts at, with the same checks; list_tours names the stops
  between the stages and the stage each day holds.

A day assignment remembers its stage by that key (migration 046010); every
assignment made before holds the whole tour, as it did.
This commit is contained in:
Maurice
2026-10-20 13:21:10 +02:00
parent 6ec06c90f4
commit 8fa75b3c4e
100 changed files with 2787 additions and 127 deletions
+4 -3
View File
@@ -374,21 +374,22 @@ export interface TestDayAssignment {
place_id: number;
order_index: number;
notes: string | null;
tour_stage_key: string | null;
}
export function createDayAssignment(
db: Database.Database,
dayId: number,
placeId: number,
overrides: Partial<{ order_index: number; notes: string }> = {},
overrides: Partial<{ order_index: number; notes: string; tour_stage_key: string }> = {},
): TestDayAssignment {
const maxOrder = db.prepare('SELECT MAX(order_index) as max FROM day_assignments WHERE day_id = ?').get(dayId) as {
max: number | null;
};
const orderIndex = overrides.order_index ?? (maxOrder.max !== null ? maxOrder.max + 1 : 0);
const result = db
.prepare('INSERT INTO day_assignments (day_id, place_id, order_index, notes) VALUES (?, ?, ?, ?)')
.run(dayId, placeId, orderIndex, overrides.notes ?? null);
.prepare('INSERT INTO day_assignments (day_id, place_id, order_index, notes, tour_stage_key) VALUES (?, ?, ?, ?, ?)')
.run(dayId, placeId, orderIndex, overrides.notes ?? null, overrides.tour_stage_key ?? null);
return db.prepare('SELECT * FROM day_assignments WHERE id = ?').get(result.lastInsertRowid) as TestDayAssignment;
}
@@ -0,0 +1,19 @@
/**
* The part of AssignmentsService that ToursService asks when a saved change
* takes stages of a multi-day tour off their days (MDT-02), for suites that
* build ToursService by hand. Given the day assignments repository it takes
* the rows off for real, so a suite on the test database sees them go;
* without one there is nothing to take off. The journey refresh after it is
* left out: the assignments suites cover it.
*/
import type { DayAssignmentsRepository } from '../../src/db/repositories/DayAssignments.repository';
import type { AssignmentsService } from '../../src/nest/assignments/assignments.service';
export function tourStageDays(dayAssignments?: DayAssignmentsRepository): AssignmentsService {
const stages = {
dropStaleTourStages: async (placeId: number, keys: readonly string[]) =>
dayAssignments ? await dayAssignments.deleteTourStagesNotIn(placeId, keys) : [],
reconcile: async () => undefined,
};
return stages as unknown as AssignmentsService;
}