2021-11-10 21:30:54 +01:00
|
|
|
/**
|
|
|
|
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
|
|
|
|
* parents.
|
|
|
|
*/
|
2023-01-03 13:35:10 +01:00
|
|
|
class FBranch {
|
2021-04-16 22:57:37 +02:00
|
|
|
constructor(froca, row) {
|
2023-07-25 22:27:15 +02:00
|
|
|
/** @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) {
|
2021-11-10 21:30:54 +01:00
|
|
|
/**
|
|
|
|
* primary key
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-03-25 12:29:00 -04:00
|
|
|
this.branchId = row.branchId;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} */
|
2018-03-25 12:29:00 -04:00
|
|
|
this.noteId = row.noteId;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} */
|
2018-03-25 12:29:00 -04:00
|
|
|
this.parentNoteId = row.parentNoteId;
|
2023-06-29 23:32:19 +02:00
|
|
|
/** @type {int} */
|
2018-03-25 12:29:00 -04:00
|
|
|
this.notePosition = row.notePosition;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} */
|
2018-03-25 12:29:00 -04:00
|
|
|
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} */
|
2020-10-20 22:33:38 +02:00
|
|
|
this.fromSearchNote = !!row.fromSearchNote;
|
2018-03-25 12:29:00 -04:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:35:10 +01:00
|
|
|
/** @returns {FNote} */
|
2018-03-25 12:29:00 -04:00
|
|
|
async getNote() {
|
2021-04-16 22:57:37 +02:00
|
|
|
return this.froca.getNote(this.noteId);
|
2018-03-25 12:29:00 -04:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:35:10 +01:00
|
|
|
/** @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
|
|
|
}
|
|
|
|
|
2023-01-03 13:35:10 +01: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 */
|
2018-04-08 22:38:52 -04:00
|
|
|
isTopLevel() {
|
|
|
|
return this.parentNoteId === 'root';
|
|
|
|
}
|
|
|
|
|
2018-03-25 12:29:00 -04:00
|
|
|
get toString() {
|
2023-01-03 13:35:10 +01:00
|
|
|
return `FBranch(branchId=${this.branchId})`;
|
2018-03-25 12:29:00 -04:00
|
|
|
}
|
2022-09-21 23:58:54 +02:00
|
|
|
|
|
|
|
get pojo() {
|
|
|
|
const pojo = {...this};
|
|
|
|
delete pojo.froca;
|
|
|
|
return pojo;
|
|
|
|
}
|
2018-03-25 12:29:00 -04:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:35:10 +01:00
|
|
|
export default FBranch;
|