fix branch prefix dialog

This commit is contained in:
zadam 2020-02-14 21:21:47 +01:00
parent 8d2c2202fa
commit 2fa41b44c5
2 changed files with 15 additions and 10 deletions

View File

@ -11,11 +11,17 @@ const $noteTitle = $('#branch-prefix-note-title');
let branchId; let branchId;
export async function showDialog(node) { export async function showDialog(notePath) {
branchId = node.data.branchId; const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath);
if (!noteId || !parentNoteId) {
return;
}
branchId = await treeCache.getBranchId(parentNoteId, noteId);
const branch = treeCache.getBranch(branchId); const branch = treeCache.getBranch(branchId);
if (branch.noteId === 'root') { if (!branch || branch.noteId === 'root') {
return; return;
} }
@ -29,7 +35,7 @@ export async function showDialog(node) {
$treePrefixInput.val(branch.prefix); $treePrefixInput.val(branch.prefix);
const noteTitle = await treeService.getNoteTitle(node.data.noteId); const noteTitle = await treeService.getNoteTitle(noteId);
$noteTitle.text(" - " + noteTitle); $noteTitle.text(" - " + noteTitle);
} }
@ -39,8 +45,6 @@ async function savePrefix() {
await server.put('branches/' + branchId + '/set-prefix', { prefix: prefix }); await server.put('branches/' + branchId + '/set-prefix', { prefix: prefix });
await treeService.setPrefix(branchId, prefix);
$dialog.modal('hide'); $dialog.modal('hide');
toastService.showMessage("Branch prefix has been saved."); toastService.showMessage("Branch prefix has been saved.");

View File

@ -52,11 +52,12 @@ export default class DialogEventComponent extends Component {
} }
async editBranchPrefixListener() { async editBranchPrefixListener() {
// FIXME const notePath = this.appContext.tabManager.getActiveTabNotePath();
const node = this.appContext.getMainNoteTree().getActiveNode();
const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js"); if (notePath) {
editBranchPrefixDialog.showDialog(node); const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");
editBranchPrefixDialog.showDialog(notePath);
}
} }
addLinkToTextListener() { addLinkToTextListener() {