shortcuts improvements

This commit is contained in:
zadam
2022-11-26 14:57:39 +01:00
parent 6883b71ce7
commit 6a9ac6f90a
9 changed files with 97 additions and 23 deletions

View File

@@ -30,13 +30,13 @@ function getNotes(noteIds) {
}
function validateParentChild(parentNoteId, childNoteId, branchId = null) {
if (childNoteId === 'root') {
return { success: false, message: 'Cannot move root note.'};
if (['root', 'hidden'].includes(childNoteId)) {
return { success: false, message: `Cannot change this note's location.`};
}
if (parentNoteId === 'none') {
// this shouldn't happen
return { success: false, message: 'Cannot move anything into root parent.' };
return { success: false, message: `Cannot move anything into 'none' parent.` };
}
const existing = getExistingBranch(parentNoteId, childNoteId);
@@ -58,13 +58,10 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
};
}
const parentNoteIsShortcut = becca.getNote(parentNoteId).type === 'shortcut';
const childNoteIsShortcut = becca.getNote(childNoteId).type === 'shortcut';
if (parentNoteIsShortcut !== childNoteIsShortcut) {
if (becca.getNote(parentNoteId).type === 'shortcut') {
return {
success: false,
message: 'Moving/cloning is not possible between shortcuts / normal notes.'
message: 'Shortcut note cannot have any children.'
};
}
@@ -189,6 +186,10 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
for (const note of notes) {
const branch = note.getParentBranches().find(b => b.parentNoteId === parentNoteId);
if (branch.branchId === 'hidden') {
position = 999_999_999;
}
sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?",
[position, branch.branchId]);