From cb91dadeca5c7ea255642de2a561b1c5e2008fa3 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 27 Feb 2021 21:18:10 +0100 Subject: [PATCH] add possibility to define search home for hoisted notes, #1694 --- src/routes/api/date_notes.js | 22 +++++++++++++++------- src/services/attributes.js | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.js index b48232ad4..02fb51813 100644 --- a/src/routes/api/date_notes.js +++ b/src/routes/api/date_notes.js @@ -66,14 +66,22 @@ function createSearchNote(req) { const searchString = params.searchString || ""; let ancestorNoteId = params.ancestorNoteId; - const today = dateUtils.localNowDate(); + const hoistedNote = cls.getHoistedNoteId() ? repository.getNote(cls.getHoistedNoteId()) : null; - let searchHome = - attributeService.getNoteWithLabel('searchHome') - || dateNoteService.getDateNote(today); + let searchHome; - if (cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root') { - const hoistedNote = repository.getNote(cls.getHoistedNoteId()); + if (hoistedNote) { + ([searchHome] = hoistedNote.getDescendantNotesWithLabel('hoistedSearchHome')); + } + + if (!searchHome) { + const today = dateUtils.localNowDate(); + + searchHome = attributeService.getNoteWithLabel('searchHome') + || dateNoteService.getDateNote(today); + } + + if (hoistedNote && hoistedNote.noteId !== 'root') { if (!hoistedNote.getDescendantNoteIds().includes(searchHome.noteId)) { // otherwise the note would be saved outside of the hoisted context which is weird @@ -81,7 +89,7 @@ function createSearchNote(req) { } if (!ancestorNoteId) { - ancestorNoteId = cls.getHoistedNoteId(); + ancestorNoteId = hoistedNote.noteId; } } diff --git a/src/services/attributes.js b/src/services/attributes.js index 6806a6852..38832b958 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -38,6 +38,7 @@ const BUILTIN_ATTRIBUTES = [ { type: 'label', name: 'workspaceIconClass' }, { type: 'label', name: 'workspaceTabBackgroundColor' }, { type: 'label', name: 'searchHome' }, + { type: 'label', name: 'hoistedSearchHome' }, { type: 'label', name: 'sqlConsoleHome' }, { type: 'label', name: 'datePattern' },