From b774d56cf78921fd8d9e85ca9b2731acf446867c Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 13 Dec 2018 21:18:35 +0100 Subject: [PATCH] note titles in jump to note start from hoisted note instead of root --- package-lock.json | 2 +- src/services/hoisted_note.js | 19 +++++++++++++++++++ src/services/note_cache.js | 29 ++++++++++++++++++++--------- src/services/repository.js | 7 ++++--- 4 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 src/services/hoisted_note.js diff --git a/package-lock.json b/package-lock.json index 74d39e693..ba2538980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.25.1-beta", + "version": "0.25.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/services/hoisted_note.js b/src/services/hoisted_note.js new file mode 100644 index 000000000..dc9536bc9 --- /dev/null +++ b/src/services/hoisted_note.js @@ -0,0 +1,19 @@ +const optionService = require('./options'); +const sqlInit = require('./sql_init'); +const eventService = require('./events'); + +let hoistedNoteId = 'root'; + +eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity}) => { + if (entityName === 'options' && entity.name === 'hoistedNoteId') { + hoistedNoteId = entity.value; + } +}); + +sqlInit.dbReady.then(async () => { + hoistedNoteId = await optionService.getOption('hoistedNoteId'); +}); + +module.exports = { + getHoistedNoteId: () => hoistedNoteId +}; \ No newline at end of file diff --git a/src/services/note_cache.js b/src/services/note_cache.js index babbae7aa..6c7fef274 100644 --- a/src/services/note_cache.js +++ b/src/services/note_cache.js @@ -4,7 +4,7 @@ const eventService = require('./events'); const repository = require('./repository'); const protectedSessionService = require('./protected_session'); const utils = require('./utils'); -const options = require('./options'); +const hoistedNoteService = require('./hoisted_note'); let loaded = false; let noteTitles = {}; @@ -121,10 +121,8 @@ async function findNotes(query) { } } - const hoistedNoteId = await options.getOption('hoistedNoteId'); - - if (hoistedNoteId !== 'root') { - results = results.filter(res => res.pathArray.includes(hoistedNoteId)); + if (hoistedNoteService.getHoistedNoteId() !== 'root') { + results = results.filter(res => res.pathArray.includes(hoistedNoteService.getHoistedNoteId())); } // sort results by depth of the note. This is based on the assumption that more important results @@ -221,9 +219,9 @@ function getNoteTitle(noteId, parentNoteId) { function getNoteTitleArrayForPath(path) { const titles = []; - if (path[0] === 'root') { + if (path[0] === hoistedNoteService.getHoistedNoteId()) { if (path.length === 1) { - return [ getNoteTitle('root') ]; + return [ getNoteTitle(hoistedNoteService.getHoistedNoteId()) ]; } else { path = path.slice(1); @@ -231,11 +229,20 @@ function getNoteTitleArrayForPath(path) { } let parentNoteId = 'root'; + let hoistedNotePassed = false; for (const noteId of path) { - const title = getNoteTitle(noteId, parentNoteId); + // start collecting path segment titles only after hoisted note + if (hoistedNotePassed) { + const title = getNoteTitle(noteId, parentNoteId); + + titles.push(title); + } + + if (noteId === hoistedNoteService.getHoistedNoteId()) { + hoistedNotePassed = true; + } - titles.push(title); parentNoteId = noteId; } @@ -250,6 +257,10 @@ function getNoteTitleForPath(path) { function getSomePath(noteId, path) { if (noteId === 'root') { + if (!path.includes(hoistedNoteService.getHoistedNoteId())) { + return false; + } + path.push(noteId); path.reverse(); diff --git a/src/services/repository.js b/src/services/repository.js index 7098a6142..ee844d97d 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -94,9 +94,10 @@ async function updateEntity(entity) { const primaryKey = entity[primaryKeyName]; - if (entity.isChanged && (entityName !== 'options' || entity.isSynced)) { - - await syncTableService.addEntitySync(entityName, primaryKey); + if (entity.isChanged) { + if (entityName !== 'options' || entity.isSynced) { + await syncTableService.addEntitySync(entityName, primaryKey); + } if (!cls.isEntityEventsDisabled()) { const eventPayload = {