mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +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:
@@ -0,0 +1,131 @@
|
||||
// FE-MAP-PLACENAMES-001 to FE-MAP-PLACENAMES-005: the place names beside the trip map's pins (#2796).
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { controlBoxes, layoutPlaceNames, tagPlaceName } from './placeNameLabels';
|
||||
|
||||
type Rect = { left: number; top: number; width: number; height: number };
|
||||
|
||||
/** jsdom lays nothing out, so every element answers the box it was given. */
|
||||
function place(el: Element, r: Rect): void {
|
||||
el.getBoundingClientRect = () =>
|
||||
({ ...r, right: r.left + r.width, bottom: r.top + r.height, x: r.left, y: r.top, toJSON: () => ({}) }) as DOMRect;
|
||||
}
|
||||
|
||||
function mapWith(pins: { name: string; priority: 0 | 1 | 2; at: Rect; label: Rect }[]): HTMLElement {
|
||||
const container = document.createElement('div');
|
||||
place(container, { left: 0, top: 0, width: 800, height: 600 });
|
||||
document.body.appendChild(container);
|
||||
for (const pin of pins) {
|
||||
const el = document.createElement('div');
|
||||
place(el, pin.at);
|
||||
tagPlaceName(el, pin.name, pin.priority);
|
||||
container.appendChild(el);
|
||||
// The label is made on the first layout; it gets its box the moment it is added.
|
||||
const original = el.appendChild.bind(el);
|
||||
el.appendChild = <T extends Node>(node: T): T => {
|
||||
if (node instanceof HTMLElement) place(node, pin.label);
|
||||
return original(node);
|
||||
};
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
const labels = (c: HTMLElement) => Array.from(c.querySelectorAll<HTMLElement>('.trek-place-name'));
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('place names on the map', () => {
|
||||
it('FE-MAP-PLACENAMES-001: every tagged pin gets its name as text, nothing as markup', () => {
|
||||
const c = mapWith([
|
||||
{
|
||||
name: '<b>Senso-ji</b>',
|
||||
priority: 0,
|
||||
at: { left: 10, top: 10, width: 20, height: 20 },
|
||||
label: { left: 36, top: 12, width: 80, height: 16 },
|
||||
},
|
||||
]);
|
||||
layoutPlaceNames(c, true);
|
||||
expect(labels(c)).toHaveLength(1);
|
||||
expect(labels(c)[0].textContent).toBe('<b>Senso-ji</b>');
|
||||
expect(c.querySelector('b')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MAP-PLACENAMES-002: of two colliding names the selected one stays', () => {
|
||||
const c = mapWith([
|
||||
{
|
||||
name: 'Plain',
|
||||
priority: 0,
|
||||
at: { left: 10, top: 10, width: 20, height: 20 },
|
||||
label: { left: 36, top: 12, width: 80, height: 16 },
|
||||
},
|
||||
{
|
||||
name: 'Picked',
|
||||
priority: 2,
|
||||
at: { left: 10, top: 60, width: 20, height: 20 },
|
||||
label: { left: 40, top: 14, width: 80, height: 16 },
|
||||
},
|
||||
]);
|
||||
layoutPlaceNames(c, true);
|
||||
const [plain, picked] = labels(c);
|
||||
expect(picked.hasAttribute('data-hidden')).toBe(false);
|
||||
expect(plain.hasAttribute('data-hidden')).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-MAP-PLACENAMES-003: a name that would cover another pin, a control or run off the map is hidden', () => {
|
||||
const c = mapWith([
|
||||
{
|
||||
name: 'Covers a pin',
|
||||
priority: 0,
|
||||
at: { left: 10, top: 10, width: 20, height: 20 },
|
||||
label: { left: 36, top: 12, width: 80, height: 16 },
|
||||
},
|
||||
{
|
||||
name: 'Neighbour',
|
||||
priority: 0,
|
||||
at: { left: 60, top: 8, width: 20, height: 20 },
|
||||
label: { left: 300, top: 300, width: 40, height: 16 },
|
||||
},
|
||||
{
|
||||
name: 'Edge',
|
||||
priority: 0,
|
||||
at: { left: 760, top: 200, width: 20, height: 20 },
|
||||
label: { left: 786, top: 202, width: 80, height: 16 },
|
||||
},
|
||||
{
|
||||
name: 'Under control',
|
||||
priority: 0,
|
||||
at: { left: 400, top: 500, width: 20, height: 20 },
|
||||
label: { left: 426, top: 502, width: 80, height: 16 },
|
||||
},
|
||||
]);
|
||||
layoutPlaceNames(c, true, [{ left: 450, top: 490, right: 520, bottom: 530 }]);
|
||||
const hidden = labels(c).map((l) => l.hasAttribute('data-hidden'));
|
||||
expect(hidden).toEqual([true, false, true, true]);
|
||||
});
|
||||
|
||||
it('FE-MAP-PLACENAMES-004: switched off, the names go away again', () => {
|
||||
const c = mapWith([
|
||||
{
|
||||
name: 'Senso-ji',
|
||||
priority: 0,
|
||||
at: { left: 10, top: 10, width: 20, height: 20 },
|
||||
label: { left: 36, top: 12, width: 80, height: 16 },
|
||||
},
|
||||
]);
|
||||
layoutPlaceNames(c, true);
|
||||
layoutPlaceNames(c, false);
|
||||
expect(labels(c)).toHaveLength(0);
|
||||
layoutPlaceNames(null, true);
|
||||
});
|
||||
|
||||
it('FE-MAP-PLACENAMES-005: control boxes are read off the elements the selector finds', () => {
|
||||
const c = document.createElement('div');
|
||||
const btn = document.createElement('button');
|
||||
place(btn, { left: 5, top: 6, width: 30, height: 30 });
|
||||
c.appendChild(btn);
|
||||
expect(controlBoxes(c, 'button')).toEqual([{ left: 5, top: 6, right: 35, bottom: 36 }]);
|
||||
expect(controlBoxes(null, 'button')).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user