2018-03-26 00:29:00 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2018-03-26 00:29:00 +08:00
|
|
|
async getBranches() {
|
|
|
|
const branches = [];
|
|
|
|
|
|
|
|
for (const parent of this.treeCache.parents[this.noteId]) {
|
2018-04-01 11:08:22 +08:00
|
|
|
branches.push(await this.treeCache.getBranchByChildParent(this.noteId, parent.noteId));
|
2018-03-26 00:29:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return branches;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getChildBranches() {
|
|
|
|
const branches = [];
|
|
|
|
|
|
|
|
for (const child of this.treeCache.children[this.noteId]) {
|
|
|
|
branches.push(await this.treeCache.getBranchByChildParent(child.noteId, this.noteId));
|
|
|
|
}
|
|
|
|
|
|
|
|
return branches;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getParentNotes() {
|
|
|
|
return this.treeCache.parents[this.noteId] || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
async getChildNotes() {
|
|
|
|
return this.treeCache.children[this.noteId] || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-03-26 00:29:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NoteShort;
|