From 874972a3d3fb3cfb715adaf27dc5b9f939c72cfe Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 5 Sep 2020 22:45:26 +0200 Subject: [PATCH] fix broken what links here widget --- src/public/app/entities/note_short.js | 11 +++++++++++ src/public/app/services/tree_cache.js | 2 +- .../widgets/collapsible_widgets/what_links_here.js | 2 +- src/routes/api/tree.js | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index cfa387ce9..f4960adb2 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -481,6 +481,17 @@ class NoteShort { .map(attributeId => this.treeCache.attributes[attributeId]); } + /** + * Get relations which target this note + * + * @returns {NoteShort[]} + */ + async getTargetRelationSourceNotes() { + const targetRelations = this.getTargetRelations(); + + return await this.treeCache.getNotes(targetRelations.map(tr => tr.noteId)); + } + /** * Return note complement which is most importantly note's content * diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js index c64d631a6..0caa12d56 100644 --- a/src/public/app/services/tree_cache.js +++ b/src/public/app/services/tree_cache.js @@ -141,7 +141,7 @@ class TreeCache { const note = this.notes[attributeRow.noteId]; - if (!note.attributes.includes(attributeId)) { + if (note && !note.attributes.includes(attributeId)) { note.attributes.push(attributeId); } diff --git a/src/public/app/widgets/collapsible_widgets/what_links_here.js b/src/public/app/widgets/collapsible_widgets/what_links_here.js index 9f13ece02..1b8f27920 100644 --- a/src/public/app/widgets/collapsible_widgets/what_links_here.js +++ b/src/public/app/widgets/collapsible_widgets/what_links_here.js @@ -53,4 +53,4 @@ export default class WhatLinksHereWidget extends CollapsibleWidget { this.refresh(); } } -} \ No newline at end of file +} diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index 37e8f00b7..3a775792f 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -38,7 +38,8 @@ function getNotesAndBranchesAndAttributes(noteIds) { position, isInheritable FROM attributes - WHERE isDeleted = 0 AND noteId IN (???)`, noteIds); + WHERE isDeleted = 0 + AND (noteId IN (???) OR (type = 'relation' AND value IN (???)))`, noteIds); // sorting in memory is faster attributes.sort((a, b) => a.position - b.position < 0 ? -1 : 1);