Skip to content

DocumentHandler: fix several admin/client media and link bugs#1869

Draft
matself wants to merge 8 commits into
hajkmap:developfrom
matself:fix/1759-1755-documenthandler-fixes
Draft

DocumentHandler: fix several admin/client media and link bugs#1869
matself wants to merge 8 commits into
hajkmap:developfrom
matself:fix/1759-1755-documenthandler-fixes

Conversation

@matself

@matself matself commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Fixes a cluster of DocumentHandler bugs reported in Discussion #1759 and Discussion #1755.

A live demo instance with these fixes applied is available at https://test.webkarta.se/?m=demo.

From #1759 (relative media paths):

  • Client: Img/Video/Audio renderers resolved ../Upload/... paths incorrectly whenever mapserviceBase had no trailing slash (e.g. /api/v2Upload/... instead of /api/v2/Upload/...). Also fixed the Audio component ignoring its own corrected URL in favor of the raw src attribute.
  • Backend: App_Data/Upload is now served directly by the Node backend (at both /Upload and /api/vN/Upload), so uploaded document media works out of the box on a plain npm run dev/node index.js instance instead of requiring a reverse proxy in front.

From #1755 (admin DocumentHandler tooling):

  • Admin: the menu editor's connection-selector silently cleared a menu item's folder whenever a link or map link was confirmed on it, breaking the linked document.
  • Admin: re-selecting an existing link/map link in the document text editor now pre-fills its saved URL instead of always opening blank.
  • Admin: widened the link URL input field (previously far too short for typical map-link URLs).
  • Admin: map links confirmed in the document editor now always include p=documentviewer in their URL, so clicking them reliably reopens the document instead of just recentering the map.
  • Admin: fixed an inserted image being duplicated (as a second, malformed <img>) whenever Enter was pressed while the image was selected.

Each fix is its own commit; see individual commit messages for root-cause detail.

Test plan

  • Verified ../Upload/... path resolution against a local backend with both correct (/api/v2/Upload) and previously-broken (/api/v2Upload) request paths.
  • Verified App_Data/Upload is served at both /Upload and /api/v2/Upload on a plain npm run dev backend instance.
  • Verified menu item folder survives confirming a map link via the admin UI.
  • Verified re-opening the map-link tool on already-linked text pre-fills the existing URL; verified fresh/unlinked text still opens blank.
  • Verified a map link confirmed with an empty or partial p parameter gets documentviewer appended (not overwritten).
  • Reproduced the image-duplication bug against real chapter content and confirmed it no longer occurs after the fix, with a correct empty paragraph inserted afterward.
  • Additionally build-tested all fixes together against a full local deployment (backend + client + admin).

Mats Elfström added 8 commits July 6, 2026 10:35
Resolving "../Upload/..." paths concatenated baseUrl directly without
a separating slash, breaking the URL whenever baseUrl (e.g. mapservice
base) had no trailing slash. Also fixes the Audio component ignoring
its own corrected URL in favor of the raw src attribute.

See discussion hajkmap#1759.
Previously nothing exposed this folder over HTTP at all, relying
entirely on a reverse proxy (e.g. nginx) in production. Now a plain
`npm run dev`/`node index.js` instance serves uploaded document media
out of the box, at both /Upload (matching a typical proxy alias) and
/api/vN/Upload (matching DocumentHandler's default relative
"../Upload/..." resolution). Respects
INFORMATIVE_CUSTOM_UPLOAD_DIR_ABSOLUTE_PATH if set, same as the
existing file-listing logic in informative.service.js.
_promptForLink/_promptForHover always opened the link dialog with
whatever urlValue was last left in state (reset to "" after every
confirm/close), never checking whether the current selection already
sits on a saved LINK entity. Editing an existing map/document/web
link therefore looked like it had been erased, forcing users to
retype it from scratch every time.

Verified via discussion hajkmap#1755: inserted a maplink, saved (href and
data-maplink persisted correctly to the chapter HTML), then
re-selected it and reopened the map-link tool - urlValue is now
pre-filled from the entity's saved data instead of opening blank.
The link/maplink/document-link input used a bare default input width
(~20 chars), far too short for the long URLs DocumentHandler map
links typically are. Set an explicit 600px width, roughly triple the
previous rendered width.
Bug 2 from discussion hajkmap#1755: map links pasted from Anchor's share
dialog typically have an empty or incomplete p= (visible plugins)
parameter, since the document viewer usually isn't open at the
moment the admin generates the share link from the running client.
Clicking such a link then just recenters the map instead of
reopening the document.

Rather than changing Anchor's generic share dialog (which has no
concept of "this link is for a document" and shouldn't need one),
enforce this where the intent is actually known: when a map link is
confirmed here, ensure its p param includes documentviewer,
appending to any existing plugin list rather than overwriting it.
Non-Hajk URLs (no hash fragment) are left untouched.
Bug 1 from discussion hajkmap#1755: MenuConnectionSelector.updateSelection
always wrote folder: folder into the menu item unconditionally, where
folder is the admin's own currently-browsed document-folder filter
(component-level UI state), not the menu item's own folder property.
Since a separate MenuConnectionSelector instance exists per
connection type (DOCUMENT, LINK, MAP_LINK), confirming a maplink or
weblink on an item silently wiped its folder to "" - breaking the
linked document, since folder+document together locate the file.

Gate the folder write the same way document/link/maplink already
are: only touch it when the DOCUMENT connection itself is being
confirmed.

Verified: a menu item with a pre-set folder now keeps it after
confirming a maplink via the admin UI.
DocumentTextEditor's _handleReturn calls insertNewLine() whenever
Enter is pressed while an image (atomic) block is selected, to add
an empty line for continued typing. insertNewLine's fragment
included the current block alongside the new empty block, and
Modifier.replaceWithFragment inserts everything in that fragment -
so the current block (the image) got duplicated into a second,
malformed copy (rendered as a bare <img> instead of a proper
<figure>) every time this path fired.

Reproduced via the exact chapter content from a live test instance:
insert an image, click it to select it, press Enter - before this
fix, getHtml() showed the image twice; after, exactly once, with a
new empty paragraph following it as intended.
…p#1755)

Documents the media-path/Upload-serving fixes from discussion hajkmap#1759
and the four admin DocumentHandler fixes from discussion hajkmap#1755
(folder-clearing, link pre-fill, missing p=documentviewer, image
duplication on Enter).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant