Skip to content

Commit c84066c

Browse files
committed
one-way: fix one-way card when in a specific node position
Signed-off-by: Louis Greiner <[email protected]>
1 parent 7676d00 commit c84066c

File tree

2 files changed

+38
-42
lines changed

2 files changed

+38
-42
lines changed

src/app/services/data/trainrun.service.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,29 @@ export class TrainrunService {
931931
return labelIDCauntMap;
932932
}
933933

934+
isTrainrunTargetRightOrBottom(): boolean {
935+
if (!this.getSelectedTrainrun()) {
936+
return false;
937+
}
938+
const firstNode = this.getFirstTrainrunSection(this.getSelectedTrainrun()).getSourceNode();
939+
const lastNode = this.getLastTrainrunSection(this.getSelectedTrainrun()).getTargetNode();
940+
return GeneralViewFunctions.getRightOrBottomNode(firstNode, lastNode) === lastNode;
941+
}
942+
943+
getLeftStartSection(): TrainrunSection {
944+
if (!this.getSelectedTrainrun()) {
945+
return null;
946+
}
947+
948+
const bothEndNodes = this.getBothEndNodesWithTrainrunId(this.getSelectedTrainrun().getId());
949+
const leftNode = GeneralViewFunctions.getLeftOrTopNode(
950+
bothEndNodes.endNode1,
951+
bothEndNodes.endNode2,
952+
);
953+
954+
return leftNode.getStartTrainrunSection(this.getSelectedTrainrun().getId());
955+
}
956+
934957
getSbbArrowForTrainrunSectionDirection(): string {
935958
if (!this.getSelectedTrainrun() || this.getSelectedTrainrun().isRoundTrip()) {
936959
return "arrows-left-right-medium";
@@ -949,9 +972,7 @@ export class TrainrunService {
949972
if (!this.getSelectedTrainrun() || this.getSelectedTrainrun().isRoundTrip()) {
950973
return "arrows-left-right-medium";
951974
}
952-
const firstNode = this.getFirstTrainrunSection(this.getSelectedTrainrun()).getSourceNode();
953-
const lastNode = this.getLastTrainrunSection(this.getSelectedTrainrun()).getTargetNode();
954-
if (GeneralViewFunctions.getRightOrBottomNode(firstNode, lastNode) === lastNode) {
975+
if (this.isTrainrunTargetRightOrBottom()) {
955976
return "arrow-right-medium";
956977
} else {
957978
return "arrow-left-medium";

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

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)