Skip to content

Commit 186f92f

Browse files
committed
fix trainrun-section-card component
Signed-off-by: Louis Greiner <[email protected]>
1 parent a846226 commit 186f92f

File tree

2 files changed

+25
-56
lines changed

2 files changed

+25
-56
lines changed

src/app/view/dialogs/trainrun-and-section-dialog/trainrunsection-card/trainrun-section-card.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
data-testid="one-way-top-card"
66
>
77
<div class="OneWayCardBetriebspunkt">
8-
<b>{{ startNode[1] }}</b> ({{ startNode[0] }})
8+
<b>{{ leftNode.getBetriebspunktName() }}</b> ({{ leftNode.getFullName() }})
99
</div>
1010
<div class="TrainFreqContainer">
1111
<svg class="renderer" width="96px" height="48px" viewBox="0 0 48 24">
@@ -31,7 +31,7 @@
3131
</svg>
3232
</div>
3333
<div class="OneWayCardBetriebspunkt">
34-
<b>{{ endNode[1] }}</b> ({{ endNode[0] }})
34+
<b>{{ rightNode.getBetriebspunktName() }}</b> ({{ rightNode.getFullName() }})
3535
</div>
3636
</div>
3737

@@ -41,7 +41,7 @@
4141
data-testid="one-way-bottom-card"
4242
>
4343
<div class="OneWayCardBetriebspunkt">
44-
<b>{{ startNode[1] }}</b> ({{ startNode[0] }})
44+
<b>{{ leftNode.getBetriebspunktName() }}</b> ({{ leftNode.getFullName() }})
4545
</div>
4646
<div class="TrainFreqContainer">
4747
<svg class="renderer" width="96px" height="48px" viewBox="0 0 48 24">
@@ -67,7 +67,7 @@
6767
</svg>
6868
</div>
6969
<div class="OneWayCardBetriebspunkt">
70-
<b>{{ endNode[1] }}</b> ({{ endNode[0] }})
70+
<b>{{ rightNode.getBetriebspunktName() }}</b> ({{ rightNode.getFullName() }})
7171
</div>
7272
</div>
7373
</div>

src/app/view/dialogs/trainrun-and-section-dialog/trainrunsection-card/trainrun-section-card.component.ts

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {StaticDomTags} from "../../../editor-main-view/data-views/static.dom.tag
1111
import {ColorRefType} from "../../../../data-structures/technical.data.structures";
1212
import {TrainrunSectionTimesService} from "../../../../services/data/trainrun-section-times.service";
1313
import {LeftAndRightTimeStructure} from "../trainrunsection-tab/trainrun-section-tab.component";
14-
import {GeneralViewFunctions} from "../../../util/generalViewFunctions";
1514

