Add notes to a map #20

Closed
opened 2026-10-14 13:10:02 +00:00 by Syndria98 · 5 comments
Owner

Make that when right clicking a map, a right menu context menu opens, and that lets you add an existing note at the map, like a map pin or marker, so that when you click it it displays on a window the linked note.

Make that when right clicking a map, a right menu context menu opens, and that lets you add an existing note at the map, like a map pin or marker, so that when you click it it displays on a window the linked note.
Syndria98 added the ai-ready label 2026-10-14 13:10:02 +00:00
Agent added the working label 2026-10-14 14:07:53 +00:00
Collaborator

Now I have a clear picture. Let me start with the backend.

Now I have a clear picture. Let me start with the backend.
Collaborator

Now the frontend pure helpers service:

Now the frontend pure helpers service:
Collaborator

Now the cycle guard improvement, then tests:

Now the cycle guard improvement, then tests:
Collaborator

Implemented issue #20. Here's what landed:

Backend

backend/src/models/Map.js — a map now carries its pins:

pins: [{ note: ObjectId → Note, x: Number, y: Number }]   // x/y in image pixels

Coordinates are image pixels, so a pin stays where it was placed whatever the zoom, pan or grid settings are.

backend/src/routes/map.js

  • POST /api/map/pin {id*, note*, x, y} — checks the map's owner and that the note belongs to the same campaign; coordinates are rounded and floored at 0. Pinning a note that is pinned already moves that marker instead of adding a twin. → {status:'ok', map}
  • POST /api/map/unpin {id*, pin*} (the pin subdocument _id) → {status:'ok', map}, keeping the ids of the pins that remain.

backend/src/routes/note.js

  • GET /api/note/all?campaign= — every note of the campaign (folders included, no content) so the picker reaches notes inside folders and every marker can say what it is.
  • GET /api/note/retrieve/:id — one note with its content, ownership checked.
  • POST /api/note/delete now also pulls the deleted note off every map's pins (a pin pointing at a gone note would open nothing).

Frontend

  • services/MapPins.js (new, pure): viewport → image pixel (ToImagePoint, returns null off the image), pin → screen pixel (ToScreenPoint), and BuildNoteOptions / OptionLabel which label the picker with the note's folder path (Undercity / Temple / The Altar) and sort by that label.
  • MapViewerPane.vue: right clicking the map opens the context menu at the cursor with Pin a note here → a submenu of the campaign's notes; the clicked spot is kept for the action (reaching a submenu moves the mouse). Markers are drawn in a screen-space overlay, so they keep their size at any zoom while the overlay itself is pointer-transparent — panning the map still works everywhere but on a marker (@pointerdown.stop keeps a marker click from starting a pan). Clicking a marker opens the note; right clicking one offers Open note / Remove pin. Markers follow a note rename (title-updated) and disappear with it (delete-note).
  • PinnedNoteWindow.vue + pinned_note in WindowDefinitions.js: reads the note through /note/retrieve/:id, renders its markdown, and mounts the note widgets (@roll…) the way the note column does, with loading and "note could not be read" states.
  • ContentSidebar.vue: an updated map entry is written back to the anchored map, so the pins survive switching between the notes and the map pane.
  • Strings added to all three locales (campaigns.map.pins.*, windows.pinned-note); AGENTS.md updated (data model row, note/map API, §5.1, event listeners).

Verification

tests/map-pins.test.js (new, 28 tests) loads the express routers into a node:vm with a stubbed require and the frontend helpers the way map-viewer.test.js loads Content.js. It covers pin placement, coordinate rounding/clamping, the same-campaign and ownership refusals, pin dedup-on-move, unpin keeping the other pins, the picker/retrieve endpoints, delete pulling pins, the coordinate and label helpers, and the viewer wiring.

npm test → 57 passed, 0 failed (29 pre-existing included). I also compiled the three touched/added SFCs with @vue/compiler-sfc (all OK); I did not run the app in a browser — the frontend dependencies are not installed in this tree.

Implemented issue #20. Here's what landed: ## Backend **`backend/src/models/Map.js`** — a map now carries its pins: ```js pins: [{ note: ObjectId → Note, x: Number, y: Number }] // x/y in image pixels ``` Coordinates are image pixels, so a pin stays where it was placed whatever the zoom, pan or grid settings are. **`backend/src/routes/map.js`** - `POST /api/map/pin` `{id*, note*, x, y}` — checks the map's owner and that the note belongs to the *same* campaign; coordinates are rounded and floored at 0. Pinning a note that is pinned already moves that marker instead of adding a twin. → `{status:'ok', map}` - `POST /api/map/unpin` `{id*, pin*}` (the pin subdocument `_id`) → `{status:'ok', map}`, keeping the ids of the pins that remain. **`backend/src/routes/note.js`** - `GET /api/note/all?campaign=` — every note of the campaign (folders included, no `content`) so the picker reaches notes inside folders and every marker can say what it is. - `GET /api/note/retrieve/:id` — one note with its content, ownership checked. - `POST /api/note/delete` now also pulls the deleted note off every map's `pins` (a pin pointing at a gone note would open nothing). ## Frontend - **`services/MapPins.js`** (new, pure): viewport → image pixel (`ToImagePoint`, returns null off the image), pin → screen pixel (`ToScreenPoint`), and `BuildNoteOptions` / `OptionLabel` which label the picker with the note's folder path (`Undercity / Temple / The Altar`) and sort by that label. - **`MapViewerPane.vue`**: right clicking the map opens the context menu at the cursor with *Pin a note here* → a submenu of the campaign's notes; the clicked spot is kept for the action (reaching a submenu moves the mouse). Markers are drawn in a screen-space overlay, so they keep their size at any zoom while the overlay itself is pointer-transparent — panning the map still works everywhere but on a marker (`@pointerdown.stop` keeps a marker click from starting a pan). Clicking a marker opens the note; right clicking one offers *Open note* / *Remove pin*. Markers follow a note rename (`title-updated`) and disappear with it (`delete-note`). - **`PinnedNoteWindow.vue`** + `pinned_note` in `WindowDefinitions.js`: reads the note through `/note/retrieve/:id`, renders its markdown, and mounts the note widgets (`@roll…`) the way the note column does, with loading and "note could not be read" states. - **`ContentSidebar.vue`**: an updated map entry is written back to the anchored map, so the pins survive switching between the notes and the map pane. - Strings added to all three locales (`campaigns.map.pins.*`, `windows.pinned-note`); `AGENTS.md` updated (data model row, note/map API, §5.1, event listeners). ## Verification `tests/map-pins.test.js` (new, 28 tests) loads the express routers into a `node:vm` with a stubbed `require` and the frontend helpers the way `map-viewer.test.js` loads `Content.js`. It covers pin placement, coordinate rounding/clamping, the same-campaign and ownership refusals, pin dedup-on-move, unpin keeping the other pins, the picker/retrieve endpoints, delete pulling pins, the coordinate and label helpers, and the viewer wiring. `npm test` → **57 passed, 0 failed** (29 pre-existing included). I also compiled the three touched/added SFCs with `@vue/compiler-sfc` (all OK); I did not run the app in a browser — the frontend dependencies are not installed in this tree.
Collaborator

Implementation is ready for review: #23

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/23
Agent added help wanted and removed working labels 2026-10-14 14:46:59 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#20