expose root node, fixes #101

This commit is contained in:
azivner
2018-05-26 16:16:34 -04:00
parent 874593a167
commit ab0486aaf1
7 changed files with 247 additions and 146 deletions

View File

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