@@ -65,19 +65,17 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
6565 }
6666 const trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
6767
68- this . trainrunSectionTimesService . setOffset ( 0 ) ;
68+ this . startNode = this . trainrunService . getStartNodeWithTrainrunId (
69+ trainrunSection . getTrainrunId ( ) ,
70+ ) ;
71+ this . endNode = this . trainrunService . getEndNodeWithTrainrunId ( trainrunSection . getTrainrunId ( ) ) ;
6972
70- // Initialize the selected trainrun as one-way, selecting the [source] → [target] card
73+ this . trainrunSectionTimesService . setOffset ( 0 ) ;
7174 if ( selectedTrainrun . isRoundTrip ( ) ) {
72- if ( TrainrunsectionHelper . isTargetRightOrBottom ( trainrunSection ) ) {
73- this . onTrainrunSectionCardClick ( "top" ) ;
74- } else {
75- this . onTrainrunSectionCardClick ( "bottom" ) ;
76- }
75+ // Initialize round trip trainrun with top card
76+ this . onTrainrunSectionCardClick ( "top" ) ;
7777 } else {
78- this . chosenCard = TrainrunsectionHelper . isTargetRightOrBottom ( trainrunSection )
79- ? "top"
80- : "bottom" ;
78+ this . chosenCard = this . trainrunService . isTrainrunTargetRightOrBottom ( ) ? "top" : "bottom" ;
8179 }
8280
8381 this . trainrunSectionTimesService . setTrainrunSection ( trainrunSection ) ;
@@ -86,11 +84,6 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
8684 this . timeCategoryLinePattern = selectedTrainrun . getTimeCategoryLinePatternRef ( ) ;
8785 this . trainrunSectionTimesService . setHighlightTravelTimeElement ( false ) ;
8886 this . trainrunSectionTimesService . applyOffsetAndTransformTimeStructure ( ) ;
89-
90- this . startNode = this . trainrunService . getStartNodeWithTrainrunId (
91- trainrunSection . getTrainrunId ( ) ,
92- ) ;
93- this . endNode = this . trainrunService . getEndNodeWithTrainrunId ( trainrunSection . getTrainrunId ( ) ) ;
9487 }
9588
9689 ngOnDestroy ( ) {
@@ -169,33 +162,15 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
169162 return ;
170163 }
171164
172- let trainrunSection = undefined ;
173- let wantedSourceNode = undefined ;
165+ let trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
174166 if ( selectedTrainrun . isRoundTrip ( ) ) {
175- const bothEndNodes = this . trainrunService . getBothEndNodesWithTrainrunId (
176- selectedTrainrun . getId ( ) ,
177- ) ;
178- // direction top-left -> default
179- wantedSourceNode = GeneralViewFunctions . getLeftOrTopNode (
180- bothEndNodes . endNode1 ,
181- bothEndNodes . endNode2 ,
182- ) ;
183- trainrunSection = wantedSourceNode . getStartTrainrunSection ( selectedTrainrun . getId ( ) ) ;
184- } else {
185- trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
186- // Get the left and right nodes to determine the cards order
187- const leftNode = this . trainrunSectionHelper . getNextStopLeftNode (
188- trainrunSection ,
189- this . nodesOrdered ,
190- ) ;
191- const rightNode = this . trainrunSectionHelper . getNextStopRightNode (
192- trainrunSection ,
193- this . nodesOrdered ,
194- ) ;
195- wantedSourceNode = position === "top" ? leftNode : rightNode ;
167+ // For a round trip trainrun, we want to choose the most top/left
168+ // section as reference when switching to a one-way trainrun
169+ trainrunSection = this . trainrunService . getLeftStartSection ( ) ;
196170 }
197171
198- if ( wantedSourceNode !== trainrunSection . getSourceNode ( ) ) {
172+ const referenceNode = position === "top" ? this . startNode : this . endNode ;
173+ if ( referenceNode !== trainrunSection . getSourceNode ( ) ) {
199174 this . trainrunSectionService . invertTrainrunSectionsSourceAndTarget (
200175 trainrunSection . getTrainrunId ( ) ,
201176 ) ;
0 commit comments