-
{{ timestampToString(scheduledTrain.stopInfo.departureTimestamp) }}
+
+ {{ timestampToString(row.checkpointStop.departureTimestamp) }}
{{
- timestampToString(scheduledTrain.stopInfo.departureTimestamp)
+ timestampToString(row.checkpointStop.departureTimestamp)
}}
- {{ timestampToString(scheduledTrain.stopInfo.departureRealTimestamp) }}
- ({{ scheduledTrain.stopInfo.departureDelay > 0 ? '+' : ''
- }}{{ scheduledTrain.stopInfo.departureDelay }})
+ {{ timestampToString(row.checkpointStop.departureRealTimestamp) }}
+ ({{ row.checkpointStop.departureDelay > 0 ? '+' : ''
+ }}{{ row.checkpointStop.departureDelay }})
@@ -183,6 +178,8 @@ import modalTrainMixin from '../../mixins/modalTrainMixin';
import ScheduledTrainStatus from './ScheduledTrainStatus.vue';
import { useApiStore } from '../../store/apiStore';
import { ActiveScenery, Station } from '../../typings/common';
+import { SceneryTimetableRow } from './typings';
+import { getTrainStopStatus, stopStatusPriority } from './utils';
export default defineComponent({
name: 'SceneryTimetable',
@@ -204,10 +201,6 @@ export default defineComponent({
listOpen: false
}),
- mounted() {
- this.loadSelectedOption();
- },
-
activated() {
this.loadSelectedOption();
},
@@ -241,27 +234,105 @@ export default defineComponent({
return url;
},
- computedScheduledTrains() {
+ sceneryTimetables(): SceneryTimetableRow[] {
if (!this.station) return [];
+ if (!this.onlineScenery) return [];
- return (
- this.onlineScenery?.scheduledTrains
- ?.filter(
- (train) =>
- train.checkpointName.toLocaleLowerCase() ==
- (this.chosenCheckpoint || this.station!.name).toLocaleLowerCase() &&
- train.region == this.mainStore.region.id
- )
- .sort((a, b) => {
- if (a.stopStatusID > b.stopStatusID) return 1;
- if (a.stopStatusID < b.stopStatusID) return -1;
+ return this.onlineScenery.scheduledTrains
+ .filter(
+ (ct) =>
+ ct.train.region == this.mainStore.region.id &&
+ this.chosenCheckpoint &&
+ ct.checkpointStop.stopNameRAW.toLowerCase() == this.chosenCheckpoint.toLowerCase()
+ )
+ .map((ct) => {
+ const trainStopStatus = getTrainStopStatus(
+ ct.checkpointStop,
+ ct.train.currentStationName,
+ this.station!.name
+ );
- if (a.stopInfo.arrivalTimestamp > b.stopInfo.arrivalTimestamp) return 1;
- if (a.stopInfo.arrivalTimestamp < b.stopInfo.arrivalTimestamp) return -1;
+ const trainStopIndex =
+ ct.train.timetableData?.followingStops.findIndex(
+ (stop) => stop.stopName == ct.checkpointStop.stopName
+ ) ?? -1;
- return a.stopInfo.departureTimestamp > b.stopInfo.departureTimestamp ? 1 : -1;
- }) || []
- );
+ let prevStationName = '',
+ nextStationName = '';
+
+ let departureLine: string | null = null;
+ let arrivingLine: string | null = null;
+
+ let prevDepartureLine: string | null = null,
+ nextArrivalLine: string | null = null;
+
+ if (trainStopIndex > -1 && ct.train.timetableData?.followingStops !== undefined) {
+ for (let i = trainStopIndex; i >= 0; i--) {
+ const stop = ct.train.timetableData.followingStops[i];
+
+ if (
+ /strong|podg\.|pe\./g.test(stop.stopName) &&
+ !prevStationName &&
+ i <= trainStopIndex - 1
+ )
+ prevStationName = stop.stopNameRAW.replace(/,.*/g, '');
+
+ if (
+ stop.arrivalLine != null &&
+ !arrivingLine &&
+ !/-|_|it|sbl/gi.test(stop.arrivalLine)
+ ) {
+ arrivingLine = stop.arrivalLine;
+ prevDepartureLine =
+ ct.train.timetableData.followingStops[i - 1]?.departureLine || null;
+ }
+ }
+
+ for (let i = trainStopIndex; i < ct.train.timetableData.followingStops.length; i++) {
+ const stop = ct.train.timetableData.followingStops[i];
+
+ if (
+ /strong|podg\.|pe\./g.test(stop.stopName) &&
+ !nextStationName &&
+ i > trainStopIndex
+ )
+ nextStationName = stop.stopNameRAW.replace(/,.*/g, '');
+
+ if (
+ stop.departureLine &&
+ !departureLine &&
+ !/-|_|it|sbl/gi.test(stop.departureLine)
+ ) {
+ departureLine = stop.departureLine;
+ nextArrivalLine = ct.train.timetableData.followingStops[i + 1]?.arrivalLine || null;
+ }
+ }
+ }
+
+ return {
+ checkpointStop: ct.checkpointStop,
+ train: ct.train,
+ prevDepartureLine,
+ nextArrivalLine,
+ departureLine,
+ arrivingLine,
+ prevStationName,
+ nextStationName,
+ status: trainStopStatus
+ };
+ })
+ .sort((a, b) => {
+ if (stopStatusPriority.indexOf(a.status) - stopStatusPriority.indexOf(b.status) < 0)
+ return -1;
+
+ if (stopStatusPriority.indexOf(a.status) - stopStatusPriority.indexOf(b.status) > 0)
+ return 1;
+
+ if (a.checkpointStop.arrivalTimestamp > b.checkpointStop.arrivalTimestamp) return 1;
+ if (a.checkpointStop.arrivalTimestamp < b.checkpointStop.arrivalTimestamp) return -1;
+
+ return a.checkpointStop.departureTimestamp > b.checkpointStop.departureTimestamp ? 1 : -1;
+ });
}
},
diff --git a/src/components/SceneryView/ScheduledTrainStatus.vue b/src/components/SceneryView/ScheduledTrainStatus.vue
index 6d69c01..f315400 100644
--- a/src/components/SceneryView/ScheduledTrainStatus.vue
+++ b/src/components/SceneryView/ScheduledTrainStatus.vue
@@ -1,7 +1,7 @@
{{ computedScheduledTrain.stopStatusIndicator }}
@@ -11,25 +11,21 @@