From 1d008cad13d003745162b417915f59eb4d429519 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 9 May 2021 20:46:32 +0200 Subject: [PATCH] fixes --- src/public/app/services/froca.js | 4 ++- src/routes/api/date_notes.js | 1 - src/services/becca/entities/attribute.js | 6 ++++- src/services/becca/entities/branch.js | 2 ++ src/services/becca/entities/note.js | 32 ++++++++++++++++++++++++ src/services/date_notes.js | 6 +++-- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/public/app/services/froca.js b/src/public/app/services/froca.js index 569796906..87476432b 100644 --- a/src/public/app/services/froca.js +++ b/src/public/app/services/froca.js @@ -306,7 +306,9 @@ class Froca { */ async getNoteComplement(noteId) { if (!this.noteComplementPromises[noteId]) { - this.noteComplementPromises[noteId] = server.get('notes/' + noteId).then(row => new NoteComplement(row)); + this.noteComplementPromises[noteId] = server.get('notes/' + noteId) + .then(row => new NoteComplement(row)) + .catch(e => console.error(`Cannot get note complement for note ${noteId}`)); // we don't want to keep large payloads forever in memory so we clean that up quite quickly // this cache is more meant to share the data between different components within one business transaction (e.g. loading of the note into the tab context and all the components) diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.js index 311f04c26..804e8dda2 100644 --- a/src/routes/api/date_notes.js +++ b/src/routes/api/date_notes.js @@ -6,7 +6,6 @@ const dateUtils = require('../../services/date_utils'); const noteService = require('../../services/notes'); const attributeService = require('../../services/attributes'); const cls = require('../../services/cls'); -const repository = require('../../services/repository'); function getInboxNote(req) { const hoistedNote = getHoistedNote(); diff --git a/src/services/becca/entities/attribute.js b/src/services/becca/entities/attribute.js index 4d1c87235..b2115a240 100644 --- a/src/services/becca/entities/attribute.js +++ b/src/services/becca/entities/attribute.js @@ -29,7 +29,9 @@ class Attribute extends AbstractEntity { /** @param {boolean} */ this.isInheritable = !!row.isInheritable; - this.becca.attributes[this.attributeId] = this; + if (this.attributeId) { + this.becca.attributes[this.attributeId] = this; + } if (!(this.noteId in this.becca.notes)) { // entities can come out of order in sync, create skeleton which will be filled later @@ -131,6 +133,8 @@ class Attribute extends AbstractEntity { } super.beforeSaving(); + + this.becca.attributes[this.attributeId] = this; } getPojo() { diff --git a/src/services/becca/entities/branch.js b/src/services/becca/entities/branch.js index 0d6792571..679797f2c 100644 --- a/src/services/becca/entities/branch.js +++ b/src/services/becca/entities/branch.js @@ -81,6 +81,8 @@ class Branch extends AbstractEntity { this.utcDateModified = dateUtils.utcNowDateTime(); super.beforeSaving(); + + this.becca.branches[this.branchId] = this; } getPojo() { diff --git a/src/services/becca/entities/note.js b/src/services/becca/entities/note.js index 2eb311744..472868df1 100644 --- a/src/services/becca/entities/note.js +++ b/src/services/becca/entities/note.js @@ -831,6 +831,36 @@ class Note extends AbstractEntity { .map(row => new NoteRevision(row)); } + /** + * @return {string[][]} - array of notePaths (each represented by array of noteIds constituting the particular note path) + */ + getAllNotePaths() { + if (this.noteId === 'root') { + return [['root']]; + } + + const notePaths = []; + + for (const parentNote of this.getParentNotes()) { + for (const parentPath of parentNote.getAllNotePaths()) { + parentPath.push(this.noteId); + notePaths.push(parentPath); + } + } + + return notePaths; + } + + /** + * @param ancestorNoteId + * @return {boolean} - true if ancestorNoteId occurs in at least one of the note's paths + */ + isDescendantOfNote(ancestorNoteId) { + const notePaths = this.getAllNotePaths(); + + return notePaths.some(path => path.includes(ancestorNoteId)); + } + decrypt() { if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { try { @@ -847,6 +877,8 @@ class Note extends AbstractEntity { beforeSaving() { super.beforeSaving(); + this.becca.notes[this.noteId] = this; + this.dateModified = dateUtils.localNowDateTime(); this.utcDateModified = dateUtils.utcNowDateTime(); } diff --git a/src/services/date_notes.js b/src/services/date_notes.js index 2d9e5dc08..2c2d129d3 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -3,7 +3,7 @@ const noteService = require('./notes'); const attributeService = require('./attributes'); const dateUtils = require('./date_utils'); -const repository = require('./repository'); +const becca = require('./becca/becca'); const sql = require('./sql'); const protectedSessionService = require('./protected_session'); @@ -26,10 +26,12 @@ function createNote(parentNote, noteTitle) { } function getNoteStartingWith(parentNoteId, startsWith) { - return repository.getEntity(`SELECT notes.* FROM notes JOIN branches USING(noteId) + const noteId = sql.getValue(`SELECT notes.noteId FROM notes JOIN branches USING(noteId) WHERE parentNoteId = ? AND title LIKE '${startsWith}%' AND notes.isDeleted = 0 AND isProtected = 0 AND branches.isDeleted = 0`, [parentNoteId]); + + return becca.getNote(noteId); } /** @return {Note} */