mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 02:56:10 +00:00
fix(roadtrip): keep the stay on each visit, not on the place (#3092)
A nullable day_assignments.stay_minutes holds the stay of one visit; a visit without one keeps reading the place's duration, so existing trips drive as before. REST PUT /trips/:tripId/assignments/:id/stay and the MCP tool set_assignment_stay write it with day_edit.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { assignmentSchema, type AssignmentStayRequest } from '@trek/shared';
|
||||
import { apiClient } from './client';
|
||||
|
||||
/** How long the drive stands at one visit (#3092); null hands it back to the place's stay. */
|
||||
export async function saveAssignmentStay(tripId: number | string, id: number, body: AssignmentStayRequest) {
|
||||
const saved = await apiClient.put(`/trips/${tripId}/assignments/${id}/stay`, body);
|
||||
return assignmentSchema.parse(saved.data.assignment);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export function stopSpan(assignment: Assignment): DaySpan | null {
|
||||
if (start === null) return null;
|
||||
const end = clockMinutes(assignment.assignment_end_time ?? assignment.place.end_time);
|
||||
if (end !== null && end > start) return { start, end };
|
||||
const duration = assignment.place.duration_minutes ?? 0;
|
||||
const duration = assignment.stay_minutes ?? assignment.place.duration_minutes ?? 0;
|
||||
return { start, end: duration > 0 ? Math.min(start + duration, MINUTES_PER_DAY) : null };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { AssistantChangeEffect } from '@trek/shared';
|
||||
import { dayPoints, type LatLng } from '../../store/assistantMapModel';
|
||||
import type { Assignment, AssignmentsMap, Place } from '../../types';
|
||||
import { haversineKm } from '../../utils/geo';
|
||||
import { stayOf } from '../Roadtrip/stayReading';
|
||||
|
||||
/**
|
||||
* A day as it would read once the waiting changes of a card ran: the stops it
|
||||
@@ -91,7 +92,7 @@ function draftOf(visit: Assignment, status: StopStatus, toolCallId: string | nul
|
||||
const time = visit.assignment_time ?? place?.place_time ?? null;
|
||||
const start = minutesOf(time);
|
||||
const explicitEnd = minutesOf(visit.assignment_end_time ?? place?.end_time ?? null);
|
||||
const duration = place?.duration_minutes;
|
||||
const duration = stayOf(visit);
|
||||
const end = explicitEnd ?? (start !== null && typeof duration === 'number' && duration > 0 ? start + duration : null);
|
||||
return {
|
||||
stop: { key, name: place?.name ?? '', status, toolCallId, time: start === null ? null : time },
|
||||
|
||||
@@ -105,7 +105,7 @@ describe('RoadtripStayModal', () => {
|
||||
fireEvent.change(slider(), { target: { value: '45' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: /^save$/i }))
|
||||
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(9, 45))
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(9, 45, undefined))
|
||||
await waitFor(() => expect(onClose).toHaveBeenCalled())
|
||||
})
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('RoadtripStayModal', () => {
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /no stay|none/i }))
|
||||
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(9, 0))
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(9, 0, undefined))
|
||||
expect(onSave.mock.calls[0][1]).not.toBeNull()
|
||||
})
|
||||
|
||||
|
||||
@@ -29,8 +29,11 @@ export interface StayDraft {
|
||||
interface RoadtripStayModalProps {
|
||||
stop: StayDraft | null
|
||||
onClose: () => void
|
||||
/** Zero clears it: the rail reads "no stay" and "nothing planned" as the same thing. */
|
||||
onSave: (placeId: number, minutes: number) => Promise<void> | void
|
||||
/**
|
||||
* Zero clears it: the rail reads "no stay" and "nothing planned" as the same thing.
|
||||
* The visit rides along, so the stay lands on it and not on every visit of the place.
|
||||
*/
|
||||
onSave: (placeId: number, minutes: number, assignmentId?: number) => Promise<void> | void
|
||||
}
|
||||
|
||||
/** The round minus and plus beside the number. */
|
||||
@@ -59,10 +62,11 @@ const SLIDER = [
|
||||
* question the number is actually being chosen for: given when the drive arrives, when
|
||||
* does it leave again. Typing minutes into a box could never show that.
|
||||
*
|
||||
* The value is `places.duration_minutes`, which the schedule has read for years and
|
||||
* nothing has ever been able to write. Cleared as a zero rather than a null, because the
|
||||
* update statement folds a null into "leave it alone" — a null could give a stop a stay
|
||||
* but never take one away.
|
||||
* The value is the visit's own stay (`day_assignments.stay_minutes`, #3092), so two
|
||||
* visits of one place can last differently; a stop without a saved visit writes the
|
||||
* place's `duration_minutes`, which a visit without a stay of its own reads. Cleared as a
|
||||
* zero rather than a null, because a null would hand the visit back to the place's stay
|
||||
* instead of taking the stay away.
|
||||
*/
|
||||
export default function RoadtripStayModal({ stop, onClose, onSave }: RoadtripStayModalProps): React.ReactElement | null {
|
||||
const { t } = useTranslation()
|
||||
@@ -86,7 +90,7 @@ export default function RoadtripStayModal({ stop, onClose, onSave }: RoadtripSta
|
||||
if (saving) return
|
||||
setSaving(true)
|
||||
try {
|
||||
await onSave(stop.placeId, value)
|
||||
await onSave(stop.placeId, value, stop.assignmentId)
|
||||
onClose()
|
||||
} finally {
|
||||
setSaving(false)
|
||||
|
||||
@@ -29,7 +29,8 @@ import type { RoadtripStopType } from '@trek/shared'
|
||||
// from the one table in stopKinds.ts.
|
||||
|
||||
export interface RoadtripStopDraft {
|
||||
editing?: { placeId: number; dwellMinutes: number; stopType: RoadtripStopType | null; accommodationId?: number; checkIn?: string; checkOut?: string }
|
||||
/** `assignmentId` is the visit being edited: its stay is its own, not every visit's of the place (#3092). */
|
||||
editing?: { placeId: number; assignmentId?: number; dwellMinutes: number; stopType: RoadtripStopType | null; accommodationId?: number; checkIn?: string; checkOut?: string }
|
||||
arrivalTime?: string | null
|
||||
poi: CorridorPoi
|
||||
dayId: number
|
||||
|
||||
@@ -2,15 +2,27 @@ import { formatClock, parseClock, type ScheduleEntry } from './roadtripModel'
|
||||
import type { RoadtripDay, RoadtripStop } from '@trek/shared/roadtrip'
|
||||
import type { StayDraft } from './RoadtripStayModal'
|
||||
import type { RoadtripStayControl } from './VisitControls'
|
||||
import type { Assignment } from '../../types'
|
||||
|
||||
/**
|
||||
* How long the drive stands at one visit: its own stay (#3092), else the one its place
|
||||
* carries. A place planned twice can be stopped at once and only driven past the other
|
||||
* time, and a visit nobody gave a length keeps reading the place, as every visit did
|
||||
* before the stay moved onto it.
|
||||
*/
|
||||
export function stayOf(a: Pick<Assignment, 'stay_minutes' | 'place'>): number | null {
|
||||
if (typeof a.stay_minutes === 'number') return a.stay_minutes
|
||||
return typeof a.place?.duration_minutes === 'number' ? a.place.duration_minutes : null
|
||||
}
|
||||
|
||||
/**
|
||||
* How long a stop is stood at, the way a stay badge shows it.
|
||||
*
|
||||
* For most stops that is the stay the place carries. A stop with a time set to leave it
|
||||
* is stood at from whenever the drive gets there until that time, so its stay is what
|
||||
* For most stops that is the stay of the visit (`stayOf`). A stop with a time set to leave
|
||||
* it is stood at from whenever the drive gets there until that time, so its stay is what
|
||||
* the schedule made of it and `until` says when it ends. The number is read here and
|
||||
* never written back to the place: the stay belongs to the place, the end time to one
|
||||
* visit of it, and a stored copy would be wrong the moment the arrival moved.
|
||||
* never written back: the end time decides it, and a stored copy would be wrong the
|
||||
* moment the arrival moved.
|
||||
*/
|
||||
export interface StayReading {
|
||||
minutes: number | null
|
||||
|
||||
@@ -5,6 +5,7 @@ import { avoidedClasses, calculateRouteWithLegs, routeEngineFor, RoutingRefusedE
|
||||
import { resolveLegMode } from '../Planner/legMode'
|
||||
import { splitIntoRuns, parseAvoid, type DriveLimits } from './roadtripModel'
|
||||
import { spillChains } from './nightSpill'
|
||||
import { stayOf } from './stayReading'
|
||||
import { useSettingsStore } from '../../store/settingsStore'
|
||||
import { useTripStore } from '../../store/tripStore'
|
||||
import { useVehicleRange } from './useVehicleRange'
|
||||
@@ -201,7 +202,7 @@ const asStop = (a: Assignment, ownerDayId: number, ownerIndex: number, accommoda
|
||||
checkInTime: stay?.check_in ?? null,
|
||||
night: stay !== undefined,
|
||||
bookedNightId: a.accommodation_id ?? null,
|
||||
dwellMinutes: typeof p.duration_minutes === 'number' ? p.duration_minutes : null,
|
||||
dwellMinutes: stayOf(a),
|
||||
endDay: a.end_day === true,
|
||||
legMode: a.leg_transport_mode ?? null,
|
||||
incomingLegMode: a.incoming_leg_transport_mode ?? null,
|
||||
|
||||
@@ -31,10 +31,10 @@ interface RtStaySheetPayload {
|
||||
* How long the traveller stays at one stop, on the phone ('rtstay', payload
|
||||
* { placeId, minutes, name }).
|
||||
*
|
||||
* Writes `places.duration_minutes` through `planner.setRoadtripStay`, which is the same
|
||||
* single write the desktop dialog makes. Zero rather than null clears it: the update
|
||||
* statement folds a null into "leave it alone", so a null could give a stop a stay but
|
||||
* never take one away.
|
||||
* Writes the stay of the visit it was opened on through `planner.setRoadtripStay`, which
|
||||
* is the same single write the desktop dialog makes, so two visits of one place keep
|
||||
* their own lengths (#3092). Zero rather than null clears it: a null would hand the visit
|
||||
* back to the place's stay instead of taking the stay away.
|
||||
*
|
||||
* Two things this sheet deliberately does not do:
|
||||
*
|
||||
@@ -51,7 +51,9 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
const open = shell.sheet?.id === 'rtstay'
|
||||
const payload = (shell.sheet?.payload ?? {}) as RtStaySheetPayload
|
||||
const is12h = useSettingsStore(s => s.settings.time_format) === '12h'
|
||||
const canEdit = planner.can('place_edit', planner.trip)
|
||||
// A visit's stay is part of the day plan; only a stop with no saved visit writes the place.
|
||||
const onVisit = typeof payload.assignmentId === 'number' && payload.assignmentId > 0
|
||||
const canEdit = planner.can(onVisit ? 'day_edit' : 'place_edit', planner.trip)
|
||||
|
||||
// Hold the last payload so the name and the number survive the exit animation
|
||||
// instead of blinking out while the sheet slides away.
|
||||
@@ -124,7 +126,7 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
const value = minutes
|
||||
setSaving(true)
|
||||
try {
|
||||
await planner.setRoadtripStay(placeId, value)
|
||||
await planner.setRoadtripStay(placeId, value, stop?.assignmentId)
|
||||
// 'rtstop' is located by day and assignment, not by place: spreading this sheet's own
|
||||
// payload into it opened a sheet that resolved to nothing, drew nothing, and still
|
||||
// counted as open, which blocks the day swipe until something else closes it.
|
||||
|
||||
@@ -87,6 +87,8 @@ export interface PlaceVisit {
|
||||
endTime: string | null;
|
||||
notes: string | null;
|
||||
endDay: boolean;
|
||||
/** The visit's own stay (#3092), or null where it read the place's. */
|
||||
stayMinutes: number | null;
|
||||
routeExcluded: boolean;
|
||||
legMode: string | null;
|
||||
incomingLegMode: string | null;
|
||||
@@ -103,6 +105,7 @@ export function visitOf(dayId: number, a: Assignment): PlaceVisit {
|
||||
endTime: a.assignment_end_time ?? null,
|
||||
notes: a.notes ?? null,
|
||||
endDay: a.end_day === true,
|
||||
stayMinutes: a.stay_minutes ?? null,
|
||||
routeExcluded: a.route_excluded === true,
|
||||
legMode: a.leg_transport_mode ?? null,
|
||||
incomingLegMode: a.incoming_leg_transport_mode ?? null,
|
||||
@@ -123,6 +126,7 @@ export type RestoreActions = Pick<
|
||||
| 'setAssignmentTimes'
|
||||
| 'setAssignmentNotes'
|
||||
| 'setAssignmentEndDay'
|
||||
| 'setAssignmentStay'
|
||||
| 'setAssignmentRouteExcluded'
|
||||
| 'setAssignmentParticipants'
|
||||
| 'setAssignmentLegMode'
|
||||
@@ -153,7 +157,7 @@ export async function restorePlace(
|
||||
return restored;
|
||||
}
|
||||
|
||||
/** Gives a visit planned again the times, note, end of day, travellers and legs it had. */
|
||||
/** Gives a visit planned again the times, note, end of day, stay, travellers and legs it had. */
|
||||
export async function restoreVisit(
|
||||
tripId: number | string,
|
||||
actions: Omit<RestoreActions, 'addPlace' | 'assignPlaceToDay' | 'ratePlace'>,
|
||||
@@ -166,6 +170,7 @@ export async function restoreVisit(
|
||||
}
|
||||
if (visit.notes) await actions.setAssignmentNotes(tripId, dayId, assignmentId, visit.notes);
|
||||
if (visit.endDay) await actions.setAssignmentEndDay(tripId, dayId, assignmentId, true);
|
||||
if (visit.stayMinutes !== null) await actions.setAssignmentStay(tripId, dayId, assignmentId, visit.stayMinutes);
|
||||
if (visit.routeExcluded) await actions.setAssignmentRouteExcluded(tripId, dayId, assignmentId, true);
|
||||
if (visit.participantIds.length > 0)
|
||||
await actions.setAssignmentParticipants(tripId, dayId, assignmentId, visit.participantIds);
|
||||
|
||||
@@ -306,7 +306,7 @@ export function usePlaceFormOpeners(options: PlaceFormOpenersOptions) {
|
||||
setStopDraft({
|
||||
poi: { osm_id: place.osm_id ?? '', name: place.name, lat: place.lat, lng: place.lng, category, poi_type: category, address: place.address ?? null, website: place.website ?? null, phone: place.phone ?? null, opening_hours: null, cuisine: null, source: 'trek', offRouteKm: 0, alongKm: 0 },
|
||||
arrivalTime, dayId, dayNumber: days.find(day => day.id === dayId)?.day_number ?? 0, position: visit.order_index ?? 0,
|
||||
editing: { placeId: place.id, stopType: place.stop_type ?? (stay ? 'hotel' : null), dwellMinutes: place.duration_minutes ?? 30, accommodationId: stay?.id, checkIn: stay?.check_in ?? '', checkOut: stay?.check_out ?? '' },
|
||||
editing: { placeId: place.id, assignmentId: visit.id, stopType: place.stop_type ?? (stay ? 'hotel' : null), dwellMinutes: visit.stay_minutes ?? place.duration_minutes ?? 30, accommodationId: stay?.id, checkIn: stay?.check_in ?? '', checkOut: stay?.check_out ?? '' },
|
||||
...(isOvernightCategory(category) ? { overnight: { ...overnightOptions(dayId), ...(stay ? { defaultEndDayId: stay.end_day_id } : {}) } } : {}),
|
||||
})
|
||||
return
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-TP-STOPEDITS-001 to FE-TP-STOPEDITS-016
|
||||
// FE-TP-STOPEDITS-001 to FE-TP-STOPEDITS-018
|
||||
//
|
||||
// Edits to one stop on the drive, driven straight through useRoadtripStopEdits. The
|
||||
// stop popup's draft and the stay release question are real state in the harness, so
|
||||
@@ -8,6 +8,7 @@ import { act, renderHook } from '@testing-library/react'
|
||||
import { accommodationsApi } from '../../api/client'
|
||||
import type { RoadtripStopDraft } from '../../components/Roadtrip/RoadtripStopPopup'
|
||||
import { reanchorAfterInsert, reanchorAfterRemove, reanchorAfterReorder } from '../../components/Roadtrip/roadtripModel'
|
||||
import { stayOf } from '../../components/Roadtrip/stayReading'
|
||||
import type { CorridorPoi } from '../../components/Roadtrip/useCorridorPois'
|
||||
import type { RoadtripStop } from '../../components/Roadtrip/useRoadtripRoutes'
|
||||
import { useTripStore, type TripStoreState } from '../../store/tripStore'
|
||||
@@ -17,6 +18,7 @@ import type { Accommodation, AssignmentsMap } from '../../types'
|
||||
import type { Can, Translate } from './plannerTypes'
|
||||
import type { PlannerDialogs } from './usePlannerDialogs'
|
||||
import type { RoadtripFeed } from './useRoadtripFeed'
|
||||
import { assignmentRepo } from '../../repo/assignmentRepo'
|
||||
import { useRoadtripStopEdits } from './useRoadtripStopEdits'
|
||||
|
||||
type Options = Parameters<typeof useRoadtripStopEdits>[0]
|
||||
@@ -485,4 +487,47 @@ describe('useRoadtripStopEdits', () => {
|
||||
'common.unknownError', 'common.unknownError',
|
||||
])
|
||||
})
|
||||
|
||||
// #3092: the same place planned twice on a day, once to stop and once only to steer the
|
||||
// route past it. The stay belongs to the visit, so changing one leaves the other alone.
|
||||
describe('a stay per visit', () => {
|
||||
const viewpoint = buildPlace({ id: 70, lat: 50, lng: 13, duration_minutes: 45 })
|
||||
const twice: AssignmentsMap = {
|
||||
5: [
|
||||
buildAssignment({ id: 51, day_id: 5, place: viewpoint, place_id: 70, order_index: 0 }),
|
||||
buildAssignment({ id: 52, day_id: 5, place: viewpoint, place_id: 70, order_index: 1 }),
|
||||
],
|
||||
}
|
||||
const seed = () => {
|
||||
useTripStore.setState({ assignments: twice })
|
||||
vi.spyOn(assignmentRepo, 'setStay').mockImplementation(async (_tripId, visit, minutes) => ({ ...visit, stay_minutes: minutes }))
|
||||
return { ...useTripStore.getState(), ...actions, setAssignmentStay: useTripStore.getState().setAssignmentStay } as unknown as TripStoreState
|
||||
}
|
||||
|
||||
it('FE-TP-STOPEDITS-017: the stay dialog changes one visit of a place and leaves the other visit of it alone', async () => {
|
||||
const tripActions = seed()
|
||||
const { result } = renderEdits(null, { tripActions, assignments: twice })
|
||||
|
||||
await act(async () => { await result.current.setRoadtripStay(70, 0, 52) })
|
||||
|
||||
expect(actions.updatePlace).not.toHaveBeenCalled()
|
||||
expect(assignmentRepo.setStay).toHaveBeenCalledWith(42, expect.objectContaining({ id: 52 }), 0)
|
||||
const [first, second] = useTripStore.getState().assignments['5']
|
||||
expect(stayOf(first)).toBe(45)
|
||||
expect(stayOf(second)).toBe(0)
|
||||
})
|
||||
|
||||
it('FE-TP-STOPEDITS-018: the stop popup writes the kind on the place and the stay on the visit it was opened on', async () => {
|
||||
const tripActions = seed()
|
||||
const editing = { placeId: 70, assignmentId: 51, dwellMinutes: 45, stopType: null }
|
||||
const { result } = renderEdits({ poi: hit(), dayId: 5, position: 0, dayNumber: 5, editing }, { tripActions, assignments: twice })
|
||||
|
||||
await act(async () => { await result.current.saveStopDraft({ stopType: 'rest_area', dwellMinutes: 90 }) })
|
||||
|
||||
expect(actions.updatePlace).toHaveBeenCalledWith(42, 70, { stop_type: 'rest_area' })
|
||||
const [first, second] = useTripStore.getState().assignments['5']
|
||||
expect(stayOf(first)).toBe(90)
|
||||
expect(stayOf(second)).toBe(45)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -24,6 +24,40 @@ interface RoadtripStopEditsOptions
|
||||
updateRouteForDay: ReturnType<typeof useRouteCalculation>['updateRouteForDay']
|
||||
}
|
||||
|
||||
/**
|
||||
* The day a saved visit is stored on, or null for none: no visit named, the optimistic
|
||||
* row of one still being saved (a negative id the server never issued), or one no longer
|
||||
* planned. A stay is written onto such a visit (#3092); without one it falls back to the
|
||||
* place.
|
||||
*/
|
||||
function savedVisitDayOf(assignments: TripStoreState['assignments'], assignmentId: number | undefined): number | null {
|
||||
if (assignmentId == null || assignmentId <= 0) return null
|
||||
const day = Object.entries(assignments).find(([, visits]) => visits.some(visit => visit.id === assignmentId))
|
||||
return day ? Number(day[0]) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the stop popup over a stop already on the drive. The kind is the place's, the stay
|
||||
* the visit's (#3092): a place planned twice keeps a stay per visit, so the popup on one
|
||||
* of them leaves the other one's alone. A stop with no saved visit writes both onto the
|
||||
* place, as before.
|
||||
*/
|
||||
async function writeEditedStop(
|
||||
tripActions: TripStoreState,
|
||||
tripId: PlannerBase['tripId'],
|
||||
assignments: TripStoreState['assignments'],
|
||||
{ placeId, assignmentId }: { placeId: number; assignmentId?: number },
|
||||
{ stopType, dwellMinutes }: { stopType: RoadtripStopType | null; dwellMinutes: number },
|
||||
): Promise<void> {
|
||||
const visitDayId = savedVisitDayOf(assignments, assignmentId)
|
||||
if (assignmentId == null || visitDayId === null) {
|
||||
await tripActions.updatePlace(tripId, placeId, { stop_type: stopType, duration_minutes: dwellMinutes })
|
||||
return
|
||||
}
|
||||
await tripActions.updatePlace(tripId, placeId, { stop_type: stopType })
|
||||
await tripActions.setAssignmentStay(tripId, visitDayId, assignmentId, dwellMinutes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits to one stop on the drive: saving the stop popup as a pause or as a night,
|
||||
* releasing a booked night, the kind, fill and stay of a stop, moving it within its day
|
||||
@@ -63,7 +97,7 @@ export function useRoadtripStopEdits(options: RoadtripStopEditsOptions) {
|
||||
}
|
||||
try {
|
||||
if (stopDraft.editing) {
|
||||
await tripActions.updatePlace(tripId, stopDraft.editing.placeId, { stop_type: stopType, duration_minutes: dwellMinutes })
|
||||
await writeEditedStop(tripActions, tripId, assignments, stopDraft.editing, { stopType, dwellMinutes })
|
||||
if (accommodationId) {
|
||||
// The night is what was switched off, not the stop: it stays where it is
|
||||
// in the drive and becomes an ordinary pause.
|
||||
@@ -106,7 +140,7 @@ export function useRoadtripStopEdits(options: RoadtripStopEditsOptions) {
|
||||
} catch (err: unknown) {
|
||||
toast.error(err instanceof Error ? err.message : t('common.unknownError'))
|
||||
}
|
||||
}, [stopDraft, tripId, tripActions, updateRouteForDay, toast, t, roadtripVias, viaLiesBefore, loadAccommodations, tripAccommodations, reservations, setStayRelease, setStopDraft])
|
||||
}, [stopDraft, tripId, tripActions, updateRouteForDay, toast, t, roadtripVias, viaLiesBefore, loadAccommodations, tripAccommodations, reservations, setStayRelease, setStopDraft, assignments])
|
||||
|
||||
/** The yes to the question above: the same save, this time allowed to drop the night. */
|
||||
const confirmStayRelease = useCallback(async () => {
|
||||
@@ -315,22 +349,32 @@ export function useRoadtripStopEdits(options: RoadtripStopEditsOptions) {
|
||||
/**
|
||||
* How long the traveller stays at one stop.
|
||||
*
|
||||
* Writes `places.duration_minutes`, which the schedule has read since it was written
|
||||
* and which nothing in TREK has ever been able to set: the road trip is the only place
|
||||
* the value means anything, so it is the only place that edits it.
|
||||
* The stay belongs to the visit (#3092): the same place planned twice on a day can be
|
||||
* stopped at once and only driven past the other time, so a stop the rail names by its
|
||||
* assignment writes `day_assignments.stay_minutes` and leaves the place and its other
|
||||
* visits alone. Only a stop without a saved visit of its own (no assignment, or the
|
||||
* optimistic row of one still on its way) falls back to the place's
|
||||
* `duration_minutes`, which every visit without a stay of its own reads.
|
||||
*
|
||||
* Zero rather than null to clear: the update statement folds a null into "leave it
|
||||
* alone" (`COALESCE(?, duration_minutes)`), so a null could give a stop a stay but
|
||||
* never take one away. The rail reads zero and absent as the same thing.
|
||||
* Zero rather than null to clear: on the place the update statement folds a null into
|
||||
* "leave it alone" (`COALESCE(?, duration_minutes)`), and on a visit a null would hand
|
||||
* it back to the place's stay instead of taking the stay away. The rail reads zero and
|
||||
* absent as the same thing.
|
||||
*/
|
||||
const setRoadtripStay = useCallback(async (placeId: number, minutes: number) => {
|
||||
if (!can('place_edit', trip)) return
|
||||
const setRoadtripStay = useCallback(async (placeId: number, minutes: number, assignmentId?: number) => {
|
||||
const visitDayId = savedVisitDayOf(assignments, assignmentId)
|
||||
try {
|
||||
if (assignmentId != null && visitDayId !== null) {
|
||||
if (!can('day_edit', trip)) return
|
||||
await tripActions.setAssignmentStay(tripId, visitDayId, assignmentId, minutes)
|
||||
return
|
||||
}
|
||||
if (!can('place_edit', trip)) return
|
||||
await tripActions.updatePlace(tripId, placeId, { duration_minutes: minutes })
|
||||
} catch (err: unknown) {
|
||||
toast.error(err instanceof Error ? err.message : t('common.unknownError'))
|
||||
}
|
||||
}, [tripId, tripActions, toast, t, can, trip])
|
||||
}, [assignments, tripId, tripActions, toast, t, can, trip])
|
||||
|
||||
/**
|
||||
* Moves a stop onto another day, from the road trip rail.
|
||||
|
||||
@@ -3,12 +3,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { assignmentRepo } from './assignmentRepo'
|
||||
import { offlineDb, clearAll } from '../db/offlineDb'
|
||||
import { saveAssignmentEndDay } from '../api/assignmentEndDay'
|
||||
import { saveAssignmentStay } from '../api/assignmentStay'
|
||||
import { isEffectivelyOffline } from '../sync/networkMode'
|
||||
import { mutationQueue } from '../sync/mutationQueue'
|
||||
import { apiClient, assignmentsApi } from '../api/client'
|
||||
import type { Assignment, Day } from '../types'
|
||||
|
||||
vi.mock('../api/assignmentEndDay', () => ({ saveAssignmentEndDay: vi.fn() }))
|
||||
vi.mock('../api/assignmentStay', () => ({ saveAssignmentStay: vi.fn() }))
|
||||
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn(() => true) }))
|
||||
vi.mock('../sync/authGate', () => ({ isAuthed: () => true }))
|
||||
vi.mock('../api/client', () => ({ apiClient: { request: vi.fn() }, assignmentsApi: { updateTime: vi.fn(), updateNotes: vi.fn(), clearDay: vi.fn() } }))
|
||||
@@ -51,6 +53,24 @@ describe('assignment day-end persistence', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('assignment stay persistence (#3092)', () => {
|
||||
it('stores the stay on the one visit offline with a replayable write', async () => {
|
||||
await assignmentRepo.setStay(9, assignment, 0)
|
||||
expect((await offlineDb.days.get(1))?.assignments?.[0]).toMatchObject({ id: 7, stay_minutes: 0 })
|
||||
expect(await offlineDb.mutationQueue.toArray()).toEqual([expect.objectContaining({
|
||||
url: '/trips/9/assignments/7/stay', method: 'PUT', body: { stay_minutes: 0 }, resource: 'assignments', entityId: 7,
|
||||
})])
|
||||
})
|
||||
|
||||
it('saves through the online API and caches what came back', async () => {
|
||||
vi.mocked(isEffectivelyOffline).mockReturnValue(false)
|
||||
vi.mocked(saveAssignmentStay).mockResolvedValue({ ...assignment, stay_minutes: 20 })
|
||||
await assignmentRepo.setStay(9, assignment, 20)
|
||||
expect(saveAssignmentStay).toHaveBeenCalledWith(9, 7, { stay_minutes: 20 })
|
||||
expect((await offlineDb.days.get(1))?.assignments?.[0].stay_minutes).toBe(20)
|
||||
})
|
||||
})
|
||||
|
||||
describe('assignment time persistence', () => {
|
||||
const times = { place_time: '07:00', end_time: null }
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { assignmentSchema } from '@trek/shared'
|
||||
import { saveAssignmentEndDay } from '../api/assignmentEndDay'
|
||||
import { saveAssignmentStay } from '../api/assignmentStay'
|
||||
import { assignmentsApi } from '../api/client'
|
||||
import { offlineDb } from '../db/offlineDb'
|
||||
import { cacheAssignment } from '../db/cacheAssignment'
|
||||
@@ -32,6 +33,34 @@ async function cacheVisitFields(tripId: number, id: number, fields: Partial<Assi
|
||||
}
|
||||
|
||||
/** The day's visits in the order given; the ones not named keep their place behind them. */
|
||||
/**
|
||||
* One field of a saved visit, written through its own route: sent straight away when
|
||||
* nothing older to the visit waits in the queue, otherwise queued behind it with the
|
||||
* cached row patched, so the planner shows the change offline as well.
|
||||
*/
|
||||
async function writeVisitField(
|
||||
tripId: number | string,
|
||||
assignment: Assignment,
|
||||
write: { suffix: string; body: Record<string, unknown>; fields: Partial<Assignment>; send: () => Promise<Assignment> },
|
||||
): Promise<Assignment> {
|
||||
if (!(await mutationQueue.mustQueue('assignments', assignment.id))) {
|
||||
const saved = await write.send()
|
||||
await cacheAssignment(saved)
|
||||
return saved
|
||||
}
|
||||
const updated = { ...assignment, ...write.fields }
|
||||
await offlineDb.transaction('rw', offlineDb.days, offlineDb.mutationQueue, async () => {
|
||||
await mutationQueue.enqueue({
|
||||
id: generateUUID(), tripId: Number(tripId), method: 'PUT',
|
||||
url: `/trips/${tripId}/assignments/${assignment.id}/${write.suffix}`,
|
||||
body: write.body, resource: 'assignments', entityId: assignment.id,
|
||||
})
|
||||
await cacheAssignment(updated)
|
||||
})
|
||||
mutationQueue.sendSoon()
|
||||
return updated
|
||||
}
|
||||
|
||||
function inOrder(items: Assignment[], orderedIds: number[]): Assignment[] {
|
||||
const rank = new Map(orderedIds.map((id, index) => [id, index]))
|
||||
return items
|
||||
@@ -237,42 +266,29 @@ export const assignmentRepo = {
|
||||
},
|
||||
|
||||
async setEndDay(tripId: number | string, assignment: Assignment, endDay: boolean): Promise<Assignment> {
|
||||
if (!(await mutationQueue.mustQueue('assignments', assignment.id))) {
|
||||
const saved = await saveAssignmentEndDay(tripId, assignment.id, { end_day: endDay })
|
||||
await cacheAssignment(saved)
|
||||
return saved
|
||||
}
|
||||
const updated = { ...assignment, end_day: endDay }
|
||||
await offlineDb.transaction('rw', offlineDb.days, offlineDb.mutationQueue, async () => {
|
||||
await mutationQueue.enqueue({
|
||||
id: generateUUID(), tripId: Number(tripId), method: 'PUT',
|
||||
url: `/trips/${tripId}/assignments/${assignment.id}/end-day`,
|
||||
body: { end_day: endDay }, resource: 'assignments', entityId: assignment.id,
|
||||
})
|
||||
await cacheAssignment(updated)
|
||||
return await writeVisitField(tripId, assignment, {
|
||||
suffix: 'end-day', body: { end_day: endDay }, fields: { end_day: endDay },
|
||||
send: () => saveAssignmentEndDay(tripId, assignment.id, { end_day: endDay }),
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* How long the drive stands at this one visit (#3092), offline too. Null hands the
|
||||
* visit back to the stay its place carries.
|
||||
*/
|
||||
async setStay(tripId: number | string, assignment: Assignment, stayMinutes: number | null): Promise<Assignment> {
|
||||
return await writeVisitField(tripId, assignment, {
|
||||
suffix: 'stay', body: { stay_minutes: stayMinutes }, fields: { stay_minutes: stayMinutes },
|
||||
send: () => saveAssignmentStay(tripId, assignment.id, { stay_minutes: stayMinutes }),
|
||||
})
|
||||
mutationQueue.sendSoon()
|
||||
return updated
|
||||
},
|
||||
|
||||
/** Takes a stop out of the day's route or puts it back (#2532), offline too. */
|
||||
async setRouteExcluded(tripId: number | string, assignment: Assignment, excluded: boolean): Promise<Assignment> {
|
||||
if (!(await mutationQueue.mustQueue('assignments', assignment.id))) {
|
||||
const saved = assignmentSchema.parse((await assignmentsApi.setRouteExcluded(tripId, assignment.id, excluded)).assignment)
|
||||
await cacheAssignment(saved)
|
||||
return saved
|
||||
}
|
||||
const updated = { ...assignment, route_excluded: excluded }
|
||||
await offlineDb.transaction('rw', offlineDb.days, offlineDb.mutationQueue, async () => {
|
||||
await mutationQueue.enqueue({
|
||||
id: generateUUID(), tripId: Number(tripId), method: 'PUT',
|
||||
url: `/trips/${tripId}/assignments/${assignment.id}/route`,
|
||||
body: { excluded }, resource: 'assignments', entityId: assignment.id,
|
||||
})
|
||||
await cacheAssignment(updated)
|
||||
return await writeVisitField(tripId, assignment, {
|
||||
suffix: 'route', body: { excluded }, fields: { route_excluded: excluded },
|
||||
send: async () => assignmentSchema.parse((await assignmentsApi.setRouteExcluded(tripId, assignment.id, excluded)).assignment),
|
||||
})
|
||||
mutationQueue.sendSoon()
|
||||
return updated
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,8 @@ type GetState = StoreApi<TripStoreState>['getState']
|
||||
|
||||
export interface AssignmentsSlice {
|
||||
setAssignmentEndDay: (tripId: number | string, dayId: number, assignmentId: number, endDay: boolean) => Promise<void>
|
||||
/** The stay of one visit (#3092); null reads the place's duration_minutes again. */
|
||||
setAssignmentStay: (tripId: number | string, dayId: number, assignmentId: number, stayMinutes: number | null) => Promise<void>
|
||||
setAssignmentRouteExcluded: (tripId: number | string, dayId: number, assignmentId: number, excluded: boolean) => Promise<void>
|
||||
setAssignmentTimes: (tripId: number | string, dayId: number, assignmentId: number, times: AssignmentTimes) => Promise<void>
|
||||
setAssignmentNotes: (tripId: number | string, dayId: number, assignmentId: number, notes: string | null) => Promise<void>
|
||||
@@ -25,6 +27,38 @@ export interface AssignmentsSlice {
|
||||
setAssignments: (assignments: AssignmentsMap) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* One field of a saved visit on its day, written optimistically: shown at once, settled
|
||||
* on what the save answers, and put back when the save is refused. `read` is how the
|
||||
* field is read off a row, so an absent value settles the same way every time.
|
||||
*/
|
||||
async function writeVisitField<K extends keyof Assignment>(
|
||||
set: SetState,
|
||||
get: GetState,
|
||||
{ dayId, assignmentId, field, value, read, save }: {
|
||||
dayId: number
|
||||
assignmentId: number
|
||||
field: K
|
||||
value: Assignment[K]
|
||||
read: (a: Assignment) => Assignment[K]
|
||||
save: (assignment: Assignment) => Promise<Assignment>
|
||||
},
|
||||
): Promise<void> {
|
||||
const key = String(dayId)
|
||||
const assignment = get().assignments[key]?.find(a => a.id === assignmentId)
|
||||
if (!assignment || assignmentId < 0) return
|
||||
const apply = (next: Assignment[K]) => set(state => ({
|
||||
assignments: { ...state.assignments, [key]: (state.assignments[key] || []).map(a => a.id === assignmentId ? { ...a, [field]: next } : a) },
|
||||
}))
|
||||
apply(value)
|
||||
try {
|
||||
apply(read(await save(assignment)))
|
||||
} catch (err: unknown) {
|
||||
apply(read(assignment))
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
export const createAssignmentsSlice = (set: SetState, get: GetState): AssignmentsSlice => ({
|
||||
setAssignmentEndDay: async (tripId, dayId, assignmentId, endDay) => {
|
||||
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
|
||||
@@ -43,21 +77,14 @@ export const createAssignmentsSlice = (set: SetState, get: GetState): Assignment
|
||||
throw err
|
||||
}
|
||||
},
|
||||
setAssignmentRouteExcluded: async (tripId, dayId, assignmentId, excluded) => {
|
||||
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
|
||||
if (!assignment || assignmentId < 0) return
|
||||
const apply = (value: boolean) => set(state => ({
|
||||
assignments: { ...state.assignments, [String(dayId)]: (state.assignments[String(dayId)] || []).map(a => a.id === assignmentId ? { ...a, route_excluded: value } : a) },
|
||||
}))
|
||||
apply(excluded)
|
||||
try {
|
||||
const saved = await assignmentRepo.setRouteExcluded(tripId, assignment, excluded)
|
||||
apply(saved.route_excluded === true)
|
||||
} catch (err: unknown) {
|
||||
apply(assignment.route_excluded === true)
|
||||
throw err
|
||||
}
|
||||
},
|
||||
setAssignmentStay: (tripId, dayId, assignmentId, stayMinutes) => writeVisitField(set, get, {
|
||||
dayId, assignmentId, field: 'stay_minutes', value: stayMinutes, read: a => a.stay_minutes ?? null,
|
||||
save: assignment => assignmentRepo.setStay(tripId, assignment, stayMinutes),
|
||||
}),
|
||||
setAssignmentRouteExcluded: (tripId, dayId, assignmentId, excluded) => writeVisitField(set, get, {
|
||||
dayId, assignmentId, field: 'route_excluded', value: excluded, read: a => a.route_excluded === true,
|
||||
save: assignment => assignmentRepo.setRouteExcluded(tripId, assignment, excluded),
|
||||
}),
|
||||
setAssignmentTimes: async (tripId, dayId, assignmentId, times) => {
|
||||
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
|
||||
if (!assignment || assignmentId < 0) return
|
||||
|
||||
@@ -156,11 +156,11 @@ describe('MRtStaySheet', () => {
|
||||
expect(screen.queryByText('Leave')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-012: saving writes the place and the minutes, then hands back to the stop', async () => {
|
||||
it('FE-MOB-RTSTAY-012: saving writes the minutes on the visit it was opened on, then hands back to the stop', async () => {
|
||||
const { planner, shell } = renderSheet()
|
||||
fireEvent.click(plus())
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 35))
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 35, 102))
|
||||
// Addressed by day and assignment, which is how 'rtstop' locates a row. Spreading this
|
||||
// sheet's own payload left it unable to resolve anything, so it drew nothing while still
|
||||
// counting as open, and the day swipe stayed blocked behind it.
|
||||
@@ -177,7 +177,7 @@ describe('MRtStaySheet', () => {
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 30))
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 30, undefined))
|
||||
expect(shell.closeSheet).toHaveBeenCalled()
|
||||
expect(shell.openSheet).not.toHaveBeenCalledWith('rtstop', expect.anything())
|
||||
})
|
||||
@@ -188,7 +188,7 @@ describe('MRtStaySheet', () => {
|
||||
expect(planner.setRoadtripStay).not.toHaveBeenCalled()
|
||||
expect(value()).toHaveTextContent('0')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 0))
|
||||
await waitFor(() => expect(planner.setRoadtripStay).toHaveBeenCalledWith(202, 0, 102))
|
||||
expect(shell.openSheet).toHaveBeenCalledWith('rtstop', { dayId: 11, assignmentId: 102 })
|
||||
})
|
||||
|
||||
@@ -212,7 +212,7 @@ describe('MRtStaySheet', () => {
|
||||
expect(shell.openSheet).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-016: without place_edit there is nothing to set the stay with', () => {
|
||||
it('FE-MOB-RTSTAY-016: without the edit right there is nothing to set the stay with', () => {
|
||||
renderSheet({ can: vi.fn(() => false) })
|
||||
expect(minus()).toBeDisabled()
|
||||
expect(plus()).toBeDisabled()
|
||||
|
||||
@@ -31,6 +31,7 @@ export class DayAssignments {
|
||||
accommodation_id?: number | null;
|
||||
route_excluded: number & Opt = 0;
|
||||
tour_stage_key?: string | null;
|
||||
stay_minutes?: number | null;
|
||||
assignment_participants_collection = new Collection<AssignmentParticipants>(this);
|
||||
file_links_collection = new Collection<FileLinks>(this);
|
||||
reservations_collection = new Collection<Reservations>(this);
|
||||
@@ -70,6 +71,7 @@ export const DayAssignmentsSchema = defineEntity({
|
||||
accommodation_id: p.integer().nullable().index('idx_day_assignments_accommodation_id'),
|
||||
route_excluded: p.integer().default(0),
|
||||
tour_stage_key: p.text().nullable(),
|
||||
stay_minutes: p.integer().nullable(),
|
||||
assignment_participants_collection: () => p.oneToMany(AssignmentParticipants).mappedBy('assignment').hidden(),
|
||||
file_links_collection: () => p.oneToMany(FileLinks).mappedBy('assignment').hidden(),
|
||||
reservations_collection: () => p.oneToMany(Reservations).mappedBy('assignment').hidden(),
|
||||
|
||||
@@ -20,4 +20,5 @@ export interface DayAssignmentsTable {
|
||||
accommodation_id: InsertOptional<number | null>;
|
||||
route_excluded: InsertOptional<number>;
|
||||
tour_stage_key: InsertOptional<string | null>;
|
||||
stay_minutes: InsertOptional<number | null>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { addColumnIfMissing } from '../migration-utils';
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* #3092: how long the drive stands at a stop belongs to the visit, not to the
|
||||
* place. A place planned twice on one road trip day (once to stop, once only to
|
||||
* steer the route past it) could not be given two different stays, because the
|
||||
* only value was `places.duration_minutes`.
|
||||
*
|
||||
* `stay_minutes` is the visit's own length. It stays null on every existing row,
|
||||
* and a null visit keeps reading the place's `duration_minutes`, so a trip
|
||||
* planned before this step drives exactly as it did.
|
||||
*/
|
||||
export class Migration20200101046420_a_visit_keeps_its_own_stay extends Migration {
|
||||
override name = 'Migration20200101046420_a_visit_keeps_its_own_stay';
|
||||
|
||||
override async up(): Promise<void> {
|
||||
await addColumnIfMissing(this, 'day_assignments', 'stay_minutes', 'stay_minutes INTEGER');
|
||||
}
|
||||
}
|
||||
@@ -266,6 +266,8 @@ export class DayAssignmentsRepository extends TrekRepository<DayAssignments> {
|
||||
accommodation_id: number | null;
|
||||
/** MDT-02: one stage of a multi-day tour, by its starting stop's key; absent for the whole tour or a place. */
|
||||
tour_stage_key?: string | null;
|
||||
/** #3092: the visit's own stay; absent or null reads the place's. */
|
||||
stay_minutes?: number | null;
|
||||
}): Promise<number> {
|
||||
return await this.insert({
|
||||
day: input.day_id,
|
||||
@@ -274,6 +276,7 @@ export class DayAssignmentsRepository extends TrekRepository<DayAssignments> {
|
||||
notes: input.notes,
|
||||
accommodation_id: input.accommodation_id,
|
||||
tour_stage_key: input.tour_stage_key ?? null,
|
||||
stay_minutes: input.stay_minutes ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,6 +427,14 @@ export class DayAssignmentsRepository extends TrekRepository<DayAssignments> {
|
||||
await this.nativeUpdate({ id }, { end_day });
|
||||
}
|
||||
|
||||
/**
|
||||
* `UPDATE day_assignments SET stay_minutes = ? WHERE id = ?` (#3092). Null hands the
|
||||
* visit back to the stay its place carries.
|
||||
*/
|
||||
async setStayMinutes(id: number, stay_minutes: number | null): Promise<void> {
|
||||
await this.nativeUpdate({ id }, { stay_minutes });
|
||||
}
|
||||
|
||||
/** AS25 — `UPDATE day_assignments SET notes = ? WHERE id = ?`. */
|
||||
async setNotes(id: number, notes: string | null): Promise<void> {
|
||||
await this.nativeUpdate({ id }, { notes });
|
||||
@@ -542,6 +553,8 @@ export class DayAssignmentsRepository extends TrekRepository<DayAssignments> {
|
||||
end_day: number;
|
||||
/** MDT-02: the copied tour keeps its stops' keys, so a day holding one of its stages keeps holding it. */
|
||||
tour_stage_key?: string | null;
|
||||
/** #3092: the visit's own stay goes with it. */
|
||||
stay_minutes?: number | null;
|
||||
}): Promise<number> {
|
||||
return await this.insert({
|
||||
day: input.day_id,
|
||||
@@ -637,7 +650,9 @@ export class DayAssignmentsRepository extends TrekRepository<DayAssignments> {
|
||||
'p.lng as lng',
|
||||
eb.fn.coalesce('a.assignment_time', 'p.place_time').as('time'),
|
||||
eb.fn.coalesce('a.assignment_end_time', 'p.end_time').as('end_time'),
|
||||
'p.duration_minutes as duration_minutes',
|
||||
// A visit's own stay before the place's (#3092): the same place planned twice
|
||||
// on a day can be stood at for two different lengths.
|
||||
eb.fn.coalesce('a.stay_minutes', 'p.duration_minutes').as('duration_minutes'),
|
||||
'a.end_day as end_day',
|
||||
'a.leg_transport_mode as leg_transport_mode',
|
||||
'a.incoming_leg_transport_mode as incoming_leg_transport_mode',
|
||||
|
||||
@@ -149,8 +149,8 @@ type CalendarReservationKyselyDB = Pick<DB, 'reservations' | 'places' | 'day_acc
|
||||
/**
|
||||
* CL4 (`CalendarService.buildTripCalendar`'s assignment read, for every dated
|
||||
* day at once) — `SELECT da.*, p.name as place_name, p.address as
|
||||
* place_address, p.lat as place_lat, p.lng as place_lng, p.duration_minutes
|
||||
* as place_duration_minutes, COALESCE(da.assignment_time, p.place_time) as
|
||||
* place_address, p.lat as place_lat, p.lng as place_lng, COALESCE(da.stay_minutes,
|
||||
* p.duration_minutes) as place_duration_minutes, COALESCE(da.assignment_time, p.place_time) as
|
||||
* effective_time, COALESCE(da.assignment_end_time, p.end_time) as
|
||||
* effective_end_time FROM
|
||||
* day_assignments da JOIN places p ON da.place_id = p.id WHERE da.day_id IN
|
||||
@@ -917,7 +917,7 @@ export class ReservationsRepository extends TrekRepository<Reservations> {
|
||||
'p.address as place_address',
|
||||
'p.lat as place_lat',
|
||||
'p.lng as place_lng',
|
||||
'p.duration_minutes as place_duration_minutes',
|
||||
eb.fn.coalesce('da.stay_minutes', 'p.duration_minutes').as('place_duration_minutes'),
|
||||
eb.fn.coalesce('da.assignment_time', 'p.place_time').as('effective_time'),
|
||||
eb.fn.coalesce('da.assignment_end_time', 'p.end_time').as('effective_end_time'),
|
||||
])
|
||||
|
||||
@@ -115,6 +115,8 @@ export interface DayAssignmentRow {
|
||||
route_excluded: number;
|
||||
/** MDT-02: the stage of a multi-day tour the day holds, by its starting stop's key; null for anything else. */
|
||||
tour_stage_key: string | null;
|
||||
/** #3092: how long the drive stands at this visit; null reads the place's `duration_minutes`. */
|
||||
stay_minutes: number | null;
|
||||
}
|
||||
|
||||
const _dayAssignmentRowKeys: AssertRowKeys<DayAssignmentRow, DayAssignments> = true;
|
||||
@@ -172,6 +174,7 @@ export interface RoadtripVisitRow {
|
||||
lng: number | null;
|
||||
time: string | null;
|
||||
end_time: string | null;
|
||||
/** The visit's own stay where it has one (#3092), else the place's. */
|
||||
duration_minutes: number | null;
|
||||
end_day: number;
|
||||
leg_transport_mode: string | null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { User } from '../../types';
|
||||
import { CurrentUser } from '../auth-core/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { ResponseContract } from '../common/response-contract';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import {
|
||||
AssignmentCreateDto,
|
||||
@@ -8,6 +9,7 @@ import {
|
||||
AssignmentMoveDto,
|
||||
AssignmentTimeDto,
|
||||
AssignmentEndDayDto,
|
||||
AssignmentStayDto,
|
||||
AssignmentNotesDto,
|
||||
AssignmentTransportDto,
|
||||
AssignmentRouteDto,
|
||||
@@ -15,6 +17,7 @@ import {
|
||||
} from './assignments.dto';
|
||||
import { AssignmentsService } from './assignments.service';
|
||||
import { Body, Controller, Delete, Get, Headers, HttpException, Param, Post, Put, UseGuards } from '@nestjs/common';
|
||||
import { assignmentResponseSchema } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* /api/trips/:tripId/days/:dayId/assignments — the day's ordered itinerary items.
|
||||
@@ -221,6 +224,25 @@ export class AssignmentOpsController {
|
||||
return { assignment };
|
||||
}
|
||||
|
||||
// #3092: the stay of one visit, so two visits of a place can last differently.
|
||||
// Same guard shape and 404 body as end-day; no reconcile, the stay touches
|
||||
// neither the day's order nor the journey skeleton.
|
||||
@RequirePermission('day_edit')
|
||||
@Put(':id/stay')
|
||||
@ResponseContract(assignmentResponseSchema)
|
||||
async stay(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() body: AssignmentStayDto,
|
||||
@Headers('x-socket-id') socketId?: string,
|
||||
) {
|
||||
const visit = await this.assignments.getAssignmentForTrip(id, tripId);
|
||||
if (!visit) throw new HttpException({ error: 'Assignment not found' }, 404);
|
||||
const assignment = await this.assignments.setStay(visit.id, body.stay_minutes);
|
||||
this.assignments.broadcast(tripId, 'assignment:updated', { assignment }, socketId);
|
||||
return { assignment };
|
||||
}
|
||||
|
||||
// #2163: the per-assignment note was write-once (create bodies, MCP, plugin
|
||||
// RPC) with no edit path anywhere. Same guard shape and 404 body as its
|
||||
// neighbours; no reconcile — the note doesn't touch the journey skeleton.
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
assignmentMoveRequestSchema,
|
||||
assignmentTimeRequestSchema,
|
||||
assignmentEndDayRequestSchema,
|
||||
assignmentStayRequestSchema,
|
||||
assignmentNotesRequestSchema,
|
||||
assignmentTransportRequestSchema,
|
||||
assignmentRouteRequestSchema,
|
||||
@@ -24,6 +25,7 @@ export class AssignmentReorderDto extends createZodDto(assignmentReorderRequestS
|
||||
export class AssignmentMoveDto extends createZodDto(assignmentMoveRequestSchema) {}
|
||||
export class AssignmentTimeDto extends createZodDto(assignmentTimeRequestSchema) {}
|
||||
export class AssignmentEndDayDto extends createZodDto(assignmentEndDayRequestSchema) {}
|
||||
export class AssignmentStayDto extends createZodDto(assignmentStayRequestSchema) {}
|
||||
export class AssignmentNotesDto extends createZodDto(assignmentNotesRequestSchema) {}
|
||||
export class AssignmentTransportDto extends createZodDto(assignmentTransportRequestSchema) {}
|
||||
export class AssignmentRouteDto extends createZodDto(assignmentRouteRequestSchema) {}
|
||||
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
idSchema,
|
||||
assignmentCreateRequestSchema,
|
||||
assignmentEndDayRequestSchema,
|
||||
assignmentStayRequestSchema,
|
||||
type AssignmentEndDayRequest,
|
||||
type AssignmentStayRequest,
|
||||
} from '@trek/shared';
|
||||
|
||||
import { z } from 'zod';
|
||||
@@ -102,6 +104,31 @@ export class AssignmentsMcp {
|
||||
return ok({ assignment });
|
||||
}
|
||||
|
||||
@Tool({
|
||||
name: 'set_assignment_stay',
|
||||
description:
|
||||
'Set how long the road trip stands at this one visit, in minutes. Two visits of the same place keep their own stays: 0 drives past without stopping. Pass null to use the stay of the place (its duration_minutes) again.',
|
||||
inputSchema: {
|
||||
tripId: idSchema,
|
||||
assignmentId: idSchema,
|
||||
...assignmentStayRequestSchema.shape,
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'places', mode: 'write' },
|
||||
})
|
||||
async setAssignmentStay(
|
||||
{ tripId, assignmentId, stay_minutes }: AssignmentStayRequest & { tripId: number; assignmentId: number },
|
||||
ctx: McpContext,
|
||||
) {
|
||||
if (!(await this.assignments.verifyTripAccess(tripId, ctx.userId))) return noAccess();
|
||||
if (!(await this.guards.hasTripPermission('day_edit', tripId, ctx.userId))) return permissionDenied();
|
||||
if (!(await this.assignments.getAssignmentForTrip(assignmentId, tripId)))
|
||||
return errorResult('Assignment not found.');
|
||||
const assignment = await this.assignments.setStay(assignmentId, stay_minutes);
|
||||
this.guards.safeBroadcast(tripId, 'assignment:updated', { assignment });
|
||||
return ok({ assignment });
|
||||
}
|
||||
|
||||
@Tool({
|
||||
name: 'unassign_place',
|
||||
description: 'Remove a place assignment from a day.',
|
||||
|
||||
@@ -566,6 +566,18 @@ export class AssignmentsService {
|
||||
return await this.getAssignmentWithPlace(idNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* How long the drive stands at one visit (#3092). The stay used to be the place's
|
||||
* alone, so the same place planned twice on a day could not be stopped at once and
|
||||
* only driven past the other time. Null hands the visit back to the place's own
|
||||
* `duration_minutes`. No auto-sort and no journey reconcile: a stay moves neither
|
||||
* the day's order nor the skeleton mirror.
|
||||
*/
|
||||
async setStay(id: number, stayMinutes: number | null) {
|
||||
await this.dayAssignmentsRepo.setStayMinutes(id, stayMinutes);
|
||||
return await this.getAssignmentWithPlace(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the per-assignment note after creation (#2163) — until now the note
|
||||
* was write-once via the create paths (REST body, MCP tools, plugin RPC) and
|
||||
|
||||
@@ -38,6 +38,8 @@ export function formatAssignmentWithPlace(
|
||||
assignment_time: a.assignment_time ?? null,
|
||||
assignment_end_time: a.assignment_end_time ?? null,
|
||||
end_day: a.end_day === 1,
|
||||
// How long the drive stands at this visit (#3092); null reads the place's duration_minutes.
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
leg_transport_mode: a.leg_transport_mode ?? null,
|
||||
incoming_leg_transport_mode: a.incoming_leg_transport_mode ?? null,
|
||||
// Kept on the day but not driven to (#2532).
|
||||
|
||||
@@ -198,6 +198,7 @@ export class DaysService {
|
||||
day_id: a.day_id,
|
||||
order_index: a.order_index,
|
||||
end_day: a.end_day === 1,
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
route_excluded: a.route_excluded === 1,
|
||||
notes: a.notes,
|
||||
// Repeated here for the same reason stop_type is: the day list hides the stop
|
||||
|
||||
@@ -753,6 +753,7 @@ export class TripsService {
|
||||
reservation_status: a.reservation_status, reservation_notes: a.reservation_notes,
|
||||
reservation_datetime: a.reservation_datetime, assignment_time: a.assignment_time,
|
||||
assignment_end_time: a.assignment_end_time, end_day: a.end_day ?? 0, tour_stage_key: a.tour_stage_key,
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
});
|
||||
assignmentMap.set(a.id, newAssignmentId);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,42 @@ describe('Create assignment', () => {
|
||||
await request(app).put(url).send({ end_day: true }).expect(401);
|
||||
});
|
||||
|
||||
it('ASSIGN-STAY: two visits of one place keep their own stay, the other falls back to the place (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { trip, day, place } = setupAssignmentFixtures(user.id);
|
||||
await updateRows(orm, Places, { id: place.id }, { duration_minutes: 60 });
|
||||
const cookie = authCookie(user.id);
|
||||
const plan = `/api/trips/${trip.id}/days/${day.id}/assignments`;
|
||||
const first = (await request(app).post(plan).set('Cookie', cookie).send({ place_id: place.id }).expect(201)).body
|
||||
.assignment;
|
||||
const second = (await request(app).post(plan).set('Cookie', cookie).send({ place_id: place.id }).expect(201)).body
|
||||
.assignment;
|
||||
expect(first.stay_minutes).toBeNull();
|
||||
|
||||
const url = `/api/trips/${trip.id}/assignments/${second.id}/stay`;
|
||||
const changed = await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: 0 }).expect(200);
|
||||
expect(changed.body.assignment).toMatchObject({ id: second.id, stay_minutes: 0 });
|
||||
|
||||
// The other visit and the place itself are untouched.
|
||||
const listed = await request(app).get(`/api/trips/${trip.id}/days`).set('Cookie', cookie).expect(200);
|
||||
const visits = listed.body.days[0].assignments as Array<{ id: number; stay_minutes: number | null }>;
|
||||
expect(visits.find((a) => a.id === first.id)?.stay_minutes).toBeNull();
|
||||
expect(visits.find((a) => a.id === second.id)?.stay_minutes).toBe(0);
|
||||
expect((await findRows(orm, Places, { id: place.id }))[0]?.duration_minutes).toBe(60);
|
||||
|
||||
await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: -5 }).expect(400);
|
||||
await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: 1.5 }).expect(400);
|
||||
const foreign = createTrip(testDb, user.id);
|
||||
await request(app)
|
||||
.put(`/api/trips/${foreign.id}/assignments/${second.id}/stay`)
|
||||
.set('Cookie', cookie)
|
||||
.send({ stay_minutes: 10 })
|
||||
.expect(404);
|
||||
const reset = await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: null }).expect(200);
|
||||
expect(reset.body.assignment.stay_minutes).toBeNull();
|
||||
await request(app).put(url).send({ stay_minutes: 10 }).expect(401);
|
||||
});
|
||||
|
||||
it('ASSIGN-001 — POST creates assignment linking place to day', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { trip, day, place } = setupAssignmentFixtures(user.id);
|
||||
|
||||
@@ -227,6 +227,13 @@ export const plan: CaseGroup = {
|
||||
rest: { method: 'put', path: (s) => `${assignmentPath(s)}/end-day`, body: () => ({ end_day: true }) },
|
||||
expect: ['assignment:updated'],
|
||||
},
|
||||
{
|
||||
tool: 'set_assignment_stay',
|
||||
needs: ['assignment'],
|
||||
args: (s) => ({ ...onAssignment(s), stay_minutes: 15 }),
|
||||
rest: { method: 'put', path: (s) => `${assignmentPath(s)}/stay`, body: () => ({ stay_minutes: 15 }) },
|
||||
expect: ['assignment:updated'],
|
||||
},
|
||||
{
|
||||
tool: 'unassign_place',
|
||||
needs: ['assignment'],
|
||||
|
||||
@@ -109,6 +109,7 @@ const UNNUMBERED = [
|
||||
'Migration20200101046390_a_trip_can_keep_its_costs_as_totals_only',
|
||||
'Migration20200101046400_a_booked_flight_shows_where_it_is',
|
||||
'Migration20200101046410_a_forwarded_booking_mail_lands_in_its_trip',
|
||||
'Migration20200101046420_a_visit_keeps_its_own_stay',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -1078,7 +1078,7 @@ const LEGACY_LIST_ROADTRIP_VISITS = `
|
||||
SELECT a.id, a.day_id, a.order_index, a.place_id, p.name, p.lat, p.lng,
|
||||
COALESCE(a.assignment_time, p.place_time) AS time,
|
||||
COALESCE(a.assignment_end_time, p.end_time) AS end_time,
|
||||
p.duration_minutes, a.end_day,
|
||||
COALESCE(a.stay_minutes, p.duration_minutes) AS duration_minutes, a.end_day,
|
||||
a.leg_transport_mode, a.incoming_leg_transport_mode, p.stop_type, p.fill_percent,
|
||||
a.accommodation_id, stay.id AS stay_id, stay.check_in, stay.check_out, checkout.day_number AS checkout_day
|
||||
FROM day_assignments a
|
||||
@@ -1170,6 +1170,26 @@ describe('DayAssignmentsRepository.listRoadtripVisits (RPL2, roadtrip-plan.servi
|
||||
});
|
||||
});
|
||||
|
||||
it('ASSIGNREPO-036: two visits of one place keep their own stay, an unset one reads the place (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
const place = createPlace(testDb, trip.id, { name: 'Viewpoint' });
|
||||
await updateRows(t, Places, { id: place.id }, { duration_minutes: 45 });
|
||||
const stopped = createDayAssignment(testDb, day.id, place.id, { order_index: 0 });
|
||||
const passed = createDayAssignment(testDb, day.id, place.id, { order_index: 1 });
|
||||
|
||||
await withRequestContext(t.orm, () => assignments.setStayMinutes(passed.id, 0));
|
||||
|
||||
const visits = await assignments.listRoadtripVisits(trip.id);
|
||||
expect(visits.map((v) => [v.id, v.duration_minutes])).toEqual([
|
||||
[stopped.id, 45],
|
||||
[passed.id, 0],
|
||||
]);
|
||||
expect(await assignmentCols(stopped.id, 'stay_minutes')).toEqual({ stay_minutes: null });
|
||||
expect((await findRow(t, Places, { id: place.id }))?.duration_minutes).toBe(45);
|
||||
});
|
||||
|
||||
it('ASSIGNREPO-033: empty array for a trip with no assignments', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
|
||||
@@ -110,7 +110,31 @@ describe('Tool: assign_place_to_day', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('MDT-MCP-001: puts one stage of a multi-day tour on a day, refusing as REST does', async () => {
|
||||
it('set_assignment_stay: changes the stay of one visit and leaves the other visit of the place alone (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
const place = createPlace(testDb, trip.id);
|
||||
const first = createDayAssignment(testDb, day.id, place.id);
|
||||
const second = createDayAssignment(testDb, day.id, place.id);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const changed = await h.client.callTool({
|
||||
name: 'set_assignment_stay',
|
||||
arguments: { tripId: trip.id, assignmentId: second.id, stay_minutes: 5 },
|
||||
});
|
||||
expect(parseToolResult(changed)).toMatchObject({ assignment: { id: second.id, stay_minutes: 5 } });
|
||||
const other = createTrip(testDb, user.id);
|
||||
const refused = await h.client.callTool({
|
||||
name: 'set_assignment_stay',
|
||||
arguments: { tripId: other.id, assignmentId: second.id, stay_minutes: 5 },
|
||||
});
|
||||
expect(refused.isError).toBe(true);
|
||||
});
|
||||
const rows = await findRows(orm, DayAssignments, { id: { $in: [first.id, second.id] } }, { id: 'asc' });
|
||||
expect(rows.map((r) => r.stay_minutes)).toEqual([null, 5]);
|
||||
});
|
||||
|
||||
it('MDT-MCP-001:puts one stage of a multi-day tour on a day, refusing as REST does', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
|
||||
@@ -57,6 +57,7 @@ function makeRow(overrides: Partial<AssignmentWithPlaceRow> = {}): AssignmentWit
|
||||
tour_place_id: null,
|
||||
tour_route_geometry: null,
|
||||
tour_stage_key: null,
|
||||
stay_minutes: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
assignmentMoveRequestSchema,
|
||||
assignmentParticipantsRequestSchema,
|
||||
assignmentSchema,
|
||||
assignmentStayRequestSchema,
|
||||
assignmentTransportRequestSchema,
|
||||
} from './assignment.schema';
|
||||
|
||||
@@ -52,6 +53,15 @@ it('requires a boolean for an explicit day end', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('takes the stay of one visit as whole minutes up to a week, or null for the place stay (#3092)', () => {
|
||||
for (const stay_minutes of [0, 45, 10_080, null]) {
|
||||
expect(assignmentStayRequestSchema.parse({ stay_minutes })).toEqual({ stay_minutes });
|
||||
}
|
||||
for (const stay_minutes of [-1, 1.5, 10_081, '30', undefined]) {
|
||||
expect(assignmentStayRequestSchema.safeParse({ stay_minutes }).success).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
describe('assignmentCreateRequestSchema', () => {
|
||||
it('requires a place_id; notes optional/nullable', () => {
|
||||
expect(assignmentCreateRequestSchema.safeParse({ place_id: 2 }).success).toBe(true);
|
||||
|
||||
@@ -42,6 +42,10 @@ export const assignmentSchema = z.object({
|
||||
assignment_time: z.string().nullable().optional(),
|
||||
assignment_end_time: z.string().nullable().optional(),
|
||||
end_day: z.boolean().optional(),
|
||||
// How long the drive stands at this visit, in minutes (#3092). Null, or absent on an
|
||||
// older server, reads the place's own duration_minutes, so a place planned twice can
|
||||
// be stopped at on one visit and only driven past on the other.
|
||||
stay_minutes: z.number().nullable().optional(),
|
||||
// Per-segment travel mode (#1281): the transport mode of the leg LEAVING this
|
||||
// stop for the next one. null = inherit the day's default_transport_mode.
|
||||
leg_transport_mode: z.string().nullable().optional(),
|
||||
@@ -105,6 +109,23 @@ export const assignmentEndDayRequestSchema = z.object({
|
||||
});
|
||||
export type AssignmentEndDayRequest = z.infer<typeof assignmentEndDayRequestSchema>;
|
||||
|
||||
/**
|
||||
* PUT /:id/stay (#3092) — how long the drive stands at this one visit, in whole
|
||||
* minutes, a week at most like the road trip's own stay bounds. Zero is a visit
|
||||
* driven past without stopping; null hands the visit back to the stay its place
|
||||
* carries (`places.duration_minutes`).
|
||||
*/
|
||||
export const assignmentStayRequestSchema = z.object({
|
||||
stay_minutes: z.number().int().min(0).max(10_080).nullable(),
|
||||
});
|
||||
export type AssignmentStayRequest = z.infer<typeof assignmentStayRequestSchema>;
|
||||
|
||||
/** What a write to one assignment answers with: the assignment as the day list reads it. */
|
||||
export const assignmentResponseSchema = z.object({
|
||||
assignment: assignmentSchema,
|
||||
});
|
||||
export type AssignmentResponse = z.infer<typeof assignmentResponseSchema>;
|
||||
|
||||
/**
|
||||
* PUT /:id/notes (#2163) — edit the per-assignment note after creation.
|
||||
* Deliberately uncapped like the create contract above: the REST create body
|
||||
|
||||
@@ -390,7 +390,7 @@ Corridor results include source attribution, distance along/from the route, fail
|
||||
|
||||
Corridor searches include installed search-provider plugins. Providers receive the category and search bounds, and the host filters hits to the route. The response lists successful and failed sources; a failed provider does not discard the remaining results.
|
||||
|
||||
The via tools manage scenic detours and followed tracks. `list_day_boundaries`, `set_day_boundary` and `set_assignment_end_day` manage manual endings; `set_assignment_end_day` is a general assignment tool and is registered whether or not the addon is on. With `roadtrip_hotel_bookends` on, a boundary between two stops that a booked night separates is ignored, because the night ends the day. The Places tool `import_trip_gpx` accepts GPX XML up to one million characters, uses the standard importer and requires places:write. It imports waypoints, routes and tracks without assigning them to days; `export_trip_gpx` exports the trip. Stay durations and place-level time defaults can be cleared with null through `update_place`.
|
||||
The via tools manage scenic detours and followed tracks. `list_day_boundaries`, `set_day_boundary` and `set_assignment_end_day` manage manual endings; `set_assignment_end_day` is a general assignment tool and is registered whether or not the addon is on. With `roadtrip_hotel_bookends` on, a boundary between two stops that a booked night separates is ignored, because the night ends the day. The Places tool `import_trip_gpx` accepts GPX XML up to one million characters, uses the standard importer and requires places:write. It imports waypoints, routes and tracks without assigning them to days; `export_trip_gpx` exports the trip. Stay durations and place-level time defaults can be cleared with null through `update_place`. `set_assignment_stay` gives one visit its own stay, so a place planned twice can be stopped at once and only driven past the other time; null hands the visit back to the place's duration.
|
||||
|
||||
`get_roadtrip_hazards` takes `tripId`. It does not reroute the trip. The shared `roadtrip_show_hazards` setting controls the online map overlay.
|
||||
|
||||
|
||||
+2
-2
@@ -91,7 +91,7 @@ Every stop has a **Stay** badge. Click it to open **Time at this stop**:
|
||||
- Below it, **Arrive** and **Leave** show what the stay does to the day while you change it.
|
||||
- **No stay** clears it.
|
||||
|
||||
**The stay belongs to the place, not to one visit.** A place planned on two days has the same stay on both.
|
||||
**The stay belongs to the visit.** A place planned twice, say once to stop and once only to lead the route past it, keeps a stay for each visit: changing one leaves the other alone. A visit you never gave a stay takes the place's own, so trips planned before this keep the stays they had.
|
||||
|
||||
A stay may run past midnight. The clock carries into the next morning together with the drive from there, and the next stop moves to the card of the day it is actually reached on. With daily travel times set, the hours between one day's end time and the next day's start time count towards the stay, so a twelve hour night that begins at 20:00 is over at 08:00 the next morning.
|
||||
|
||||
@@ -106,7 +106,7 @@ A visit's **End** is the time the drive leaves it. Set it in the place form, whe
|
||||
- If the daily travel times close the day before the End comes, the stop is where that day ends: *The travel day ends before 14:00, so the drive goes on the next morning.*
|
||||
- Clicking the **Stay** badge of such a stop opens the End instead of the slider, with **Remove end time**. After that the stay is yours to choose again. The button is missing when you may not edit the stop, and when the End is stored on the place itself and another visit of the same place relies on it: removing it there would change that visit too.
|
||||
|
||||
The End belongs to one visit; the stay belongs to the place. Older trips can carry an End on the place, which then applies to its visits that have none of their own.
|
||||
The End and the stay both belong to one visit. Older trips can carry an End or a stay on the place, which then applies to its visits that have none of their own.
|
||||
|
||||
## Pinned times and the schedule
|
||||
|
||||
|
||||
Reference in New Issue
Block a user