From a9df0c485f07c759704bb228b4c0cbf83895b896 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 1 Nov 2021 21:11:16 +0100 Subject: [PATCH] link map contains also backward references and tree map contains parents as well, closes #2270 --- src/routes/api/note_map.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index 9437e13f5..a14922b1d 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -31,8 +31,13 @@ function getNeighbors(note, depth) { const retNoteIds = []; + function isIgnoredRelation(relation) { + return ['relationMapLink', 'template', 'image'].includes(relation.name); + } + + // forward links for (const relation of note.getRelations()) { - if (['relationMapLink', 'template', 'image'].includes(relation.name)) { + if (isIgnoredRelation(relation)) { continue; } @@ -44,6 +49,20 @@ function getNeighbors(note, depth) { } } + // backward links + for (const relation of note.getTargetRelations()) { + if (isIgnoredRelation(relation)) { + continue; + } + + const sourceNote = relation.getNote(); + retNoteIds.push(sourceNote.noteId); + + for (const noteId of getNeighbors(sourceNote, depth - 1)) { + retNoteIds.push(noteId); + } + } + return retNoteIds; } @@ -125,6 +144,7 @@ function getTreeMap(req) { return !note.getParentNotes().find(parentNote => parentNote.noteId === imageLinkRelation.noteId); }) + .concat(...mapRootNote.getParentNotes()) .map(note => [ note.noteId, note.isContentAvailable() ? note.title : '[protected]',