Notes/src/public/app/entities/fbranch.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
* parents.
*/
class FBranch {
2021-04-16 22:57:37 +02:00
constructor(froca, row) {
/** @type {Froca} */
2021-04-16 22:57:37 +02:00
this.froca = froca;
2020-01-29 22:32:22 +01:00
this.update(row);
}
update(row) {
/**
* primary key
* @type {string}
*/
this.branchId = row.branchId;
2021-10-29 21:37:12 +02:00
/** @type {string} */
this.noteId = row.noteId;
2021-10-29 21:37:12 +02:00
/** @type {string} */
this.parentNoteId = row.parentNoteId;
2023-06-29 23:32:19 +02:00
/** @type {int} */
this.notePosition = row.notePosition;
2021-10-29 21:37:12 +02:00
/** @type {string} */
this.prefix = row.prefix;
2021-10-29 21:37:12 +02:00
/** @type {boolean} */
2018-11-26 14:47:46 +01:00
this.isExpanded = !!row.isExpanded;
2021-10-29 21:37:12 +02:00
/** @type {boolean} */
this.fromSearchNote = !!row.fromSearchNote;
}
/** @returns {FNote} */
async getNote() {
2021-04-16 22:57:37 +02:00
return this.froca.getNote(this.noteId);
}
/** @returns {FNote} */
2020-08-26 16:50:16 +02:00
getNoteFromCache() {
2021-04-16 22:57:37 +02:00
return this.froca.getNoteFromCache(this.noteId);
2020-08-26 16:50:16 +02:00
}
/** @returns {FNote} */
2020-01-12 09:57:28 +01:00
async getParentNote() {
2021-04-16 22:57:37 +02:00
return this.froca.getNote(this.parentNoteId);
2020-01-12 09:57:28 +01:00
}
2023-06-30 11:18:34 +02:00
/** @returns {boolean} true if it's top level, meaning its parent is the root note */
isTopLevel() {
return this.parentNoteId === 'root';
}
get toString() {
return `FBranch(branchId=${this.branchId})`;
}
2022-09-21 23:58:54 +02:00
get pojo() {
const pojo = {...this};
delete pojo.froca;
return pojo;
}
}
export default FBranch;