From e48609aa68ee9110f12d1167be4cc8c305b4cf02 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 5 Jun 2021 23:35:47 +0200 Subject: [PATCH] introducing hidden notes, WIP --- src/public/app/layouts/desktop_layout.js | 3 +- src/public/app/widgets/note_tree.js | 14 ++++- src/routes/api/date_notes.js | 79 +++++++++++++++++------- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index 39ad7b027..366dae4fb 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -139,9 +139,10 @@ export default class DesktopLayout { .child(new SearchResultWidget()) .child(new SqlResultWidget()) ) - .child(...this.customWidgets.get('center-pane')) + .child(...this.customWidgets.get('node-detail-pane')) ) ) + .child(...this.customWidgets.get('center-pane')) ) .child(new RightPaneContainer() .child(...this.customWidgets.get('right-pane')) diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 6488a376e..de598bdb4 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -550,6 +550,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } for (const branch of childBranches) { + if (branch.noteId === 'hidden') { + continue; + } + if (hideArchivedNotes) { const note = branch.getNoteFromCache(); @@ -869,7 +873,11 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { oldActiveNode.setFocus(false); } - if (this.noteContext && this.noteContext.notePath && !this.noteContext.note.isDeleted) { + if (this.noteContext + && this.noteContext.notePath + && !this.noteContext.note.isDeleted + && !this.noteContext.notePath.includes("root/hidden") + ) { const newActiveNode = await this.getNodeFromPath(this.noteContext.notePath); if (newActiveNode) { @@ -1158,7 +1166,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { if (activeNotePath) { const node = await this.getNodeFromPath(activeNotePath, true); - await node.setActive(true, {noEvents: true, noFocus: true}); + if (node) { + await node.setActive(true, {noEvents: true, noFocus: true}); + } } } diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.js index 804e8dda2..1dc200512 100644 --- a/src/routes/api/date_notes.js +++ b/src/routes/api/date_notes.js @@ -6,6 +6,7 @@ const dateUtils = require('../../services/date_utils'); const noteService = require('../../services/notes'); const attributeService = require('../../services/attributes'); const cls = require('../../services/cls'); +const becca = require('../../becca/becca'); function getInboxNote(req) { const hoistedNote = getHoistedNote(); @@ -79,6 +80,40 @@ function createSqlConsole() { return note; } +function getHiddenRoot() { + let hidden = becca.getNote('hidden'); + + if (!hidden) { + hidden = noteService.createNewNote({ + noteId: 'hidden', + title: 'hidden', + type: 'text', + content: '', + parentNoteId: 'root' + }).note; + + hidden.addLabel('archived', "", true); + } + + return hidden; +} + +function getSearchRoot() { + let searchRoot = becca.getNote('search'); + + if (!searchRoot) { + searchRoot = noteService.createNewNote({ + noteId: 'search', + title: 'search', + type: 'text', + content: '', + parentNoteId: getHiddenRoot().noteId + }).note; + } + + return searchRoot; +} + function createSearchNote(req) { const params = req.body; const searchString = params.searchString || ""; @@ -86,29 +121,29 @@ function createSearchNote(req) { const hoistedNote = getHoistedNote(); - let searchHome; + let searchHome = getSearchRoot(); - if (hoistedNote) { - ([searchHome] = hoistedNote.getDescendantNotesWithLabel('hoistedSearchHome')); - - if (!searchHome) { - ([searchHome] = hoistedNote.getDescendantNotesWithLabel('searchHome')); - } - - if (!searchHome) { - searchHome = hoistedNote; - } - - if (!ancestorNoteId) { - ancestorNoteId = hoistedNote.noteId; - } - } - else { - const today = dateUtils.localNowDate(); - - searchHome = attributeService.getNoteWithLabel('searchHome') - || dateNoteService.getDateNote(today); - } + // if (hoistedNote) { + // ([searchHome] = hoistedNote.getDescendantNotesWithLabel('hoistedSearchHome')); + // + // if (!searchHome) { + // ([searchHome] = hoistedNote.getDescendantNotesWithLabel('searchHome')); + // } + // + // if (!searchHome) { + // searchHome = hoistedNote; + // } + // + // if (!ancestorNoteId) { + // ancestorNoteId = hoistedNote.noteId; + // } + // } + // else { + // const today = dateUtils.localNowDate(); + // + // searchHome = attributeService.getNoteWithLabel('searchHome') + // || dateNoteService.getDateNote(today); + // } const {note} = noteService.createNewNote({ parentNoteId: searchHome.noteId,