mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
Poprawki do zapamiętywania statusów dyżurnych
This commit is contained in:
+1
-3
@@ -8,7 +8,7 @@
|
||||
</div> -->
|
||||
<header class="app_header">
|
||||
<div class="header_body">
|
||||
<status-indicator :dataStatus="dataStatus" />
|
||||
<status-indicator />
|
||||
|
||||
<span class="header_brand">
|
||||
<span>
|
||||
@@ -116,7 +116,6 @@ export default defineComponent({
|
||||
() => store.getters[GETTERS.currentRegion]
|
||||
);
|
||||
|
||||
const dataStatus = computed(() => data.value.sceneryDataStatus);
|
||||
// const sceneryDataStatus = computed(() => data.value.sceneryDataStatus);
|
||||
|
||||
const isFilterCardVisible = ref(false);
|
||||
@@ -128,7 +127,6 @@ export default defineComponent({
|
||||
currentRegion,
|
||||
isFilterCardVisible,
|
||||
|
||||
dataStatus,
|
||||
dispatcherDataStatus: computed(() => data.value.dispatcherDataStatus),
|
||||
|
||||
trainCount: computed(() => data.value.trainList.length),
|
||||
|
||||
@@ -163,12 +163,14 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { GETTERS } from '@/constants/storeConstants';
|
||||
import { DataStatus } from '@/scripts/enums/DataStatus';
|
||||
import { StoreData } from '@/scripts/interfaces/StoreData';
|
||||
import { defineComponent } from 'vue';
|
||||
import { State, useStore } from '@/store';
|
||||
import { computed, defineComponent } from 'vue';
|
||||
import { Store } from 'vuex';
|
||||
|
||||
export default defineComponent({
|
||||
props: ['dataStatus'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
@@ -193,11 +195,20 @@ export default defineComponent({
|
||||
this.setSignalStatus(DataStatus.Loading);
|
||||
},
|
||||
|
||||
setup() {
|
||||
const store: Store<State> = useStore();
|
||||
|
||||
return {
|
||||
dataStatus: computed(() => store.getters[GETTERS.allData] as StoreData)
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
dataStatus(storeData: StoreData) {
|
||||
const sceneryDataStatus = storeData.sceneryDataStatus;
|
||||
const trainsDataStatus = storeData.trainsDataStatus;
|
||||
const dispatcherDataStatus = storeData.dispatcherDataStatus;
|
||||
|
||||
|
||||
if (sceneryDataStatus == DataStatus.Error) {
|
||||
this.setSignalStatus(sceneryDataStatus);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<div class="train-table" @keydown.esc="closeTimetableCard">
|
||||
<transition name="anim" mode="out-in">
|
||||
<div :key="trainsDataStatus">
|
||||
<div class="traffic-warning" v-if="distanceLimitExceeded">
|
||||
<!-- <div class="traffic-warning" v-if="data.">
|
||||
{{ $t('trains.distance-exceeded') }}
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="table-info no-trains" v-if="trains.length == 0 && trainsDataStatus >= 2">
|
||||
{{ $t('trains.no-trains') }}
|
||||
|
||||
@@ -34,7 +34,7 @@ export const getStatusID = (stationStatus: any): string => {
|
||||
};
|
||||
|
||||
export const getStatusTimestamp = (stationStatus: any): number => {
|
||||
if (!stationStatus || stationStatus == -1) return -2;
|
||||
if (!stationStatus) return -2;
|
||||
|
||||
const statusCode = stationStatus[2];
|
||||
const statusTimestamp = stationStatus[3];
|
||||
|
||||
+16
-4
@@ -24,6 +24,8 @@ import StationRoutes from '@/scripts/interfaces/StationRoutes';
|
||||
export interface State {
|
||||
stationList: Station[],
|
||||
trainList: Train[],
|
||||
|
||||
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: string; }[],
|
||||
// timetableList: Timetable[],
|
||||
|
||||
sceneryData: any[][],
|
||||
@@ -75,6 +77,7 @@ export const store = createStore<State>({
|
||||
// timetableList: [],
|
||||
|
||||
sceneryData: [],
|
||||
lastDispatcherStatuses: [],
|
||||
|
||||
region: { id: "eu", value: "PL1" },
|
||||
|
||||
@@ -195,6 +198,7 @@ export const store = createStore<State>({
|
||||
}) || []
|
||||
|
||||
const onlineStationNames: string[] = [];
|
||||
const prevDispatcherStatuses: State['lastDispatcherStatuses'] = [];
|
||||
|
||||
stationsAPIData.message.forEach((stationAPI) => {
|
||||
if (stationAPI.region !== this.state.region.id || !stationAPI.isOnline) return;
|
||||
@@ -204,9 +208,17 @@ export const store = createStore<State>({
|
||||
const stationName = stationAPI.stationName.toLowerCase();
|
||||
const station = this.state.stationList.find(s => s.name == stationAPI.stationName);
|
||||
|
||||
const prevDispatcherStatus = this.state.lastDispatcherStatuses.find(dispatcher => dispatcher.hash === stationAPI.stationHash);
|
||||
const stationStatus = dispatchersAPIData.success ? dispatchersAPIData.message.find((status: string[]) => status[0] == stationAPI.stationHash && status[1] == this.state.region.id) : -1;
|
||||
const statusTimestamp = getStatusTimestamp(stationStatus);
|
||||
const statusID = getStatusID(stationStatus);
|
||||
|
||||
const statusTimestamp = getStatusTimestamp(stationStatus == -1 && prevDispatcherStatus ? prevDispatcherStatus.statusTimestamp : stationStatus);
|
||||
const statusID = getStatusID(stationStatus == -1 && prevDispatcherStatus ? prevDispatcherStatus.statusTimestamp : stationStatus );
|
||||
|
||||
prevDispatcherStatuses.push({
|
||||
hash: stationAPI.stationHash,
|
||||
statusID,
|
||||
statusTimestamp
|
||||
});
|
||||
|
||||
const stationTrains = trainsAPIData.response
|
||||
.filter(train => train.region === this.state.region.id && train.online && train.currentStationName === stationAPI.stationName)
|
||||
@@ -277,7 +289,6 @@ export const store = createStore<State>({
|
||||
statusTimestamp,
|
||||
statusID,
|
||||
scheduledTrains,
|
||||
// statusTimeString: timestampToString(statusTimestamp),
|
||||
}
|
||||
|
||||
if (!station) {
|
||||
@@ -298,9 +309,10 @@ export const store = createStore<State>({
|
||||
.forEach(offlineStation => {
|
||||
offlineStation.onlineInfo = undefined;
|
||||
});
|
||||
|
||||
|
||||
this.state.trainList = updatedTrainList;
|
||||
this.state.trainsDataStatus = DataStatus.Loaded;
|
||||
this.state.lastDispatcherStatuses = prevDispatcherStatuses;
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user