fix moving/cloning notes broken in 0.42.4, closes #1066

This commit is contained in:
zadam 2020-05-31 22:33:02 +02:00
parent 4d22959e28
commit 8c88ce6f65
8 changed files with 34 additions and 29 deletions

View file

@ -39,13 +39,14 @@ export async function showDialog(noteIds) {
}
async function cloneNotesTo(notePath) {
const targetNoteId = treeService.getNoteIdFromNotePath(notePath);
const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath);
const targetBranchId = await treeCache.getBranchId(parentNoteId, noteId);
for (const cloneNoteId of clonedNoteIds) {
await branchService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());
await branchService.cloneNoteTo(cloneNoteId, targetBranchId, $clonePrefix.val());
const clonedNote = await treeCache.getNote(cloneNoteId);
const targetNote = await treeCache.getNote(targetNoteId);
const targetNote = await treeCache.getBranch(targetBranchId).getNote();
toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`);
}
@ -64,4 +65,4 @@ $form.on('submit', () => {
}
return false;
});
});

View file

@ -32,10 +32,11 @@ export async function showDialog(branchIds) {
noteAutocompleteService.showRecentNotes($noteAutoComplete);
}
async function moveNotesTo(parentNoteId) {
await branchService.moveToParentNote(movedBranchIds, parentNoteId);
async function moveNotesTo(parentBranchId) {
await branchService.moveToParentNote(movedBranchIds, parentBranchId);
const parentNote = await treeCache.getNote(parentNoteId);
const parentBranch = treeCache.getBranch(parentBranchId);
const parentNote = await parentBranch.getNote();
toastService.showMessage(`Selected notes have been moved into ${parentNote.title}`);
}
@ -46,13 +47,12 @@ $form.on('submit', () => {
if (notePath) {
$dialog.modal('hide');
const noteId = treeService.getNoteIdFromNotePath(notePath);
moveNotesTo(noteId);
const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath);
treeCache.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId));
}
else {
console.error("No path to move to.");
}
return false;
});
});

View file

@ -198,8 +198,8 @@ ws.subscribeToMessages(async message => {
}
});
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {
async function cloneNoteTo(childNoteId, parentBranchId, prefix) {
const resp = await server.put(`notes/${childNoteId}/clone-to/${parentBranchId}`, {
prefix: prefix
});

View file

@ -33,13 +33,13 @@ async function pasteAfter(afterBranchId) {
}
}
async function pasteInto(parentNoteId) {
async function pasteInto(parentBranchId) {
if (isClipboardEmpty()) {
return;
}
if (clipboardMode === 'cut') {
await branchService.moveToParentNote(clipboardBranchIds, parentNoteId);
await branchService.moveToParentNote(clipboardBranchIds, parentBranchId);
clipboardBranchIds = [];
clipboardMode = null;
@ -50,7 +50,7 @@ async function pasteInto(parentNoteId) {
for (const clipboardBranch of clipboardBranches) {
const clipboardNote = await clipboardBranch.getNote();
await branchService.cloneNoteTo(clipboardNote.noteId, parentNoteId);
await branchService.cloneNoteTo(clipboardNote.noteId, parentBranchId);
}
// copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple places
@ -89,4 +89,4 @@ export default {
cut,
copy,
isClipboardEmpty
}
}

View file

@ -746,6 +746,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
node.icon = this.getIcon(note, isFolder);
node.extraClasses = this.getExtraClasses(note);
node.title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
node.setExpanded(branch.isExpanded, {noEvents:true});
node.renderTitle();
}
@ -1079,7 +1080,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
const toNode = node.getPrevSibling();
if (toNode !== null) {
branchService.moveToParentNote([node.data.branchId], toNode.data.noteId);
branchService.moveToParentNote([node.data.branchId], toNode.data.branchId);
}
}
@ -1164,7 +1165,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
pasteNotesFromClipboardCommand({node}) {
clipboard.pasteInto(node.data.noteId);
clipboard.pasteInto(node.data.branchId);
}
pasteNotesAfterFromClipboard({node}) {

View file

@ -3,10 +3,10 @@
const cloningService = require('../../services/cloning');
async function cloneNoteToParent(req) {
const {noteId, parentNoteId} = req.params;
const {noteId, parentBranchId} = req.params;
const {prefix} = req.body;
return await cloningService.cloneNoteToParent(noteId, parentNoteId, prefix);
return await cloningService.cloneNoteToParent(noteId, parentBranchId, prefix);
}
async function cloneNoteAfter(req) {
@ -18,4 +18,4 @@ async function cloneNoteAfter(req) {
module.exports = {
cloneNoteToParent,
cloneNoteAfter
};
};

View file

@ -152,7 +152,7 @@ function register(app) {
apiRoute(GET, '/api/edited-notes/:date', noteRevisionsApiRoute.getEditedNotesOnDate);
apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent);
apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentBranchId', cloningApiRoute.cloneNoteToParent);
apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter);
route(GET, '/api/notes/:branchId/export/:type/:format/:version/:taskId', [auth.checkApiAuthOrElectron], exportRoute.exportBranch);

View file

@ -9,12 +9,14 @@ const Branch = require('../entities/branch');
const TaskContext = require("./task_context.js");
const utils = require('./utils');
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
if (await isNoteDeleted(noteId) || await isNoteDeleted(parentNoteId)) {
async function cloneNoteToParent(noteId, parentBranchId, prefix) {
const parentBranch = await repository.getBranch(parentBranchId);
if (await isNoteDeleted(noteId) || await isNoteDeleted(parentBranch.noteId)) {
return { success: false, message: 'Note is deleted.' };
}
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
const validationResult = await treeService.validateParentChild(parentBranch.noteId, noteId);
if (!validationResult.success) {
return validationResult;
@ -22,12 +24,13 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
const branch = await new Branch({
noteId: noteId,
parentNoteId: parentNoteId,
parentNoteId: parentBranch.noteId,
prefix: prefix,
isExpanded: 0
}).save();
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
parentBranch.isExpanded = true; // the new target should be expanded so it immediately shows up to the user
await parentBranch.save();
return { success: true, branchId: branch.branchId };
}
@ -111,4 +114,4 @@ module.exports = {
ensureNoteIsAbsentFromParent,
toggleNoteInParent,
cloneNoteAfter
};
};