@@ -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 ;
@@ -35,11 +36,6 @@ export interface InformSelectedTrainrunClick {
35
36
open : boolean ;
36
37
}
37
38
38
- export class TrainrunSectionOperation {
39
- type : 'create' | 'update' | 'delete' ;
40
- trainrunSection : TrainrunSection ;
41
- }
42
-
43
39
@Injectable ( {
44
40
providedIn : "root" ,
45
41
} )
@@ -51,7 +47,7 @@ export class TrainrunSectionService implements OnDestroy {
51
47
trainrunSections : [ ] ,
52
48
} ; // store the data in memory
53
49
54
- trainrunSectionOperation = new EventEmitter < TrainrunSectionOperation > ( ) ;
50
+ readonly operation = new EventEmitter < Operation > ( ) ;
55
51
56
52
informSelectedTrainrunClickSubject =
57
53
new BehaviorSubject < InformSelectedTrainrunClick > ( {
@@ -675,6 +671,8 @@ export class TrainrunSectionService implements OnDestroy {
675
671
676
672
createTrainrunSection ( sourceNodeId : number , targetNodeId : number , retrieveTravelTimeFromEdge : boolean = false ) {
677
673
const trainrunSection : TrainrunSection = new TrainrunSection ( ) ;
674
+ const initialTrainrunsLength = this . trainrunService . trainrunsStore . trainruns . length ;
675
+
678
676
trainrunSection . setTrainrun (
679
677
this . trainrunService . getSelectedOrNewTrainrun ( ) ,
680
678
) ;
@@ -689,11 +687,6 @@ export class TrainrunSectionService implements OnDestroy {
689
687
const targetNode = this . nodeService . getNodeFromId ( targetNodeId ) ;
690
688
trainrunSection . setSourceAndTargetNodeReference ( sourceNode , targetNode ) ;
691
689
this . trainrunSectionsStore . trainrunSections . push ( trainrunSection ) ;
692
- this . logger . log (
693
- "create new trainrunSection between nodes" ,
694
- sourceNode . getBetriebspunktName ( ) ,
695
- targetNode . getBetriebspunktName ( ) ,
696
- ) ;
697
690
698
691
this . handleNodeAndTrainrunSectionDetails (
699
692
sourceNode ,
@@ -706,10 +699,11 @@ export class TrainrunSectionService implements OnDestroy {
706
699
//this.trainrunSectionsUpdated();
707
700
this . trainrunService . trainrunsUpdated ( ) ;
708
701
709
- this . trainrunSectionOperation . emit ( {
710
- type : 'create' ,
711
- trainrunSection : trainrunSection ,
712
- } ) ;
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
+ }
713
707
}
714
708
715
709
reconnectTrainrunSection (
0 commit comments