63 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-10-17 14:44:59 +02:00
"use strict";
import AbstractShacaEntity from "./abstract_shaca_entity.js";
import { SBranchRow } from './rows';
import SNote from "./snote.js";
2024-04-09 22:32:06 +03: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;
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;
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];
}
getParentNote() {
return this.parentNote;
}
2021-10-17 14:44:59 +02:00
}
2024-04-09 22:32:06 +03:00
export = SBranch;