2021-10-17 14:44:59 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import AbstractShacaEntity from "./abstract_shaca_entity.js";
|
2024-07-16 21:43:04 +03:00
|
|
|
import { SBranchRow } from './rows';
|
2024-07-18 21:35:17 +03:00
|
|
|
import SNote from "./snote.js";
|
2024-04-09 22:32:06 +03:00
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
class SBranch extends AbstractShacaEntity {
|
2024-04-09 22:32:06 +03:00
|
|
|
|
|
|
|
|
private branchId: string;
|
|
|
|
|
private noteId: string;
|
2024-04-10 19:04:38 +03:00
|
|
|
parentNoteId: string;
|
2024-04-09 22:32:06 +03:00
|
|
|
private prefix: string;
|
|
|
|
|
private isExpanded: boolean;
|
|
|
|
|
isHidden: boolean;
|
|
|
|
|
|
2024-04-09 22:49:05 +03:00
|
|
|
constructor([branchId, noteId, parentNoteId, prefix, isExpanded]: SBranchRow) {
|
2021-10-17 14:44:59 +02:00
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.branchId = branchId;
|
|
|
|
|
this.noteId = noteId;
|
|
|
|
|
this.parentNoteId = parentNoteId;
|
|
|
|
|
this.prefix = prefix;
|
|
|
|
|
this.isExpanded = !!isExpanded;
|
2022-03-22 23:17:47 +01:00
|
|
|
this.isHidden = false;
|
2021-10-17 14:44:59 +02:00
|
|
|
|
|
|
|
|
const childNote = this.childNote;
|
|
|
|
|
const parentNote = this.parentNote;
|
|
|
|
|
|
|
|
|
|
if (!childNote.parents.includes(parentNote)) {
|
|
|
|
|
childNote.parents.push(parentNote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!childNote.parentBranches.includes(this)) {
|
|
|
|
|
childNote.parentBranches.push(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!parentNote.children.includes(childNote)) {
|
|
|
|
|
parentNote.children.push(childNote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.shaca.branches[this.branchId] = this;
|
|
|
|
|
this.shaca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 22:32:06 +03:00
|
|
|
get childNote(): SNote {
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.notes[this.noteId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getNote() {
|
|
|
|
|
return this.childNote;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 22:32:06 +03:00
|
|
|
get parentNote(): SNote {
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.notes[this.parentNoteId];
|
|
|
|
|
}
|
2023-07-17 22:19:03 +02:00
|
|
|
|
|
|
|
|
getParentNote() {
|
|
|
|
|
return this.parentNote;
|
|
|
|
|
}
|
2021-10-17 14:44:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 21:50:12 +03:00
|
|
|
export default SBranch;
|