Skip to content

Commit 63d75e9

Browse files
committed
one-way: uniformize trainrun direction arrows
Signed-off-by: Louis Greiner <greiner.louis@gmail.com>
1 parent b45d492 commit 63d75e9

File tree

6 files changed

+73
-62
lines changed

6 files changed

+73
-62
lines changed

src/app/perlenkette/perlenkette.component.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
style="transform: translateY(-2px)"
5353
>{{ perlenketteTrainrun.pathItems.at(0).getPerlenketteNode().fullName }}</span
5454
>
55-
@if (getArrowDirectionForOneWayTrainrun() !== null) {
55+
@if (trainrunService.getSbbArrowForTrainrunDirection() !== null) {
5656
<sbb-icon
57-
[svgIcon]="getArrowDirectionForOneWayTrainrun()"
57+
[svgIcon]="trainrunService.getSbbArrowForTrainrunDirection()"
5858
aria-hidden="false"
5959
height="13px"
6060
width="13px"
@@ -77,9 +77,9 @@
7777
<span class="station" (click)="scrollFirst($event)">{{
7878
perlenketteTrainrun.pathItems.at(0).getPerlenketteNode().fullName
7979
}}</span>
80-
@if (getArrowDirectionForOneWayTrainrun() !== null) {
80+
@if (trainrunService.getSbbArrowForTrainrunDirection() !== null) {
8181
<sbb-icon
82-
[svgIcon]="getArrowDirectionForOneWayTrainrun()"
82+
[svgIcon]="trainrunService.getSbbArrowForTrainrunDirection()"
8383
aria-hidden="false"
8484
height="13px"
8585
width="13px"
@@ -114,10 +114,13 @@
114114
</sbb-toggle-icon>
115115
</sbb-toggle-option>
116116
<sbb-toggle-option
117-
label=""
117+
label=""
118118
subtitle=""
119119
[value]="ShowTrainrunEditTab.sbb_trainrun_roundtrip_tab"
120120
>
121+
<sbb-toggle-icon>
122+
<sbb-icon [svgIcon]="trainrunService.getSbbArrowForTrainrunDirection()"></sbb-icon>
123+
</sbb-toggle-icon>
121124
</sbb-toggle-option>
122125
</sbb-toggle>
123126
</div>

src/app/perlenkette/perlenkette.component.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export class PerlenketteComponent implements AfterContentChecked, OnDestroy {
5858

5959
private showAllLockStates = false;
6060

61-
private trainrunSectionHelper: TrainrunsectionHelper;
62-
6361
public showTrainrunEditTab: ShowTrainrunEditTab = ShowTrainrunEditTab.sbb_trainrun_tab;
6462

6563
sbbToogleValue = ShowTrainrunEditTab.sbb_trainrun_tab;
@@ -71,11 +69,10 @@ export class PerlenketteComponent implements AfterContentChecked, OnDestroy {
7169
private readonly nodeService: NodeService,
7270
private versionControlService: VersionControlService,
7371
private changeDetectorRef: ChangeDetectorRef,
74-
private trainrunService: TrainrunService,
72+
public trainrunService: TrainrunService,
7573
private trainrunSectionService: TrainrunSectionService,
7674
) {
7775
this.selectedPerlenketteConnection = undefined;
78-
this.trainrunSectionHelper = new TrainrunsectionHelper(this.trainrunService);
7976

8077
this.loadPerlenketteService
8178
.getPerlenketteData()
@@ -444,19 +441,5 @@ export class PerlenketteComponent implements AfterContentChecked, OnDestroy {
444441
);
445442
}
446443

447-
getArrowDirectionForOneWayTrainrun(): string {
448-
if (!this.perlenketteTrainrun || this.perlenketteTrainrun.direction === Direction.ROUND_TRIP) {
449-
return "minus-medium";
450-
}
451-
const isTargetRightOrBottom = TrainrunsectionHelper.isTargetRightOrBottom(
452-
this.trainrunSectionService.getSelectedTrainrunSection(),
453-
);
454-
if (isTargetRightOrBottom) {
455-
return "arrow-right-medium";
456-
} else {
457-
return "arrow-left-medium";
458-
}
459-
}
460-
461444
protected readonly ShowTrainrunEditTab = ShowTrainrunEditTab;
462445
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {Transition} from "../../models/transition.model";
3030
import {Port} from "../../models/port.model";
3131
import {Connection} from "../../models/connection.model";
3232
import {Operation, OperationType, TrainrunOperation} from "../../models/operation.model";
33+
import {TrainrunsectionHelper} from "../util/trainrunsection.helper";
3334

3435
@Injectable({
3536
providedIn: "root",
@@ -723,6 +724,21 @@ export class TrainrunService {
723724
return iterator.current().trainrunSection;
724725
}
725726

727+
getLastTrainrunSection(trainrun: Trainrun): TrainrunSection | undefined {
728+
const sections = this.trainrunSectionService.getAllTrainrunSectionsForTrainrun(
729+
trainrun.getId(),
730+
);
731+
if (sections.length === 0) {
732+
return undefined;
733+
}
734+
// sections[0] does not ensure to be the first section in the trainrun
735+
const iterator = this.getIterator(sections[0].getSourceNode(), sections[0]);
736+
while (iterator.hasNext()) {
737+
iterator.next();
738+
}
739+
return iterator.current().trainrunSection;
740+
}
741+
726742
sumTravelTimeUpToLastNonStopNode(node: Node, trainrunSection: TrainrunSection): number {
727743
let summedTravelTime = 0;
728744
const iterator = this.getNonStopIterator(node, trainrunSection);
@@ -912,4 +928,31 @@ export class TrainrunService {
912928
});
913929
return labelIDCauntMap;
914930
}
931+
932+
getSbbArrowForTrainrunSectionDirection(): string {
933+
if (!this.getSelectedTrainrun() || this.getSelectedTrainrun().isRoundTrip()) {
934+
return "arrows-left-right-medium";
935+
}
936+
const isTargetRightOrBottom = TrainrunsectionHelper.isTargetRightOrBottom(
937+
this.trainrunSectionService.getSelectedTrainrunSection(),
938+
);
939+
if (isTargetRightOrBottom) {
940+
return "arrow-right-medium";
941+
} else {
942+
return "arrow-left-medium";
943+
}
944+
}
945+
946+
getSbbArrowForTrainrunDirection(): string {
947+
if (!this.getSelectedTrainrun() || this.getSelectedTrainrun().isRoundTrip()) {
948+
return "arrows-left-right-medium";
949+
}
950+
const firstNode = this.getFirstTrainrunSection(this.getSelectedTrainrun()).getSourceNode();
951+
const lastNode = this.getLastTrainrunSection(this.getSelectedTrainrun()).getTargetNode();
952+
if (GeneralViewFunctions.getRightOrBottomNode(firstNode, lastNode) === lastNode) {
953+
return "arrow-right-medium";
954+
} else {
955+
return "arrow-left-medium";
956+
}
957+
}
915958
}

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,16 @@
2525
></sbb-trainrun-tab>
2626
</sbb-tab>
2727
<sbb-tab id="trainrun-section-tab">
28-
@if (getArrowDirectionForOneWayTrainrun() !== null) {
29-
<ng-template sbb-tab-label>
30-
<span style="transform: translateY(-2px)" class="onewayTrip">{{
31-
nextStopLeftNodeName
32-
}}</span>
33-
<sbb-icon
34-
style="transform: translateY(-2px)"
35-
[svgIcon]="getArrowDirectionForOneWayTrainrun()"
36-
aria-hidden="false"
37-
height="13px"
38-
width="13px"
39-
></sbb-icon>
40-
<span style="transform: translateY(-2px)">{{ nextStopRightNodeName }}</span>
41-
</ng-template>
42-
} @else {
43-
<ng-template sbb-tab-label>
44-
<span>{{ nextStopLeftNodeName + " — " + nextStopRightNodeName }}</span>
45-
</ng-template>
46-
}
28+
<ng-template sbb-tab-label
29+
>{{ nextStopLeftNodeName }}
30+
<sbb-icon
31+
[svgIcon]="trainrunService.getSbbArrowForTrainrunSectionDirection()"
32+
aria-hidden="false"
33+
height="13px"
34+
width="13px"
35+
></sbb-icon
36+
>{{ nextStopRightNodeName }}
37+
</ng-template>
4738
<sbb-trainrunsection-tab [trainrunDialogParameter]="data"></sbb-trainrunsection-tab>
4839
</sbb-tab>
4940
<sbb-tab
@@ -52,7 +43,15 @@
5243
>
5344
<sbb-trainrun-filter-tab (trainrunDeleted)="closeDialog()"></sbb-trainrun-filter-tab>
5445
</sbb-tab>
55-
<sbb-tab label="" id="trainrun-roundTrip-tab">
46+
<sbb-tab id="trainrun-roundTrip-tab">
47+
<ng-template sbb-tab-label>
48+
<sbb-icon
49+
[svgIcon]="trainrunService.getSbbArrowForTrainrunDirection()"
50+
aria-hidden="false"
51+
height="13px"
52+
width="13px"
53+
></sbb-icon>
54+
</ng-template>
5655
<sbb-trainrun-roundtrip-tab
5756
(trainrunDeleted)="closeDialog()"
5857
></sbb-trainrun-roundtrip-tab>

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class TrainrunAndSectionDialogComponent implements OnDestroy {
8181
constructor(
8282
public dialog: SbbDialog,
8383
private uiInteractionService: UiInteractionService,
84-
private trainrunService: TrainrunService,
84+
public trainrunService: TrainrunService,
8585
private trainrunSectionService: TrainrunSectionService,
8686
private dataService: DataService,
8787
) {
@@ -220,18 +220,4 @@ export class TrainrunAndSectionDialogComponent implements OnDestroy {
220220
top: dialogPos.top + "px",
221221
};
222222
}
223-
224-
getArrowDirectionForOneWayTrainrun(): string {
225-
if (!this.selectedTrainrun || this.selectedTrainrun.isRoundTrip()) {
226-
return "minus-medium";
227-
}
228-
const isTargetRightOrBottom = TrainrunsectionHelper.isTargetRightOrBottom(
229-
this.trainrunSectionService.getSelectedTrainrunSection(),
230-
);
231-
if (isTargetRightOrBottom) {
232-
return "arrow-right-medium";
233-
} else {
234-
return "arrow-left-medium";
235-
}
236-
}
237223
}

src/app/view/dialogs/trainrun-and-section-dialog/trainrun-tab/trainrun-tab.component.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
::ng-deep div.sbb-tab-label {
99
background: var(--sbb-header-lean-background-color);
10-
}
11-
::ng-deep div.sbb-tab-label:has(span.onewayTrip) {
12-
padding: 0 15px;
13-
height: 36px;
10+
max-height: 36px;
1411
}
1512

1613
::ng-deep .sbb-trainrun-chip-group {

0 commit comments

Comments
 (0)