mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
sharing improvements
This commit is contained in:
parent
972f2f40bf
commit
47845930f4
@ -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') {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 shared
|
||||
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];
|
||||
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user