Merge branch 'stable'

# Conflicts:
#	package-lock.json
#	package.json
#	src/services/build.js
This commit is contained in:
zadam 2023-11-16 23:57:25 +01:00
commit 746abb02d3
5 changed files with 27 additions and 21 deletions

View File

@ -288,7 +288,7 @@ async function loadReferenceLinkTitle($el, href = null) {
if (note) { if (note) {
const icon = await getLinkIcon(noteId, viewScope.viewMode); const icon = await getLinkIcon(noteId, viewScope.viewMode);
k
$el.prepend($("<span>").addClass(icon)); $el.prepend($("<span>").addClass(icon));
} }
} }

View File

@ -20,14 +20,14 @@ const eventService = require("../../services/events.js");
function moveBranchToParent(req) { function moveBranchToParent(req) {
const {branchId, parentBranchId} = req.params; const {branchId, parentBranchId} = req.params;
const parentBranch = becca.getBranch(parentBranchId);
const branchToMove = becca.getBranch(branchId); const branchToMove = becca.getBranch(branchId);
const targetParentBranch = becca.getBranch(parentBranchId);
if (!parentBranch || !branchToMove) { if (!branchToMove || !targetParentBranch) {
throw new ValidationError(`One or both branches '${branchId}', '${parentBranchId}' have not been found`); throw new ValidationError(`One or both branches '${branchId}', '${parentBranchId}' have not been found`);
} }
return branchService.moveBranchToBranch(branchToMove, parentBranch, branchId); return branchService.moveBranchToBranch(branchToMove, targetParentBranch, branchId);
} }
function moveBranchBeforeNote(req) { function moveBranchBeforeNote(req) {

View File

@ -1,12 +1,12 @@
const treeService = require("./tree"); const treeService = require("./tree");
const sql = require("./sql"); const sql = require("./sql");
function moveBranchToNote(sourceBranch, targetParentNoteId) { function moveBranchToNote(branchToMove, targetParentNoteId) {
if (sourceBranch.parentNoteId === targetParentNoteId) { if (branchToMove.parentNoteId === targetParentNoteId) {
return {success: true}; // no-op return {success: true}; // no-op
} }
const validationResult = treeService.validateParentChild(targetParentNoteId, sourceBranch.noteId, sourceBranch.branchId); const validationResult = treeService.validateParentChild(targetParentNoteId, branchToMove.noteId, branchToMove.branchId);
if (!validationResult.success) { if (!validationResult.success) {
return [200, validationResult]; return [200, validationResult];
@ -15,10 +15,10 @@ function moveBranchToNote(sourceBranch, targetParentNoteId) {
const maxNotePos = sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]); const maxNotePos = sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]);
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 10; const newNotePos = maxNotePos === null ? 0 : maxNotePos + 10;
const newBranch = sourceBranch.createClone(targetParentNoteId, newNotePos); const newBranch = branchToMove.createClone(targetParentNoteId, newNotePos);
newBranch.save(); newBranch.save();
sourceBranch.markAsDeleted(); branchToMove.markAsDeleted();
return { return {
success: true, success: true,
@ -26,16 +26,18 @@ function moveBranchToNote(sourceBranch, targetParentNoteId) {
}; };
} }
function moveBranchToBranch(sourceBranch, targetParentBranch) { function moveBranchToBranch(branchToMove, targetParentBranch) {
const res = moveBranchToNote(sourceBranch, targetParentBranch.noteId); const res = moveBranchToNote(branchToMove, targetParentBranch.noteId);
if (!res.success) { if (!res.success) {
return res; return res;
} }
// expanding so that the new placement of the branch is immediately visible // expanding so that the new placement of the branch is immediately visible
targetParentBranch.isExpanded = true; if (!targetParentBranch.isExpanded) {
targetParentBranch.save(); targetParentBranch.isExpanded = true;
targetParentBranch.save();
}
return res; return res;
} }

View File

@ -10,6 +10,8 @@ class AttributeExistsExp extends Expression {
this.attributeType = attributeType; this.attributeType = attributeType;
this.attributeName = attributeName; this.attributeName = attributeName;
// template attr is used as a marker for templates, but it's not meant to be inherited
this.isTemplateLabel = this.attributeType === 'label' && (this.attributeName === 'template' || this.attributeName === 'workspacetemplate');
this.prefixMatch = prefixMatch; this.prefixMatch = prefixMatch;
} }
@ -23,12 +25,10 @@ class AttributeExistsExp extends Expression {
for (const attr of attrs) { for (const attr of attrs) {
const note = attr.note; const note = attr.note;
if (attr.isInheritable) { if (attr.isInheritable && !this.isTemplateLabel) {
resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated());
} }
else if (note.isInherited() && else if (note.isInherited() && !this.isTemplateLabel) {
// template attr is used as a marker for templates, but it's not meant to be inherited
!(this.attributeType === 'label' && (this.attributeName === 'template' || this.attributeName === 'workspacetemplate'))) {
resultNoteSet.addAll(note.getInheritingNotes()); resultNoteSet.addAll(note.getInheritingNotes());
} }
else { else {

View File

@ -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);