|
|
|
@ -8,7 +8,7 @@ const becca = require('../becca/becca');
|
|
|
|
|
|
|
|
|
|
|
|
function validateParentChild(parentNoteId, childNoteId, branchId = null) {
|
|
|
|
function validateParentChild(parentNoteId, childNoteId, branchId = null) {
|
|
|
|
if (['root', '_hidden', '_share', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(childNoteId)) {
|
|
|
|
if (['root', '_hidden', '_share', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(childNoteId)) {
|
|
|
|
return { branch: null, success: false, message: `Cannot change this note's location.`};
|
|
|
|
return { branch: null, success: false, message: `Cannot change this note's location.` };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parentNoteId === 'none') {
|
|
|
|
if (parentNoteId === 'none') {
|
|
|
|
@ -16,14 +16,14 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
|
|
|
|
return { branch: null, success: false, message: `Cannot move anything into 'none' parent.` };
|
|
|
|
return { branch: null, success: false, message: `Cannot move anything into 'none' parent.` };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const existing = becca.getBranchFromChildAndParent(childNoteId, parentNoteId);
|
|
|
|
const existingBranch = becca.getBranchFromChildAndParent(childNoteId, parentNoteId);
|
|
|
|
|
|
|
|
|
|
|
|
if (existing && (branchId === null || existing.branchId !== branchId)) {
|
|
|
|
if (existingBranch && existingBranch.branchId !== branchId) {
|
|
|
|
const parentNote = becca.getNote(parentNoteId);
|
|
|
|
const parentNote = becca.getNote(parentNoteId);
|
|
|
|
const childNote = becca.getNote(childNoteId);
|
|
|
|
const childNote = becca.getNote(childNoteId);
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
branch: existing,
|
|
|
|
branch: existingBranch,
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
|
message: `Note "${childNote.title}" note already exists in the "${parentNote.title}".`
|
|
|
|
message: `Note "${childNote.title}" note already exists in the "${parentNote.title}".`
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -52,6 +52,10 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
|
|
|
|
* Tree cycle can be created when cloning or when moving existing clone. This method should detect both cases.
|
|
|
|
* Tree cycle can be created when cloning or when moving existing clone. This method should detect both cases.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function wouldAddingBranchCreateCycle(parentNoteId, childNoteId) {
|
|
|
|
function wouldAddingBranchCreateCycle(parentNoteId, childNoteId) {
|
|
|
|
|
|
|
|
if (parentNoteId === childNoteId) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const childNote = becca.getNote(childNoteId);
|
|
|
|
const childNote = becca.getNote(childNoteId);
|
|
|
|
const parentNote = becca.getNote(parentNoteId);
|
|
|
|
const parentNote = becca.getNote(parentNoteId);
|
|
|
|
|
|
|
|
|
|
|
|
|