various javaDoc improvements

This commit is contained in:
zadam
2021-04-07 22:01:52 +02:00
parent 2f58b6b3c8
commit 79c5645964
31 changed files with 3225 additions and 263 deletions

View File

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