From c2ebd4b308d712b3f4cff99019c559ccab0e49b7 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 9 Nov 2019 15:31:47 +0100 Subject: [PATCH] show notes in a book including their prefix, closes #695 --- src/public/javascripts/services/link.js | 4 ++-- .../javascripts/services/note_detail_book.js | 4 +++- src/public/javascripts/services/tree_utils.js | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js index cf0c2b0ed..eb1b2ffc4 100644 --- a/src/public/javascripts/services/link.js +++ b/src/public/javascripts/services/link.js @@ -16,9 +16,9 @@ function getNotePathFromUrl(url) { async function createNoteLink(notePath, noteTitle = null, tooltip = true) { if (!noteTitle) { - const noteId = treeUtils.getNoteIdFromNotePath(notePath); + const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath); - noteTitle = await treeUtils.getNoteTitle(noteId); + noteTitle = await treeUtils.getNoteTitle(noteId, parentNoteId); } const $noteLink = $("", { diff --git a/src/public/javascripts/services/note_detail_book.js b/src/public/javascripts/services/note_detail_book.js index 517b67284..79b8bf631 100644 --- a/src/public/javascripts/services/note_detail_book.js +++ b/src/public/javascripts/services/note_detail_book.js @@ -131,11 +131,13 @@ class NoteDetailBook { for (const childNote of await note.getChildNotes()) { const type = this.getRenderingType(childNote); + const childNotePath = this.ctx.notePath + '/' + childNote.noteId; + const $card = $('
') .attr('data-note-id', childNote.noteId) .css("flex-basis", ZOOMS[this.zoomLevel].width) .addClass("type-" + type) - .append($('
').append(await linkService.createNoteLink(childNote.noteId, null, false))) + .append($('
').append(await linkService.createNoteLink(childNotePath, null, false))) .append($('
') .css("max-height", ZOOMS[this.zoomLevel].height) .append(await this.getNoteContent(type, childNote))); diff --git a/src/public/javascripts/services/tree_utils.js b/src/public/javascripts/services/tree_utils.js index df396af1c..74883d47d 100644 --- a/src/public/javascripts/services/tree_utils.js +++ b/src/public/javascripts/services/tree_utils.js @@ -25,6 +25,29 @@ function getNoteIdFromNotePath(notePath) { return lastSegment.split("-")[0]; } +function getNoteIdAndParentIdFromNotePath(notePath) { + let parentNoteId = 'root'; + let noteId = ''; + + if (notePath) { + const path = notePath.split("/"); + + const lastSegment = path[path.length - 1]; + + // path could have also tabId suffix + noteId = lastSegment.split("-")[0]; + + if (path.length > 1) { + parentNoteId = path[path.length - 2]; + } + } + + return { + parentNoteId, + noteId + } +} + async function getNotePath(node) { if (!node) { console.error("Node is null"); @@ -103,6 +126,7 @@ export default { getNodeByKey, getNotePath, getNoteIdFromNotePath, + getNoteIdAndParentIdFromNotePath, getNoteTitle, getNotePathTitle, }; \ No newline at end of file