5
5
TrainrunSectionDto ,
6
6
} from "../../data-structures/business.data.structures" ;
7
7
import { Node } from "../../models/node.model" ;
8
- import { Injectable , OnDestroy } from "@angular/core" ;
8
+ import { Injectable , OnDestroy , EventEmitter } from "@angular/core" ;
9
9
import { BehaviorSubject , Subject } from "rxjs" ;
10
10
import { TrainrunService } from "./trainrun.service" ;
11
11
import { NodeService } from "./node.service" ;
@@ -22,6 +22,7 @@ import {Transition} from "../../models/transition.model";
22
22
import { takeUntil } from "rxjs/operators" ;
23
23
import { FilterService } from "../ui/filter.service" ;
24
24
import { TrainrunSectionNodePair } from "../util/trainrun.iterator" ;
25
+ import { CreateTrainrunOperation , Operation , UpdateTrainrunSectionsOperation } from "../../models/operation.model" ;
25
26
26
27
interface DepartureAndArrivalTimes {
27
28
nodeFromDepartureTime : number ;
@@ -46,6 +47,8 @@ export class TrainrunSectionService implements OnDestroy {
46
47
trainrunSections : [ ] ,
47
48
} ; // store the data in memory
48
49
50
+ readonly operation = new EventEmitter < Operation > ( ) ;
51
+
49
52
informSelectedTrainrunClickSubject =
50
53
new BehaviorSubject < InformSelectedTrainrunClick > ( {
51
54
trainrunSectionId : undefined ,
@@ -668,6 +671,8 @@ export class TrainrunSectionService implements OnDestroy {
668
671
669
672
createTrainrunSection ( sourceNodeId : number , targetNodeId : number , retrieveTravelTimeFromEdge : boolean = false ) {
670
673
const trainrunSection : TrainrunSection = new TrainrunSection ( ) ;
674
+ const initialTrainrunsLength = this . trainrunService . trainrunsStore . trainruns . length ;
675
+
671
676
trainrunSection . setTrainrun (
672
677
this . trainrunService . getSelectedOrNewTrainrun ( ) ,
673
678
) ;
@@ -682,11 +687,6 @@ export class TrainrunSectionService implements OnDestroy {
682
687
const targetNode = this . nodeService . getNodeFromId ( targetNodeId ) ;
683
688
trainrunSection . setSourceAndTargetNodeReference ( sourceNode , targetNode ) ;
684
689
this . trainrunSectionsStore . trainrunSections . push ( trainrunSection ) ;
685
- this . logger . log (
686
- "create new trainrunSection between nodes" ,
687
- sourceNode . getBetriebspunktName ( ) ,
688
- targetNode . getBetriebspunktName ( ) ,
689
- ) ;
690
690
691
691
this . handleNodeAndTrainrunSectionDetails (
692
692
sourceNode ,
@@ -698,6 +698,12 @@ export class TrainrunSectionService implements OnDestroy {
698
698
this . propagateTimesForNewTrainrunSection ( trainrunSection ) ;
699
699
//this.trainrunSectionsUpdated();
700
700
this . trainrunService . trainrunsUpdated ( ) ;
701
+
702
+ if ( initialTrainrunsLength !== this . trainrunService . trainrunsStore . trainruns . length ) {
703
+ this . operation . emit ( new CreateTrainrunOperation ( trainrunSection ) ) ;
704
+ } else {
705
+ this . operation . emit ( new UpdateTrainrunSectionsOperation ( this . getAllTrainrunSectionsForTrainrun ( trainrunSection . getTrainrunId ( ) ) ) ) ;
706
+ }
701
707
}
702
708
703
709
reconnectTrainrunSection (
0 commit comments