mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
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:
@@ -1,4 +1,4 @@
|
||||
// FE-API-COLLECTIONS-001 to FE-API-COLLECTIONS-035
|
||||
// FE-API-COLLECTIONS-001 to FE-API-COLLECTIONS-038
|
||||
//
|
||||
// The Collections addon wrapper is thin, but every method encodes a URL, a verb and a
|
||||
// request-body shape that the server contract depends on. These tests drive each method
|
||||
@@ -370,4 +370,50 @@ describe('collectionsApi', () => {
|
||||
expect(requestBody).toEqual({ gpx: '<gpx/>', file_name: 'tokyo.gpx' })
|
||||
expect(res).toEqual({ file, skipped: 0, track_points: 12 })
|
||||
})
|
||||
|
||||
it('FE-API-COLLECTIONS-036: copyToTrip() passes the notes and tags a copy takes along (D9)', async () => {
|
||||
server.use(http.post(`${BASE}/copy-to-trip`, record({ copied: 1, skipped: [], created: [] })))
|
||||
|
||||
await collectionsApi.copyToTrip({ trip_id: 7, place_ids: [10], include_notes: true, tag_ids: [4] })
|
||||
|
||||
expect(requestBody).toEqual({ trip_id: 7, place_ids: [10], include_notes: true, tag_ids: [4] })
|
||||
})
|
||||
|
||||
it('FE-API-COLLECTIONS-037: reorderPlaces() puts the ordered ids of a list (PLC-03)', async () => {
|
||||
let method = ''
|
||||
server.use(
|
||||
http.put(`${BASE}/:id/places/reorder`, async (info) => {
|
||||
method = info.request.method
|
||||
return record({ success: true })(info)
|
||||
}),
|
||||
)
|
||||
|
||||
const res = await collectionsApi.reorderPlaces(1, [11, 10])
|
||||
|
||||
expect(method).toBe('PUT')
|
||||
expect(requestUrl).toContain(`${BASE}/1/places/reorder`)
|
||||
expect(requestBody).toEqual({ orderedIds: [11, 10] })
|
||||
expect(res).toEqual({ success: true })
|
||||
})
|
||||
|
||||
it('FE-API-COLLECTIONS-038: readMap() uploads the map file as multipart and returns the list file (PLC-22)', async () => {
|
||||
const read = {
|
||||
file: { format: 'trek.collection', version: 1, name: 'Lisbon', places: [{ name: 'Miradouro' }] },
|
||||
folders: ['Views'],
|
||||
skipped: [{ name: 'Tram 28', folder: null, reason: 'line' }],
|
||||
}
|
||||
let upload: File | null = null
|
||||
server.use(
|
||||
http.post(`${BASE}/map/read`, async ({ request }) => {
|
||||
upload = (await request.formData()).get('file') as File | null
|
||||
return HttpResponse.json(read)
|
||||
}),
|
||||
)
|
||||
|
||||
const res = await collectionsApi.readMap(new File(['<kml/>'], 'lisbon.kml'))
|
||||
|
||||
expect(upload).not.toBeNull()
|
||||
expect((upload as unknown as File).name).toBe('lisbon.kml')
|
||||
expect(res).toEqual(read)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,6 +18,8 @@ import type {
|
||||
CollectionGpxReadRequest,
|
||||
CollectionGpxReadResult,
|
||||
CollectionKmlExport,
|
||||
CollectionMapReadResult,
|
||||
CollectionPlacesReorderRequest,
|
||||
CollectionPlaceUpdateRequest,
|
||||
CollectionCopyToTripRequest,
|
||||
CollectionInviteRequest,
|
||||
@@ -76,6 +78,12 @@ export const collectionsApi = {
|
||||
ax.get(`${base}/${id}/export/gpx`).then((r: AxiosResponse) => r.data),
|
||||
readGpx: (body: CollectionGpxReadRequest): Promise<CollectionGpxReadResult> =>
|
||||
ax.post(`${base}/gpx/read`, body satisfies CollectionGpxReadRequest).then((r: AxiosResponse) => r.data),
|
||||
/** A KML or KMZ map (PLC-22) read by the server into a list file; it writes nothing, importFile(Into) does. */
|
||||
readMap: (file: File): Promise<CollectionMapReadResult> => {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
return postMultipart(`${base}/map/read`, fd)
|
||||
},
|
||||
/** The same list as pins for Google My Maps (#1866). */
|
||||
exportKml: (id: number): Promise<CollectionKmlExport> =>
|
||||
ax.get(`${base}/${id}/export/kml`).then((r: AxiosResponse) => r.data),
|
||||
@@ -94,6 +102,10 @@ export const collectionsApi = {
|
||||
reorder: (orderedIds: number[]): Promise<unknown> =>
|
||||
ax.post(`${base}/reorder`, { orderedIds }).then((r: AxiosResponse) => r.data),
|
||||
|
||||
/** A list's places in a new order (PLC-03): every id a place of that list, the ones left out follow. */
|
||||
reorderPlaces: (id: number, orderedIds: number[]): Promise<{ success: true }> =>
|
||||
ax.put(`${base}/${id}/places/reorder`, { orderedIds } satisfies CollectionPlacesReorderRequest).then((r: AxiosResponse) => r.data),
|
||||
|
||||
savePlace: (body: CollectionSavePlaceRequest): Promise<CollectionSaveResult> =>
|
||||
ax.post(`${base}/places`, body satisfies CollectionSavePlaceRequest).then((r: AxiosResponse) => r.data),
|
||||
saveFromTrip: (body: CollectionSaveFromTripRequest): Promise<CollectionSaveResult> =>
|
||||
|
||||
Reference in New Issue
Block a user