sharing improvements

This commit is contained in:
zadam 2021-12-23 20:54:48 +01:00
parent 972f2f40bf
commit 47845930f4
4 changed files with 23 additions and 7 deletions

View File

@ -58,7 +58,10 @@ class Branch extends AbstractEntity {
} }
init() { init() {
this.becca.branches[this.branchId] = this; if (this.branchId) {
this.becca.branches[this.branchId] = this;
}
this.becca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this; this.becca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
if (this.branchId === 'root') { if (this.branchId === 'root') {

View File

@ -41,10 +41,15 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
const existing = getExistingBranch(parentNoteId, childNoteId); const existing = getExistingBranch(parentNoteId, childNoteId);
console.log("BBBB", existing);
if (existing && (branchId === null || existing.branchId !== branchId)) { if (existing && (branchId === null || existing.branchId !== branchId)) {
const parentNote = becca.getNote(parentNoteId);
const childNote = becca.getNote(childNoteId);
return { return {
success: false, success: false,
message: 'This note already exists in the target.' message: `Note "${childNote.title}" note already exists in the "${parentNote.title}".`
}; };
} }
@ -59,7 +64,12 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
} }
function getExistingBranch(parentNoteId, childNoteId) { function getExistingBranch(parentNoteId, childNoteId) {
const branchId = sql.getValue('SELECT branchId FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0', [childNoteId, parentNoteId]); const branchId = sql.getValue(`
SELECT branchId
FROM branches
WHERE noteId = ?
AND parentNoteId = ?
AND isDeleted = 0`, [childNoteId, parentNoteId]);
return becca.getBranch(branchId); return becca.getBranch(branchId);
} }

View File

@ -59,7 +59,7 @@ function getContent(note) {
content = document.body.innerHTML; content = document.body.innerHTML;
} }
} }
else if (note.type === 'code') { else if (note.type === 'code' || note.type === 'mermaid') {
if (!content?.trim()) { if (!content?.trim()) {
content = NO_CONTENT + getChildrenList(note); content = NO_CONTENT + getChildrenList(note);
} }

View File

@ -3,18 +3,21 @@ const shacaLoader = require("./shaca/shaca_loader");
const shareRoot = require("./share_root"); const shareRoot = require("./share_root");
const contentRenderer = require("./content_renderer.js"); const contentRenderer = require("./content_renderer.js");
function getSubRoot(note) { function getSharedSubTreeRoot(note) {
if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) { if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
// share root itself is not shared
return null; return null;
} }
// every path leads to share root, but which one to choose?
// for sake of simplicity URLs are not note paths
const parentNote = note.getParentNotes()[0]; const parentNote = note.getParentNotes()[0];
if (parentNote.noteId === shareRoot.SHARE_ROOT_NOTE_ID) { if (parentNote.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
return note; return note;
} }
return getSubRoot(parentNote); return getSharedSubTreeRoot(parentNote);
} }
function register(router) { function register(router) {
@ -28,7 +31,7 @@ function register(router) {
if (note) { if (note) {
const content = contentRenderer.getContent(note); const content = contentRenderer.getContent(note);
const subRoot = getSubRoot(note); const subRoot = getSharedSubTreeRoot(note);
res.render("share/page", { res.render("share/page", {
note, note,