Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
allow deleting notes including all the clones, closes #629
zadam8dadc7e51880
diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.jsindex d69dd6692c..2de264d3ac 100644--- a/src/public/javascripts/services/branches.js+++ b/src/public/javascripts/services/branches.js@@ -86,21 +86,44 @@ async function deleteNodes(nodes) {return false;}- const nodeTitles = $("<ul>").append(...nodes.map(node => $("<li>").text(node.title)));- const confirmText = $("<div>").text('This will delete the following notes and their sub-notes: ').append(nodeTitles);+ const $deleteClonesCheckbox = $('<div class="form-check">')+ .append($('<input type="checkbox" class="form-check-input" id="delete-clones-checkbox">'))+ .append($('<label for="delete-clones-checkbox">')+ .text("delete also all note clones")+ .attr("title", "all clones of selected notes will be deleted and as such the whole note will be deleted."));+ const $nodeTitles = $("<ul>").append(...nodes.map(node => $("<li>").text(node.title)));+ const $confirmText = $("<div>")+ .append($("<p>").text('This will delete the following notes and their sub-notes: '))+ .append($nodeTitles)+ .append($deleteClonesCheckbox);const confirmDialog = await import('../dialogs/confirm.js');- if (!await confirmDialog.confirm(confirmText)) {+ if (!await confirmDialog.confirm($confirmText)) {return false;}+ const deleteClones = $deleteClonesCheckbox.find("input").is(":checked");+for (const node of nodes) {- const {noteDeleted} = await server.remove('branches/' + node.data.branchId);+ if (deleteClones) {+ await server.remove('notes/' + node.data.noteId);- if (noteDeleted) {noteDetailService.noteDeleted(node.data.noteId);}+ else {+ const {noteDeleted} = await server.remove('branches/' + node.data.branchId);++ if (noteDeleted) {+ noteDetailService.noteDeleted(node.data.noteId);+ }+ }+ }++ if (deleteClones) {+ // if clones are also deleted we give up with targeted cleanup of the tree+ treeService.reload();+ return true;}// following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has beendiff --git a/src/routes/api/branches.js b/src/routes/api/branches.jsindex 1c5162a475..f0261820a5 100644--- a/src/routes/api/branches.js+++ b/src/routes/api/branches.js@@ -103,7 +103,7 @@ async function deleteBranch(req) {const branch = await repository.getBranch(req.params.branchId);return {- noteDeleted: await notes.deleteNote(branch)+ noteDeleted: await notes.deleteBranch(branch)};}diff --git a/src/routes/api/notes.js b/src/routes/api/notes.jsindex c1298d2cfe..d5ff4b2980 100644--- a/src/routes/api/notes.js+++ b/src/routes/api/notes.js@@ -77,7 +77,7 @@ async function deleteNote(req) {const note = await repository.getNote(noteId);for (const branch of await note.getBranches()) {- await noteService.deleteNote(branch);+ await noteService.deleteBranch(branch);}}diff --git a/src/services/cloning.js b/src/services/cloning.jsindex d32abacc6d..9f25c9e585 100644--- a/src/services/cloning.js+++ b/src/services/cloning.js@@ -53,7 +53,7 @@ async function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {const branch = await repository.getEntity(`SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0`, [noteId, parentNoteId]);if (branch) {- await noteService.deleteNote(branch);+ await noteService.deleteBranch(branch);}}diff --git a/src/services/notes.js b/src/services/notes.jsindex 0a7642a0dc..f27049554d 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -384,7 +384,7 @@ async function updateNote(noteId, noteUpdates) {}/** @return {boolean} - true if note has been deleted, false otherwise */-async function deleteNote(branch) {+async function deleteBranch(branch) {if (!branch || branch.isDeleted) {return false;}@@ -407,7 +407,7 @@ async function deleteNote(branch) {await note.save();for (const childBranch of await note.getChildBranches()) {- await deleteNote(childBranch);+ await deleteBranch(childBranch);}for (const attribute of await note.getOwnedAttributes()) {@@ -461,7 +461,7 @@ module.exports = {createNewNote,createNote,updateNote,- deleteNote,+ deleteBranch,protectNoteRecursively,scanForLinks};\ No newline at end of file