import { Component , OnInit , ViewContainerRef } from "@angular/core" ; import { AppConfig } from "./core/app-config/app-config" ; import { MatDialog } from "@angular/material/dialog" ; import { DemoDataGeneratingProgressDialogComponent } from "./core/demo-data/demo-data-generating-progress-dialog.component" ; import { AnalyticsService } from "./core/analytics/analytics.service" ; import { EntityMapperService } from "./core/entity/entity-mapper.service" ; import { ConfigService } from "./core/config/config.service" ; import { RouterService } from "./core/view/dynamic-routing/router.service" ; import { EntityConfigService } from "./core/entity/entity-config.service" ; import { SessionService } from "./core/session/session-service/session.service" ; import { SyncState } from "./core/session/session-states/sync-state.enum" ; import { ActivatedRoute , Router } from "@angular/router" ; import { waitForChangeTo } from "./core/session/session-states/session-utils" ; import { environment } from "../environments/environment" ; import { DynamicEntityService } from "./core/entity/dynamic-entity.service" ; import { Child } from "./child-dev-project/children/model/child" ; import { School } from "./child-dev-project/schools/model/school" ; @ Component ( { selector : "app-root" , template : "<app-ui></app-ui>" , } ) export class AppComponent implements OnInit { constructor ( private viewContainerRef , private dialog , private analyticsService , private configService , private entityMapper , private routerService , private entityConfigService , private sessionService , private activatedRoute , private router ) { this . initBasicServices ( ) ; } private async initBasicServices ( ) { DynamicEntityService . registerNewEntity ( "Participant" , Child ) ; DynamicEntityService . registerNewEntity ( "Team" , School ) ; this . sessionService . syncState . pipe ( waitForChangeTo ( SyncState . COMPLETED ) ) . toPromise ( ) . then ( ( ) => this . configService . loadConfig ( this . entityMapper ) ) . then ( ( ) => this . router . navigate ( [ ] , { relativeTo : this . activatedRoute } ) ) ; this . configService . configUpdates . subscribe ( ( ) => { this . routerService . initRouting ( ) ; this . entityConfigService . setupEntitiesFromConfig ( ) ; } ) ; await this . configService . loadConfig ( this . entityMapper ) ; if ( environment . production ) { this . analyticsService . init ( ) ; } } ngOnInit ( ) { this . loadDemoData ( ) ; } private loadDemoData ( ) { if ( AppConfig . settings . demo_mode ) { DemoDataGeneratingProgressDialogComponent . loadDemoDataWithLoadingDialog ( this . dialog ) ; } } }