Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
sharing improvements
zadam47845930f489
diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.jsindex 013a0f98e1..63c096458e 100644--- a/src/becca/entities/branch.js+++ b/src/becca/entities/branch.js@@ -58,7 +58,10 @@ class Branch extends AbstractEntity {}init() {- this.becca.branches[this.branchId] = this;+ if (this.branchId) {+ this.becca.branches[this.branchId] = this;+ }+this.becca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;if (this.branchId === 'root') {diff --git a/src/services/tree.js b/src/services/tree.jsindex bf4d20825b..65ff0903b6 100644--- a/src/services/tree.js+++ b/src/services/tree.js@@ -41,10 +41,15 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {const existing = getExistingBranch(parentNoteId, childNoteId);+ console.log("BBBB", existing);+if (existing && (branchId === null || existing.branchId !== branchId)) {+ const parentNote = becca.getNote(parentNoteId);+ const childNote = becca.getNote(childNoteId);+return {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) {- 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);}diff --git a/src/share/content_renderer.js b/src/share/content_renderer.jsindex 576b83beb3..0d300f61be 100644--- a/src/share/content_renderer.js+++ b/src/share/content_renderer.js@@ -59,7 +59,7 @@ function getContent(note) {content = document.body.innerHTML;}}- else if (note.type === 'code') {+ else if (note.type === 'code' || note.type === 'mermaid') {if (!content?.trim()) {content = NO_CONTENT + getChildrenList(note);}diff --git a/src/share/routes.js b/src/share/routes.jsindex 71b7adae76..8166643131 100644--- a/src/share/routes.js+++ b/src/share/routes.js@@ -3,18 +3,21 @@ const shacaLoader = require("./shaca/shaca_loader");const shareRoot = require("./share_root");const contentRenderer = require("./content_renderer.js");-function getSubRoot(note) {+function getSharedSubTreeRoot(note) {if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {+ // share root itself is not sharedreturn null;}+ // every path leads to share root, but which one to choose?+ // for sake of simplicity URLs are not note pathsconst parentNote = note.getParentNotes()[0];if (parentNote.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {return note;}- return getSubRoot(parentNote);+ return getSharedSubTreeRoot(parentNote);}function register(router) {@@ -28,7 +31,7 @@ function register(router) {if (note) {const content = contentRenderer.getContent(note);- const subRoot = getSubRoot(note);+ const subRoot = getSharedSubTreeRoot(note);res.render("share/page", {note,