From 0c196ae3a59430e25d58e88a45608556f05c4be3 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 21 Sep 2022 23:58:54 +0200 Subject: [PATCH] fix deleting / erasing note --- src/public/app/entities/branch.js | 6 ++++++ src/public/app/widgets/note_tree.js | 2 +- src/routes/api/branches.js | 7 ++++++- src/services/notes.js | 8 -------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/public/app/entities/branch.js b/src/public/app/entities/branch.js index 5abbbcc44..3933d805f 100644 --- a/src/public/app/entities/branch.js +++ b/src/public/app/entities/branch.js @@ -52,6 +52,12 @@ class Branch { get toString() { return `Branch(branchId=${this.branchId})`; } + + get pojo() { + const pojo = {...this}; + delete pojo.froca; + return pojo; + } } export default Branch; diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index dba1fc018..a87a2dffd 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -670,7 +670,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { const note = branch.getNoteFromCache(); if (!note) { - throw new Error(`Branch "${branch.branchId}" has no note "${branch.noteId}"`); + throw new Error(`Branch "${branch.branchId}" has no child note "${branch.noteId}"`); } const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title; diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 3af5fe8ed..9292de5c8 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -194,10 +194,15 @@ function deleteBranch(req) { const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes'); const deleteId = utils.randomString(10); - const noteDeleted = branch.deleteBranch(deleteId, taskContext); + let noteDeleted; if (eraseNotes) { + // erase automatically means deleting all clones + note itself + branch.getNote().deleteNote(deleteId, taskContext); noteService.eraseNotesWithDeleteId(deleteId); + noteDeleted = true; + } else { + noteDeleted = branch.deleteBranch(deleteId, taskContext); } if (last) { diff --git a/src/services/notes.js b/src/services/notes.js index 108b9a9db..5cbb694fa 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -735,10 +735,6 @@ function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) { const attributeIdsToErase = sql.getColumn("SELECT attributeId FROM attributes WHERE isDeleted = 1 AND utcDateModified <= ?", [dateUtils.utcDateTimeStr(cutoffDate)]); eraseAttributes(attributeIdsToErase); - - if (noteIdsToErase.length > 0 || branchIdsToErase.length > 0 || attributeIdsToErase.length > 0) { - require('../becca/becca_loader').reload(); - } }); } @@ -754,10 +750,6 @@ function eraseNotesWithDeleteId(deleteId) { const attributeIdsToErase = sql.getColumn("SELECT attributeId FROM attributes WHERE deleteId = ?", [deleteId]); eraseAttributes(attributeIdsToErase); - - if (noteIdsToErase.length > 0 || branchIdsToErase.length > 0 || attributeIdsToErase.length > 0) { - require('../becca/becca_loader').reload(); - } } function eraseDeletedNotesNow() {