import { Component } from "@angular/core" ; import { OnInitDynamicComponent } from "../../../core/view/dynamic-components/on-init-dynamic-component.interface" ; import { Child } from "../../children/model/child" ; import { PanelConfig } from "../../../core/entity-components/entity-details/EntityDetailsConfig" ; import { FormFieldConfig } from "../../../core/entity-components/entity-form/entity-form/FormConfig" ; import { Router } from "@angular/router" ; import { ChildSchoolRelation } from "../../children/model/childSchoolRelation" ; import { Entity } from "../../../core/entity/model/entity" ; import { ChildrenService } from "../../children/children.service" ; /**
 * This component creates a table containing all children currently attending this school.
 */ @ Component ( { selector : "app-children-overview" , templateUrl : "children-overview.component.html" , styleUrls : [ "./children-overview.component.scss" ] , } ) export class ChildrenOverviewComponent implements OnInitDynamicComponent { columns : FormFieldConfig [ ] = [ { id : "childId" } , { id : "schoolClass" } , { id : "start" } , { id : "end" } , { id : "result" } , ] ; entity : Entity ; records : ChildSchoolRelation [ ] = [ ] ; constructor ( private childrenService , private router ) { } async onInitFromDynamicConfig ( config ) { if ( config ?. config ?. columns ) { this . columns = config . config . columns ; } this . entity = config . entity ; this . records = await this . childrenService . queryRelationsOf ( "school" , this . entity . getId ( ) ) ; } routeToChild ( child ) { this . router . navigate ( [ `/${ child . getType ( ) . toLowerCase ( ) }` , child . getId ( ) ] ) ; } generateNewRecordFactory ( ) { return ( ) => { const newRelation = new ChildSchoolRelation ( ) ; newRelation . schoolId = this . entity . getId ( ) ; return newRelation ; } ; } }