mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
expose root node, fixes #101
This commit is contained in:
@@ -10,7 +10,7 @@ async function prepareTree(noteRows, branchRows, relations) {
|
||||
|
||||
treeCache.load(noteRows, branchRows, relations);
|
||||
|
||||
return await prepareRealBranch(await treeCache.getNote('root'));
|
||||
return [ await prepareNode(await treeCache.getBranch('root')) ];
|
||||
}
|
||||
|
||||
async function prepareBranch(note) {
|
||||
@@ -22,6 +22,35 @@ async function prepareBranch(note) {
|
||||
}
|
||||
}
|
||||
|
||||
async function prepareNode(branch) {
|
||||
const note = await branch.getNote();
|
||||
const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
|
||||
|
||||
const node = {
|
||||
noteId: note.noteId,
|
||||
parentNoteId: branch.parentNoteId,
|
||||
branchId: branch.branchId,
|
||||
isProtected: note.isProtected,
|
||||
title: utils.escapeHtml(title),
|
||||
extraClasses: await getExtraClasses(note),
|
||||
refKey: note.noteId,
|
||||
expanded: note.type !== 'search' && branch.isExpanded
|
||||
};
|
||||
|
||||
if (note.hasChildren() || note.type === 'search') {
|
||||
node.folder = true;
|
||||
|
||||
if (node.expanded && note.type !== 'search') {
|
||||
node.children = await prepareRealBranch(note);
|
||||
}
|
||||
else {
|
||||
node.lazy = true;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
async function prepareRealBranch(parentNote) {
|
||||
utils.assertArguments(parentNote);
|
||||
|
||||
@@ -35,30 +64,7 @@ async function prepareRealBranch(parentNote) {
|
||||
const noteList = [];
|
||||
|
||||
for (const branch of childBranches) {
|
||||
const note = await branch.getNote();
|
||||
const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
|
||||
|
||||
const node = {
|
||||
noteId: note.noteId,
|
||||
parentNoteId: branch.parentNoteId,
|
||||
branchId: branch.branchId,
|
||||
isProtected: note.isProtected,
|
||||
title: utils.escapeHtml(title),
|
||||
extraClasses: await getExtraClasses(note),
|
||||
refKey: note.noteId,
|
||||
expanded: note.type !== 'search' && branch.isExpanded
|
||||
};
|
||||
|
||||
if (note.hasChildren() || note.type === 'search') {
|
||||
node.folder = true;
|
||||
|
||||
if (node.expanded && note.type !== 'search') {
|
||||
node.children = await prepareRealBranch(note);
|
||||
}
|
||||
else {
|
||||
node.lazy = true;
|
||||
}
|
||||
}
|
||||
const node = await prepareNode(branch);
|
||||
|
||||
noteList.push(node);
|
||||
}
|
||||
@@ -90,6 +96,10 @@ async function getExtraClasses(note) {
|
||||
|
||||
const extraClasses = [];
|
||||
|
||||
if (note.noteId === 'root') {
|
||||
extraClasses.push("tree-root");
|
||||
}
|
||||
|
||||
if (note.isProtected) {
|
||||
extraClasses.push("protected");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user