Skip to content

Commit

Permalink
wip: add inputs/outputs to root component
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jun 20, 2024
1 parent 52e9b86 commit 43a0b02
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
14 changes: 13 additions & 1 deletion src/app/services/data/trainrunsection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -35,6 +35,11 @@ export interface InformSelectedTrainrunClick {
open: boolean;
}

export class TrainrunSectionOperation {
type: 'create' | 'update' | 'delete';
trainrunSection: TrainrunSection;
}

@Injectable({
providedIn: "root",
})
Expand All @@ -46,6 +51,8 @@ export class TrainrunSectionService implements OnDestroy {
trainrunSections: [],
}; // store the data in memory

trainrunSectionOperation = new EventEmitter<TrainrunSectionOperation>();

informSelectedTrainrunClickSubject =
new BehaviorSubject<InformSelectedTrainrunClick>({
trainrunSectionId: undefined,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 43a0b02

Please sign in to comment.