trilium/src/public/javascripts/entities/note_short.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

class NoteShort {
constructor(treeCache, row) {
this.treeCache = treeCache;
this.noteId = row.noteId;
this.title = row.title;
this.isProtected = row.isProtected;
this.type = row.type;
this.mime = row.mime;
this.hideInAutocomplete = row.hideInAutocomplete;
}
2018-03-26 11:25:17 +08:00
isJson() {
return this.mime === "application/json";
}
async getBranches() {
const branchIds = this.treeCache.parents[this.noteId].map(
parentNoteId => this.treeCache.getBranchIdByChildParent(this.noteId, parentNoteId));
return this.treeCache.getBranches(branchIds);
}
hasChildren() {
return this.treeCache.children[this.noteId]
&& this.treeCache.children[this.noteId].length > 0;
}
async getChildBranches() {
if (!this.treeCache.children[this.noteId]) {
2018-04-11 09:08:00 +08:00
return [];
}
const branchIds = this.treeCache.children[this.noteId].map(
childNoteId => this.treeCache.getBranchIdByChildParent(childNoteId, this.noteId));
return await this.treeCache.getBranches(branchIds);
}
2018-04-17 11:34:56 +08:00
getParentNoteIds() {
return this.treeCache.parents[this.noteId] || [];
}
async getParentNotes() {
2018-04-17 11:34:56 +08:00
return await this.treeCache.getNotes(this.getParentNoteIds());
}
getChildNoteIds() {
return this.treeCache.children[this.noteId] || [];
}
async getChildNotes() {
2018-04-17 11:34:56 +08:00
return await this.treeCache.getNotes(this.getChildNoteIds());
}
get toString() {
return `Note(noteId=${this.noteId}, title=${this.title})`;
}
2018-04-08 20:21:49 +08:00
get dto() {
const dto = Object.assign({}, this);
delete dto.treeCache;
delete dto.hideInAutocomplete;
return dto;
}
}
export default NoteShort;