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 from note actions button, closes #3131
zadamcf6330dee6ec
diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.jsindex ef04344b91..c516155245 100644--- a/src/public/app/services/branches.js+++ b/src/public/app/services/branches.js@@ -68,7 +68,7 @@ async function moveToParentNote(branchIdsToMove, newParentBranchId) {}}-async function deleteNotes(branchIdsToDelete) {+async function deleteNotes(branchIdsToDelete, forceDeleteAllClones = false) {branchIdsToDelete = filterRootNote(branchIdsToDelete);if (branchIdsToDelete.length === 0) {@@ -83,7 +83,7 @@ async function deleteNotes(branchIdsToDelete) {}else {({proceed, deleteAllClones, eraseNotes} = await new Promise(res =>- appContext.triggerCommand('showDeleteNotesDialog', {branchIdsToDelete, callback: res})));+ appContext.triggerCommand('showDeleteNotesDialog', {branchIdsToDelete, callback: res, forceDeleteAllClones})));}if (!proceed) {diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.jsindex fe486f299a..090d67309a 100644--- a/src/public/app/widgets/buttons/note_actions.js+++ b/src/public/app/widgets/buttons/note_actions.js@@ -1,5 +1,6 @@import NoteContextAwareWidget from "../note_context_aware_widget.js";import utils from "../../services/utils.js";+import branchService from "../../services/branches.js";const TPL = `<div class="dropdown note-actions">@@ -30,6 +31,7 @@ const TPL = `<a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"><kbd data-command="openNoteExternally"></kbd> Open note externally</a><a class="dropdown-item import-files-button">Import files</a><a class="dropdown-item export-note-button">Export note</a>+ <a class="dropdown-item delete-note-button">Delete note</a><a data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button"><kbd data-command="printActiveNote"></kbd> Print note</a></div></div>`;@@ -65,6 +67,15 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle'));this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button");++ this.$deleteNoteButton = this.$widget.find(".delete-note-button");+ this.$deleteNoteButton.on("click", () => {+ if (this.note.noteId === 'root') {+ return;+ }++ branchService.deleteNotes([this.note.getParentBranches()[0].branchId], true);+ });}refreshWithNote(note) {diff --git a/src/public/app/widgets/dialogs/delete_notes.js b/src/public/app/widgets/dialogs/delete_notes.jsindex 24801ba962..413120ab2d 100644--- a/src/public/app/widgets/dialogs/delete_notes.js+++ b/src/public/app/widgets/dialogs/delete_notes.js@@ -97,7 +97,7 @@ export default class DeleteNotesDialog extends BasicWidget {this.resolve({proceed: true,- deleteAllClones: this.isDeleteAllClonesChecked(),+ deleteAllClones: this.forceDeleteAllClones || this.isDeleteAllClonesChecked(),eraseNotes: this.isEraseNotesChecked()});});@@ -108,7 +108,7 @@ export default class DeleteNotesDialog extends BasicWidget {async renderDeletePreview() {const response = await server.post('delete-notes-preview', {branchIdsToDelete: this.branchIds,- deleteAllClones: this.isDeleteAllClonesChecked()+ deleteAllClones: this.forceDeleteAllClones || this.isDeleteAllClonesChecked()});this.$deleteNotesList.empty();@@ -143,14 +143,18 @@ export default class DeleteNotesDialog extends BasicWidget {}}- async showDeleteNotesDialogEvent({branchIdsToDelete, callback}) {+ async showDeleteNotesDialogEvent({branchIdsToDelete, callback, forceDeleteAllClones}) {this.branchIds = branchIdsToDelete;+ this.forceDeleteAllClones = forceDeleteAllClones;await this.renderDeletePreview();utils.openDialog(this.$widget);- this.$deleteAllClones.prop("checked", false);+ this.$deleteAllClones+ .prop("checked", !!forceDeleteAllClones)+ .prop("disabled", !!forceDeleteAllClones);+this.$eraseNotes.prop("checked", false);this.resolve = callback;diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 3f3ba7948f..dba1fc0188 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -946,7 +946,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {if (this.noteContext&& this.noteContext.notePath- && !this.noteContext.note.isDeleted+ && !this.noteContext.note?.isDeleted&& !this.noteContext.notePath.includes("root/hidden")) {const newActiveNode = await this.getNodeFromPath(this.noteContext.notePath);