From ac636b6649aedfe07fd915ed8e3bea5af190b919 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 23 Nov 2020 23:11:21 +0100 Subject: [PATCH] WIP per-tab hoisting --- src/public/app/services/hoisted_note.js | 6 +++--- src/public/app/services/tab_context.js | 2 +- src/routes/api/autocomplete.js | 4 ++-- src/routes/api/tree.js | 2 +- src/services/note_cache/note_cache_service.js | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index 5c668b2fb..953e8ae31 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.js @@ -25,7 +25,7 @@ function isRootNode(node) { || node.data.noteId === getHoistedNoteId(); } -async function checkNoteAccess(notePath) { +async function checkNoteAccess(notePath, tabContext) { // notePath argument can contain only noteId which is not good when hoisted since // then we need to check the whole note path const resolvedNotePath = await treeService.resolveNotePath(notePath); @@ -35,11 +35,11 @@ async function checkNoteAccess(notePath) { return false; } - const hoistedNoteId = getHoistedNoteId(); + const hoistedNoteId = tabContext.hoistedNoteId; if (hoistedNoteId !== 'root' && !resolvedNotePath.includes(hoistedNoteId)) { const confirmDialog = await import('../dialogs/confirm.js'); - +console.trace("HI!", hoistedNoteId, notePath); if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?")) { return false; } diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index bfc280d01..1bde9d523 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -45,7 +45,7 @@ class TabContext extends Component { return; } - if (await hoistedNoteService.checkNoteAccess(resolvedNotePath) === false) { + if (await hoistedNoteService.checkNoteAccess(resolvedNotePath, this) === false) { return; // note is outside of hoisted subtree and user chose not to unhoist } diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 84f7ea741..ecdea6d0c 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -5,7 +5,7 @@ const searchService = require('../../services/search/services/search.js'); const repository = require('../../services/repository'); const log = require('../../services/log'); const utils = require('../../services/utils'); -const optionService = require('../../services/options'); +const cls = require('../../services/cls'); function getAutocomplete(req) { const query = req.query.query.trim(); @@ -35,7 +35,7 @@ function getRecentNotes(activeNoteId) { let extraCondition = ''; const params = [activeNoteId]; - const hoistedNoteId = optionService.getOption('hoistedNoteId'); + const hoistedNoteId = cls.getHoistedNoteId(); if (hoistedNoteId !== 'root') { extraCondition = `AND recent_notes.notePath LIKE ?`; params.push(hoistedNoteId + '%'); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index f9f68b381..4b6572b8f 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -84,7 +84,7 @@ function getTree(req) { ) SELECT noteId FROM treeWithDescendantsAscendantsAndTemplates`, [subTreeNoteId, subTreeNoteId]); - noteIds.push(subTreeNoteId);console.log("noteIds", noteIds); + noteIds.push(subTreeNoteId); return getNotesAndBranchesAndAttributes(noteIds); } diff --git a/src/services/note_cache/note_cache_service.js b/src/services/note_cache/note_cache_service.js index 811a6f593..cb1a797f4 100644 --- a/src/services/note_cache/note_cache_service.js +++ b/src/services/note_cache/note_cache_service.js @@ -86,6 +86,10 @@ function getNoteTitle(childNoteId, parentNoteId) { } function getNoteTitleArrayForPath(notePathArray) { + if (notePathArray.length === 1 && notePathArray[0] === cls.getHoistedNoteId()) { + return [getNoteTitle(cls.getHoistedNoteId())]; + } + const titles = []; let parentNoteId = 'root';