2021-10-17 14:44:59 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
2024-04-09 22:32:06 +03:00
|
|
|
import AbstractShacaEntity = require('./abstract_shaca_entity');
|
|
|
|
|
import SNote = require('./snote');
|
|
|
|
|
|
|
|
|
|
type BranchRow = [ string, string, string, string, string, boolean ];
|
2021-10-17 14:44:59 +02: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;
|
|
|
|
|
private parentNoteId: string;
|
|
|
|
|
private prefix: string;
|
|
|
|
|
private isExpanded: boolean;
|
|
|
|
|
isHidden: boolean;
|
|
|
|
|
|
|
|
|
|
constructor([branchId, noteId, parentNoteId, prefix, isExpanded]: BranchRow) {
|
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-04-09 22:32:06 +03:00
|
|
|
export = SBranch;
|