1615
@Component({
1716
selector: "sbb-trainrunsection-card",
@@ -23,14 +22,13 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
2322
@Input() trainrunDialogParameter: TrainrunDialogParameter;
2423
@Input() innerContentScaleFactor = "1.0";
2524

26-
public startNode: string[] = ["", ""];
27-
public endNode: string[] = ["", ""];
25+
public leftNode: Node;
26+
public rightNode: Node;
2827
public frequencyLinePattern: LinePatternRefs;
2928
public categoryColorRef: ColorRefType;
3029
public timeCategoryLinePattern: LinePatternRefs;
3130
public chosenCard: "top" | "bottom";
3231

33-
private trainrunSectionHelper: TrainrunsectionHelper;
3432
private destroyed = new Subject<void>();
3533

3634
public get nodesOrdered(): Node[] {
@@ -43,8 +41,6 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
4341
private changeDetection: ChangeDetectorRef,
4442
public trainrunSectionTimesService: TrainrunSectionTimesService,
4543
) {
46-
this.trainrunSectionHelper = new TrainrunsectionHelper(this.trainrunService);
47-
4844
this.trainrunSectionTimesService.setOffset(0);
4945
this.trainrunService.trainruns.pipe(takeUntil(this.destroyed)).subscribe(() => {
5046
this.updateAllValues();
@@ -65,15 +61,19 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
6561
}
6662
const trainrunSection = this.trainrunService.getFirstTrainrunSection(selectedTrainrun);
6763

68-
this.trainrunSectionTimesService.setOffset(0);
64+
this.leftNode = this.trainrunService.getLeftOrTopNodeWithTrainrunId(
65+
trainrunSection.getTrainrunId(),
66+
);
67+
this.rightNode = this.trainrunService.getRightOrBottomNodeWithTrainrunId(
68+
trainrunSection.getTrainrunId(),
69+
);
6970

70-
// Initialize the selected trainrun as one-way, selecting the [source] → [target] card
71+
this.trainrunSectionTimesService.setOffset(0);
7172
if (selectedTrainrun.isRoundTrip()) {
72-
if (TrainrunsectionHelper.isTargetRightOrBottom(trainrunSection)) {
73-
this.onTrainrunSectionCardClick("top");
74-
} else {
75-
this.onTrainrunSectionCardClick("bottom");
76-
}
73+
// Initialize round trip trainrun with top card
74+
this.onTrainrunSectionCardClick("top");
75+
} else {
76+
this.chosenCard = this.trainrunService.isTrainrunTargetRightOrBottom() ? "top" : "bottom";
7777
}
7878

7979
this.trainrunSectionTimesService.setTrainrunSection(trainrunSection);
@@ -82,19 +82,6 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
8282
this.timeCategoryLinePattern = selectedTrainrun.getTimeCategoryLinePatternRef();
8383
this.trainrunSectionTimesService.setHighlightTravelTimeElement(false);
8484
this.trainrunSectionTimesService.applyOffsetAndTransformTimeStructure();
85-
86-
const startNode = this.trainrunService.getStartNodeWithTrainrunId(
87-
trainrunSection.getTrainrunId(),
88-
);
89-
this.startNode = [startNode.getFullName(), startNode.getBetriebspunktName()];
90-
const endNode = this.trainrunService.getEndNodeWithTrainrunId(trainrunSection.getTrainrunId());
91-
this.endNode = [endNode.getFullName(), endNode.getBetriebspunktName()];
92-
93-
if (!selectedTrainrun.isRoundTrip()) {
94-
this.chosenCard = TrainrunsectionHelper.isTargetRightOrBottom(trainrunSection)
95-
? "top"
96-
: "bottom";
97-
}
9885
}
9986

10087
ngOnDestroy() {
@@ -173,33 +160,15 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
173160
return;
174161
}
175162

176-
let trainrunSection = undefined;
177-
let wantedSourceNode = undefined;
163+
let trainrunSection = this.trainrunService.getFirstTrainrunSection(selectedTrainrun);
178164
if (selectedTrainrun.isRoundTrip()) {
179-
const bothEndNodes = this.trainrunService.getBothEndNodesWithTrainrunId(
180-
selectedTrainrun.getId(),
181-
);
182-
// direction top-left -> default
183-
wantedSourceNode = GeneralViewFunctions.getLeftOrTopNode(
184-
bothEndNodes.endNode1,
185-
bothEndNodes.endNode2,
186-
);
187-
trainrunSection = wantedSourceNode.getStartTrainrunSection(selectedTrainrun.getId());
188-
} else {
189-
trainrunSection = this.trainrunService.getFirstTrainrunSection(selectedTrainrun);
190-
// Get the left and right nodes to determine the cards order
191-
const leftNode = this.trainrunSectionHelper.getNextStopLeftNode(
192-
trainrunSection,
193-
this.nodesOrdered,
194-
);
195-
const rightNode = this.trainrunSectionHelper.getNextStopRightNode(
196-
trainrunSection,
197-
this.nodesOrdered,
198-
);
199-
wantedSourceNode = position === "top" ? leftNode : rightNode;
165+
// For a round trip trainrun, we want to choose the most top/left
166+
// section as reference when switching to a one-way trainrun
167+
trainrunSection = this.trainrunService.getLeftOrTopExtremitySection();
200168
}
201169

202-
if (wantedSourceNode !== trainrunSection.getSourceNode()) {
170+
const referenceNode = position === "top" ? this.leftNode : this.rightNode;
171+
if (referenceNode !== trainrunSection.getSourceNode()) {
203172
this.trainrunSectionService.invertTrainrunSectionsSourceAndTarget(
204173
trainrunSection.getTrainrunId(),
205174
);
@@ -217,8 +186,8 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
217186
const trainrunSections =
218187
this.trainrunSectionService.getAllTrainrunSectionsForTrainrun(selectedTrainrunId);
219188
const [startNode, endNode] = [
220-
this.trainrunService.getStartNodeWithTrainrunId(selectedTrainrunId),
221-
this.trainrunService.getEndNodeWithTrainrunId(selectedTrainrunId),
189+
this.trainrunService.getLeftOrTopNodeWithTrainrunId(selectedTrainrunId),
190+
this.trainrunService.getRightOrBottomNodeWithTrainrunId(selectedTrainrunId),
222191
];
223192

224193
// Try to find startNode → endNode

0 commit comments

Comments
 (0)