From 721e5da672473f51c5329fd9a0fc52116fd9ee1e Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 3 Mar 2021 22:48:06 +0100 Subject: [PATCH] use notePath instead of noteId for note creation to correctly work with cloned ancestors --- src/public/app/services/main_tree_executors.js | 12 ++++++------ src/public/app/services/note_create.js | 13 ++++++++----- src/public/app/services/tree_context_menu.js | 10 +++++----- .../widgets/attribute_widgets/attribute_editor.js | 2 +- .../widgets/mobile_widgets/mobile_detail_menu.js | 2 +- src/public/app/widgets/note_detail.js | 2 +- src/public/app/widgets/note_tree.js | 3 ++- .../app/widgets/type_widgets/editable_text.js | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/public/app/services/main_tree_executors.js b/src/public/app/services/main_tree_executors.js index fdd5cd107..d65401378 100644 --- a/src/public/app/services/main_tree_executors.js +++ b/src/public/app/services/main_tree_executors.js @@ -27,28 +27,28 @@ export default class MainTreeExecutors extends Component { } async createNoteIntoCommand() { - const activeNote = appContext.tabManager.getActiveTabNote(); + const activeTabContext = appContext.tabManager.getActiveTabContext(); - if (!activeNote) { + if (!activeTabContext) { return; } - await noteCreateService.createNote(activeNote.noteId, { - isProtected: activeNote.isProtected, + await noteCreateService.createNote(activeTabContext.notePath, { + isProtected: activeTabContext.note.isProtected, saveSelection: false }); } async createNoteAfterCommand() { const node = this.tree.getActiveNode(); - const parentNoteId = node.data.parentNoteId; + const parentNotePath = treeService.getNotePath(node.getParent()); const isProtected = await treeService.getParentProtectedStatus(node); if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) { return; } - await noteCreateService.createNote(parentNoteId, { + await noteCreateService.createNote(parentNotePath, { target: 'after', targetBranchId: node.data.branchId, isProtected: isProtected, diff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.js index 8c87ac19b..063089d58 100644 --- a/src/public/app/services/note_create.js +++ b/src/public/app/services/note_create.js @@ -1,13 +1,13 @@ -import hoistedNoteService from "./hoisted_note.js"; import appContext from "./app_context.js"; import utils from "./utils.js"; import protectedSessionHolder from "./protected_session_holder.js"; import server from "./server.js"; import ws from "./ws.js"; import treeCache from "./tree_cache.js"; +import treeService from "./tree.js"; import toastService from "./toast.js"; -async function createNote(parentNoteId, options = {}) { +async function createNote(parentNotePath, options = {}) { options = Object.assign({ activate: true, focus: 'title', @@ -30,6 +30,8 @@ async function createNote(parentNoteId, options = {}) { const newNoteName = options.title || "new note"; + const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath); + const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId}`, { title: newNoteName, content: options.content || "", @@ -47,7 +49,7 @@ async function createNote(parentNoteId, options = {}) { if (options.activate) { const activeTabContext = appContext.tabManager.getActiveTabContext(); - await activeTabContext.setNote(note.noteId); + await activeTabContext.setNote(`${parentNotePath}/${note.noteId}`); if (options.focus === 'title') { appContext.triggerEvent('focusAndSelectTitle'); @@ -82,12 +84,13 @@ function parseSelectedHtml(selectedHtml) { } } -async function duplicateSubtree(noteId, parentNoteId) { +async function duplicateSubtree(noteId, parentNotePath) { + const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath); const {note} = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`); await ws.waitForMaxKnownEntityChangeId(); - await appContext.tabManager.activateOrOpenNote(note.noteId); + await appContext.tabManager.activateOrOpenNote(`${parentNotePath}/${note.noteId}`); const origNote = await treeCache.getNote(noteId); toastService.showMessage(`Note "${origNote.title}" has been duplicated`); diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index 8d39e9c5b..92c9989ea 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -112,10 +112,10 @@ class TreeContextMenu { appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (command === "insertNoteAfter") { - const parentNoteId = this.node.data.parentNoteId; + const parentNotePath = treeService.getNotePath(this.node.getParent()); const isProtected = await treeService.getParentProtectedStatus(this.node); - noteCreateService.createNote(parentNoteId, { + noteCreateService.createNote(parentNotePath, { target: 'after', targetBranchId: this.node.data.branchId, type: type, @@ -123,14 +123,14 @@ class TreeContextMenu { }); } else if (command === "insertChildNote") { - noteCreateService.createNote(noteId, { + const parentNotePath = treeService.getNotePath(this.node); + + noteCreateService.createNote(parentNotePath, { type: type, isProtected: this.node.data.isProtected }); } else { - console.log("Triggering", command, notePath); - this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath}); } } diff --git a/src/public/app/widgets/attribute_widgets/attribute_editor.js b/src/public/app/widgets/attribute_widgets/attribute_editor.js index fc88accff..8c5fe36fe 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_editor.js +++ b/src/public/app/widgets/attribute_widgets/attribute_editor.js @@ -491,7 +491,7 @@ export default class AttributeEditorWidget extends TabAwareWidget { } async createNoteForReferenceLink(title) { - const {note} = await noteCreateService.createNote(this.noteId, { + const {note} = await noteCreateService.createNote(this.notePath, { activate: false, title: title }); diff --git a/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js b/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js index eb4168297..4b59cfab1 100644 --- a/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js +++ b/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js @@ -26,7 +26,7 @@ class MobileDetailMenuWidget extends BasicWidget { ], selectMenuItemHandler: async ({command}) => { if (command === "insertChildNote") { - noteCreateService.createNote(note.noteId); + noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath()); } else if (command === "delete") { const notePath = appContext.tabManager.getActiveTabNotePath(); diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 42f9877a5..5105c2481 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -318,7 +318,7 @@ export default class NoteDetailWidget extends TabAwareWidget { } // without await as this otherwise causes deadlock through component mutex - noteCreateService.createNote(note.noteId, { + noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath(), { isProtected: note.isProtected, saveSelection: true }); diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 4eadc5912..aefc0c2d5 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -203,8 +203,9 @@ export default class NoteTreeWidget extends TabAwareWidget { this.$tree.on("mousedown", ".refresh-search-button", e => this.refreshSearch(e)); this.$tree.on("mousedown", ".add-note-button", e => { const node = $.ui.fancytree.getNode(e); + const parentNotePath = treeService.getNotePath(node); - noteCreateService.createNote(node.data.noteId, { + noteCreateService.createNote(parentNotePath, { isProtected: node.data.isProtected }); }); diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index f7f33c079..104fe8d63 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -274,7 +274,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } async createNoteForReferenceLink(title) { - const {note} = await noteCreateService.createNote(this.noteId, { + const {note} = await noteCreateService.createNote(this.notePath, { activate: false, title: title });