mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
make note tree initial load non-lazy
This commit is contained in:
parent
0a05a40186
commit
90d091aedb
@ -2986,7 +2986,7 @@ var uniqueId = $.fn.extend( {
|
|||||||
self = this,
|
self = this,
|
||||||
wasExpanded = this.isExpanded();
|
wasExpanded = this.isExpanded();
|
||||||
|
|
||||||
_assert(this.isLazy(), "load() requires a lazy node");
|
//_assert(this.isLazy(), "load() requires a lazy node");
|
||||||
// _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
|
// _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
|
||||||
if (!forceReload && !this.isUndefined()) {
|
if (!forceReload && !this.isUndefined()) {
|
||||||
return _getResolvedPromise(this);
|
return _getResolvedPromise(this);
|
||||||
|
@ -21,12 +21,12 @@ async function prepareRootNode() {
|
|||||||
return await prepareNode(hoistedBranch);
|
return await prepareNode(hoistedBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function prepareBranch(note) {
|
async function prepareChildren(note) {
|
||||||
if (note.type === 'search') {
|
if (note.type === 'search') {
|
||||||
return await prepareSearchBranch(note);
|
return await prepareSearchNoteChildren(note);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return await prepareRealBranch(note);
|
return await prepareNormalNoteChildren(note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,17 +94,24 @@ async function prepareNode(branch) {
|
|||||||
icon: getIcon(note),
|
icon: getIcon(note),
|
||||||
refKey: note.noteId,
|
refKey: note.noteId,
|
||||||
expanded: branch.isExpanded || hoistedNoteId === note.noteId,
|
expanded: branch.isExpanded || hoistedNoteId === note.noteId,
|
||||||
lazy: true,
|
|
||||||
key: utils.randomString(12) // this should prevent some "duplicate key" errors
|
key: utils.randomString(12) // this should prevent some "duplicate key" errors
|
||||||
};
|
};
|
||||||
|
|
||||||
node.folder = getChildBranchesWithoutImages(note).length > 0
|
const childBranches = getChildBranchesWithoutImages(note);
|
||||||
|| note.type === 'search';
|
|
||||||
|
node.folder = childBranches.length > 0
|
||||||
|
|| note.type === 'search'
|
||||||
|
|
||||||
|
node.lazy = node.folder && !node.expanded;
|
||||||
|
|
||||||
|
if (node.folder && node.expanded) {
|
||||||
|
node.children = await prepareChildren(note);
|
||||||
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function prepareRealBranch(parentNote) {
|
async function prepareNormalNoteChildren(parentNote) {
|
||||||
utils.assertArguments(parentNote);
|
utils.assertArguments(parentNote);
|
||||||
|
|
||||||
const noteList = [];
|
const noteList = [];
|
||||||
@ -132,12 +139,12 @@ function getChildBranchesWithoutImages(parentNote) {
|
|||||||
return childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
|
return childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function prepareSearchBranch(note) {
|
async function prepareSearchNoteChildren(note) {
|
||||||
await treeCache.reloadNotes([note.noteId]);
|
await treeCache.reloadNotes([note.noteId]);
|
||||||
|
|
||||||
const newNote = await treeCache.getNote(note.noteId);
|
const newNote = await treeCache.getNote(note.noteId);
|
||||||
|
|
||||||
return await prepareRealBranch(newNote);
|
return await prepareNormalNoteChildren(newNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExtraClasses(note) {
|
function getExtraClasses(note) {
|
||||||
@ -174,7 +181,7 @@ function getExtraClasses(note) {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
prepareRootNode,
|
prepareRootNode,
|
||||||
prepareBranch,
|
prepareBranch: prepareChildren,
|
||||||
getExtraClasses,
|
getExtraClasses,
|
||||||
getIcon,
|
getIcon,
|
||||||
getChildBranchesWithoutImages
|
getChildBranchesWithoutImages
|
||||||
|
@ -220,7 +220,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
$span.append(refreshSearchButton);
|
$span.append(refreshSearchButton);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// this is done to automatically lazy load all expanded search notes after tree load
|
// this is done to automatically lazy load all expanded notes after tree load
|
||||||
loadChildren: (event, data) => {
|
loadChildren: (event, data) => {
|
||||||
// semaphore since the conflict when two processes are trying to load the same data
|
// semaphore since the conflict when two processes are trying to load the same data
|
||||||
// breaks the fancytree
|
// breaks the fancytree
|
||||||
@ -441,12 +441,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null
|
return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null
|
||||||
}
|
}
|
||||||
|
|
||||||
async reload() {
|
|
||||||
const rootNode = await treeBuilder.prepareRootNode();
|
|
||||||
|
|
||||||
await this.tree.reload([rootNode]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// must be event since it's triggered from outside the tree
|
// must be event since it's triggered from outside the tree
|
||||||
collapseTreeEvent() { this.collapseTree(); }
|
collapseTreeEvent() { this.collapseTree(); }
|
||||||
|
|
||||||
@ -637,7 +631,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
|
|
||||||
const activeNotePath = activeNode !== null ? treeService.getNotePath(activeNode) : null;
|
const activeNotePath = activeNode !== null ? treeService.getNotePath(activeNode) : null;
|
||||||
|
|
||||||
await this.reload();
|
const rootNode = await treeBuilder.prepareRootNode();
|
||||||
|
|
||||||
|
await this.batchUpdate(async () => {
|
||||||
|
await this.tree.reload([rootNode]);
|
||||||
|
});
|
||||||
|
|
||||||
if (activeNotePath) {
|
if (activeNotePath) {
|
||||||
const node = await this.getNodeFromPath(activeNotePath, true);
|
const node = await this.getNodeFromPath(activeNotePath, true);
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
<!-- Include Fancytree skin and library -->
|
<!-- Include Fancytree skin and library -->
|
||||||
<link href="libraries/fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet">
|
<link href="libraries/fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet">
|
||||||
<script src="libraries/fancytree/jquery.fancytree-all-deps.min.js"></script>
|
<script src="libraries/fancytree/jquery.fancytree-all-deps.js"></script>
|
||||||
|
|
||||||
<script src="libraries/jquery.hotkeys.js"></script>
|
<script src="libraries/jquery.hotkeys.js"></script>
|
||||||
<script src="libraries/jquery.fancytree.hotkeys.js"></script>
|
<script src="libraries/jquery.fancytree.hotkeys.js"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user