Poprawki w działaniu ładowania pociągów

This commit is contained in:
2020-09-10 23:05:52 +02:00
parent 4ef90e655d
commit e2a09bca2d
4 changed files with 20 additions and 17 deletions
+11 -5
View File
@@ -124,9 +124,9 @@
<div class="users-content"> <div class="users-content">
<div <div
class="user" class="user"
v-for="train in stationInfo.stationTrains" v-for="train in computedStationTrains"
:key="train.trainNo + train.driverName" :key="train.trainNo + train.driverName"
:class="{'no-timetable': !hasTimetable(train.trainNo)}" :class="{'no-timetable': !train.hasTimetable}"
> >
<a <a
:href="`https://rj.td2.info.pl/train#${train.trainNo};eu`" :href="`https://rj.td2.info.pl/train#${train.trainNo};eu`"
@@ -245,18 +245,24 @@ export default class StationCard extends styleMixin {
: `${this.stationInfo.dispatcherExp}`; : `${this.stationInfo.dispatcherExp}`;
} }
get computedStationTrains() {
return this.stationInfo.stationTrains.map(stationTrain => ({
...stationTrain,
hasTimetable: this.trains.find(train => train.timetableData && train.trainNo === stationTrain.trainNo)
}))
}
get computedScheduledTrains() { get computedScheduledTrains() {
console.log(this.stationInfo.stationName, "test");
return this.stationInfo.scheduledTrains.sort((a, b) => { return this.stationInfo.scheduledTrains.sort((a, b) => {
if (a.arrivalTime > b.arrivalTime) return 1; if (a.arrivalTime > b.arrivalTime) return 1;
else if ((a.arrivalTime < b.arrivalTime)) return -1; else if ((a.arrivalTime < b.arrivalTime)) return -1;
return a.departureTime > b.departureTime ? 1 : -1; return a.departureTime > b.departureTime ? 1 : -1;
}) })
}
hasTimetable(trainNo: number) {
return this.trains.find(train => train.timetableData && train.trainNo === trainNo);
} }
timestampToTime(timestamp: number) { timestampToTime(timestamp: number) {
@@ -145,7 +145,6 @@ import Vue from "vue";
import { Component, Prop } from "vue-property-decorator"; import { Component, Prop } from "vue-property-decorator";
import Station from "@/scripts/interfaces/Station"; import Station from "@/scripts/interfaces/Station";
import Train from "@/scripts/interfaces/Train";
import styleMixin from "@/mixins/styleMixin"; import styleMixin from "@/mixins/styleMixin";
+9 -9
View File
@@ -97,7 +97,7 @@ export default class Store extends VuexModule {
this.context.commit('setJSONData'); this.context.commit('setJSONData');
this.context.dispatch('fetchOnlineData'); this.context.dispatch('fetchOnlineData');
setInterval(() => this.context.dispatch('fetchOnlineData'), 20000); setInterval(() => this.context.dispatch('fetchOnlineData'), 5000);
} }
@Action({ commit: 'updateTimetableData' }) @Action({ commit: 'updateTimetableData' })
@@ -304,16 +304,14 @@ export default class Store extends VuexModule {
@Mutation @Mutation
private updateOnlineTrains(updatedTrainList) { private updateOnlineTrains(updatedTrainList) {
this.trainList = this.trainList = updatedTrainList.reduce((acc, updatedTrain) => {
this.trainList.length == 0 const trainData = this.trainList.find(train => train.trainNo === updatedTrain.trainNo);
? updatedTrainList
: this.trainList.reduce((acc, train) => {
const onlineTrainData = updatedTrainList.find(updatedTrain => train.trainNo === updatedTrain.trainNo);
if (onlineTrainData) acc.push({ ...train, ...onlineTrainData }); if (trainData) acc.push({ ...updatedTrain, ...trainData });
else acc.push({ ...updatedTrain });
return acc; return acc;
}, [] as Train[]); }, [] as Train[]);
this.trainCount = this.trainList.filter(train => train.online).length; this.trainCount = this.trainList.filter(train => train.online).length;
this.dataConnectionStatus = Status.Loaded; this.dataConnectionStatus = Status.Loaded;
@@ -347,6 +345,8 @@ export default class Store extends VuexModule {
return acc; return acc;
}, []); }, []);
// console.log('gituwa');
return { ...station, scheduledTrains }; return { ...station, scheduledTrains };
}); });
-2
View File
@@ -124,8 +124,6 @@ export default class StationsView extends Vue {
const dir: number = this.sorterActive.dir; const dir: number = this.sorterActive.dir;
// const scheduledTrainList = this.scheduledTrains; // const scheduledTrainList = this.scheduledTrains;
return this.stationList return this.stationList
.filter((station) => { .filter((station) => {
if (!station.reqLevel || station.reqLevel == "-1") return true; if (!station.reqLevel || station.reqLevel == "-1") return true;