From 43a0b025292215d88e8d0dfd5cb3ae02c6dad922 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 19 Jun 2024 17:10:45 +0200 Subject: [PATCH] wip: add inputs/outputs to root component --- src/app/app.component.ts | 32 +++++++++++++++++-- .../services/data/trainrunsection.service.ts | 14 +++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 85a11c4d..6e2d3ab1 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,9 +1,13 @@ -import {Component} from "@angular/core"; +import {Component, Input, Output} from "@angular/core"; import {AuthService} from "./services/auth/auth.service"; +import {TrainrunService} from "./services/data/trainrun.service"; +import {TrainrunSectionService} from "./services/data/trainrunsection.service"; +import {DataService} from "./services/data/data.service"; import {environment} from "../environments/environment"; import packageJson from "../../package.json"; import {Observable} from "rxjs"; import {ProjectDto} from "./api/generated"; +import {NetzgrafikDto} from "./data-structures/business.data.structures"; @Component({ selector: "sbb-root", @@ -33,7 +37,20 @@ export class AppComponent { return this.authService.claims?.email; } - constructor(private authService: AuthService) { + constructor(private authService: AuthService, private trainrunService: TrainrunService, private trainrunSectionService: TrainrunSectionService, private dataService: DataService) { + + /*trainrunService.trainruns.subscribe((value) => { + console.log('trainrunService', value); + }); + + trainrunSectionService.trainrunSections.subscribe((value) => { + console.log('trainrunSectionService', value); + });*/ + + /*trainrunSectionService.trainrunSectionCreated.subscribe((trainrunSection) => { + console.log('trainrunSectionCreated', trainrunSection); + });*/ + if (!this.disableBackend) { this.authenticated = authService.initialized; } @@ -44,4 +61,15 @@ export class AppComponent { this.authService.logOut(); } } + + @Input() + get dto() { + return this.dataService.getNetzgrafikDto(); + } + set dto(dto: NetzgrafikDto) { + this.dataService.loadNetzgrafikDto(dto); + } + + @Output() + trainrunSectionOperation = this.trainrunSectionService.trainrunSectionOperation; } diff --git a/src/app/services/data/trainrunsection.service.ts b/src/app/services/data/trainrunsection.service.ts index 71299be6..45c2cf90 100644 --- a/src/app/services/data/trainrunsection.service.ts +++ b/src/app/services/data/trainrunsection.service.ts @@ -5,7 +5,7 @@ import { TrainrunSectionDto, } from "../../data-structures/business.data.structures"; import {Node} from "../../models/node.model"; -import {Injectable, OnDestroy} from "@angular/core"; +import {Injectable, OnDestroy, EventEmitter} from "@angular/core"; import {BehaviorSubject, Subject} from "rxjs"; import {TrainrunService} from "./trainrun.service"; import {NodeService} from "./node.service"; @@ -35,6 +35,11 @@ export interface InformSelectedTrainrunClick { open: boolean; } +export class TrainrunSectionOperation { + type: 'create' | 'update' | 'delete'; + trainrunSection: TrainrunSection; +} + @Injectable({ providedIn: "root", }) @@ -46,6 +51,8 @@ export class TrainrunSectionService implements OnDestroy { trainrunSections: [], }; // store the data in memory + trainrunSectionOperation = new EventEmitter(); + informSelectedTrainrunClickSubject = new BehaviorSubject({ trainrunSectionId: undefined, @@ -698,6 +705,11 @@ export class TrainrunSectionService implements OnDestroy { this.propagateTimesForNewTrainrunSection(trainrunSection); //this.trainrunSectionsUpdated(); this.trainrunService.trainrunsUpdated(); + + this.trainrunSectionOperation.emit({ + type: 'create', + trainrunSection: trainrunSection, + }); } reconnectTrainrunSection(