mirror of
https://github.com/zadam/trilium.git
synced 2025-10-27 16:26:31 +01:00
various javaDoc improvements
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
import noteAttributeCache from "../services/note_attribute_cache.js";
|
||||
import ws from "../services/ws.js";
|
||||
import options from "../services/options.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
|
||||
const LABEL = 'label';
|
||||
const RELATION = 'relation';
|
||||
@@ -186,6 +187,26 @@ class NoteShort {
|
||||
return this.treeCache.getNotesFromCache(this.parents);
|
||||
}
|
||||
|
||||
// will sort the parents so that non-search & non-archived are first and archived at the end
|
||||
// this is done so that non-search & non-archived paths are always explored as first when looking for note path
|
||||
resortParents() {
|
||||
this.parents.sort((aNoteId, bNoteId) => {
|
||||
const aBranchId = this.parentToBranch[aNoteId];
|
||||
|
||||
if (aBranchId && aBranchId.startsWith('virt-')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const aNote = this.treeCache.getNoteFromCache([aNoteId]);
|
||||
|
||||
if (aNote.hasLabel('archived')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
});
|
||||
}
|
||||
|
||||
/** @returns {string[]} */
|
||||
getChildNoteIds() {
|
||||
return this.children;
|
||||
@@ -261,6 +282,72 @@ class NoteShort {
|
||||
return noteAttributeCache.attributes[this.noteId];
|
||||
}
|
||||
|
||||
getAllNotePaths(encounteredNoteIds = null) {
|
||||
if (this.noteId === 'root') {
|
||||
return [['root']];
|
||||
}
|
||||
|
||||
if (!encounteredNoteIds) {
|
||||
encounteredNoteIds = new Set();
|
||||
}
|
||||
|
||||
encounteredNoteIds.add(this.noteId);
|
||||
|
||||
const parentNotes = this.getParentNotes();
|
||||
let paths;
|
||||
|
||||
if (parentNotes.length === 1) { // optimization for the most common case
|
||||
if (encounteredNoteIds.has(parentNotes[0].noteId)) {
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
paths = parentNotes[0].getAllNotePaths(encounteredNoteIds);
|
||||
}
|
||||
}
|
||||
else {
|
||||
paths = [];
|
||||
|
||||
for (const parentNote of parentNotes) {
|
||||
if (encounteredNoteIds.has(parentNote.noteId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const newSet = new Set(encounteredNoteIds);
|
||||
|
||||
paths.push(...parentNote.getAllNotePaths(newSet));
|
||||
}
|
||||
}
|
||||
|
||||
for (const path of paths) {
|
||||
path.push(this.noteId);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
getSortedNotePaths(hoistedNotePath = 'root') {
|
||||
const notePaths = this.getAllNotePaths().map(path => ({
|
||||
notePath: path,
|
||||
isInHoistedSubTree: path.includes(hoistedNotePath),
|
||||
isArchived: path.find(noteId => treeCache.notes[noteId].hasLabel('archived')),
|
||||
isSearch: path.find(noteId => treeCache.notes[noteId].type === 'search')
|
||||
}));
|
||||
|
||||
notePaths.sort((a, b) => {
|
||||
if (a.isInHoistedSubTree !== b.isInHoistedSubTree) {
|
||||
return a.isInHoistedSubTree ? -1 : 1;
|
||||
} else if (a.isSearch !== b.isSearch) {
|
||||
return a.isSearch ? 1 : -1;
|
||||
} else if (a.isArchived !== b.isArchived) {
|
||||
return a.isArchived ? 1 : -1;
|
||||
} else {
|
||||
return a.notePath.length - b.notePath.length;
|
||||
}
|
||||
});
|
||||
|
||||
return notePaths;
|
||||
}
|
||||
|
||||
__filterAttrs(attributes, type, name) {
|
||||
if (!type && !name) {
|
||||
return attributes;
|
||||
@@ -300,7 +387,7 @@ class NoteShort {
|
||||
const workspaceIconClass = this.getWorkspaceIconClass();
|
||||
|
||||
if (iconClassLabels.length > 0) {
|
||||
return iconClassLabels.map(l => l.value).join(' ');
|
||||
return iconClassLabels[0].value;
|
||||
}
|
||||
else if (workspaceIconClass) {
|
||||
return workspaceIconClass;
|
||||
@@ -550,7 +637,7 @@ class NoteShort {
|
||||
});
|
||||
}
|
||||
|
||||
hasAncestor(ancestorNote, visitedNoteIds) {
|
||||
hasAncestor(ancestorNote, visitedNoteIds = null) {
|
||||
if (this.noteId === ancestorNote.noteId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user