mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 22:08:12 +00:00
Plik z danymi przerzucono do API
This commit is contained in:
@@ -20,7 +20,7 @@ export const GETTERS = {
|
|||||||
trainList: "trainList",
|
trainList: "trainList",
|
||||||
allData: "allData",
|
allData: "allData",
|
||||||
timetableDataStatus: "timetableDataStatus",
|
timetableDataStatus: "timetableDataStatus",
|
||||||
sceneryDataStatus: "sceneryDataStatus",
|
sceneryDataStatus: "sceneryDataStatus",
|
||||||
dataStatus: "dataStatus",
|
dataStatus: "dataStatus",
|
||||||
currentRegion: "currentRegion"
|
currentRegion: "currentRegion"
|
||||||
}
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
|||||||
export const URLs = {
|
export const URLs = {
|
||||||
|
sceneryData: "https://spythere.github.io/api/stationData.json",
|
||||||
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
||||||
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
||||||
dispatchers: "https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1",
|
dispatchers: "https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1",
|
||||||
|
|||||||
+28
-14
@@ -5,7 +5,7 @@ import { createStore, useStore as baseUseStore, Store } from 'vuex'
|
|||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import JSONStationData from "@/data/stationData.json";
|
// import JSONStationData from "@/data/stationData.json";
|
||||||
|
|
||||||
import Station from "@/scripts/interfaces/Station";
|
import Station from "@/scripts/interfaces/Station";
|
||||||
import Train from "@/scripts/interfaces/Train";
|
import Train from "@/scripts/interfaces/Train";
|
||||||
@@ -27,7 +27,9 @@ import { URLs } from '@/scripts/utils/apiURLs';
|
|||||||
export interface State {
|
export interface State {
|
||||||
stationList: Station[],
|
stationList: Station[],
|
||||||
trainList: Train[],
|
trainList: Train[],
|
||||||
|
|
||||||
|
sceneryData: any[][],
|
||||||
|
|
||||||
region: { id: string; value: string };
|
region: { id: string; value: string };
|
||||||
trainCount: number;
|
trainCount: number;
|
||||||
stationCount: number;
|
stationCount: number;
|
||||||
@@ -46,8 +48,10 @@ export const store = createStore<State>({
|
|||||||
stationList: [],
|
stationList: [],
|
||||||
trainList: [],
|
trainList: [],
|
||||||
|
|
||||||
|
sceneryData: [],
|
||||||
|
|
||||||
region: { id: "eu", value: "PL1" },
|
region: { id: "eu", value: "PL1" },
|
||||||
|
|
||||||
trainCount: 0,
|
trainCount: 0,
|
||||||
stationCount: 0,
|
stationCount: 0,
|
||||||
|
|
||||||
@@ -75,13 +79,15 @@ export const store = createStore<State>({
|
|||||||
sceneryDataStatus: (state): DataStatus => state.sceneryDataStatus,
|
sceneryDataStatus: (state): DataStatus => state.sceneryDataStatus,
|
||||||
dataStatus: (state): DataStatus => state.dataConnectionStatus,
|
dataStatus: (state): DataStatus => state.dataConnectionStatus,
|
||||||
currentRegion: (state): { id: string; value: string } => state.region
|
currentRegion: (state): { id: string; value: string } => state.region
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async synchronizeData({ commit, dispatch, state }) {
|
async synchronizeData({ commit, dispatch, state }) {
|
||||||
if(state.listenerLaunched) return;
|
if (state.listenerLaunched) return;
|
||||||
|
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA);
|
const sceneryData = await (await axios.get(URLs.sceneryData + "?time=" + Date.now())).data;
|
||||||
|
|
||||||
|
commit(MUTATIONS.SET_SCENERY_DATA, sceneryData);
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
||||||
|
|
||||||
dispatch(ACTIONS.fetchOnlineData);
|
dispatch(ACTIONS.fetchOnlineData);
|
||||||
@@ -92,12 +98,15 @@ export const store = createStore<State>({
|
|||||||
async fetchOnlineData({ commit, dispatch }) {
|
async fetchOnlineData({ commit, dispatch }) {
|
||||||
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loading);
|
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loading);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Promise.all([axios.get(URLs.stations), axios.get(URLs.trains), axios.get(URLs.dispatchers)])
|
Promise.all([axios.get(URLs.stations), axios.get(URLs.trains), axios.get(URLs.dispatchers)])
|
||||||
.then(async response => {
|
.then(async response => {
|
||||||
const onlineStationsData: StationAPIData[] = response[0].data.message;
|
const onlineStationsData: StationAPIData[] = response[0].data.message;
|
||||||
const onlineTrainsData: TrainAPIData[] = await response[1].data.message;
|
const onlineTrainsData: TrainAPIData[] = await response[1].data.message;
|
||||||
const onlineDispatchersData: string[][] = await response[2].data.message;
|
const onlineDispatchersData: string[][] = await response[2].data.message;
|
||||||
|
|
||||||
|
|
||||||
const updatedStationList = onlineStationsData.reduce((acc, station) => {
|
const updatedStationList = onlineStationsData.reduce((acc, station) => {
|
||||||
if (station.region !== this.state.region.id || !station.isOnline) return acc;
|
if (station.region !== this.state.region.id || !station.isOnline) return acc;
|
||||||
|
|
||||||
@@ -242,8 +251,10 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SCENERY_DATA(state) {
|
SET_SCENERY_DATA(state, data: any[][]) {
|
||||||
state.stationList = JSONStationData.map(station => ({
|
state.sceneryData = [...data];
|
||||||
|
|
||||||
|
state.stationList = data.map(station => ({
|
||||||
stationName: station[0] as string,
|
stationName: station[0] as string,
|
||||||
stationURL: station[1] as string,
|
stationURL: station[1] as string,
|
||||||
stationLines: station[2] as string,
|
stationLines: station[2] as string,
|
||||||
@@ -286,6 +297,8 @@ export const store = createStore<State>({
|
|||||||
scheduledTrains: [],
|
scheduledTrains: [],
|
||||||
spawns: []
|
spawns: []
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
||||||
@@ -305,9 +318,10 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
UPDATE_STATIONS(state, updatedStationList: any[]) {
|
UPDATE_STATIONS(state, updatedStationList: any[]) {
|
||||||
|
|
||||||
state.stationList = state.stationList.reduce((acc: Station[], station) => {
|
state.stationList = state.stationList.reduce((acc: Station[], station) => {
|
||||||
const onlineStationData = updatedStationList.find(updatedStation => updatedStation.stationName === station.stationName);
|
const onlineStationData = updatedStationList.find(updatedStation => updatedStation.stationName === station.stationName);
|
||||||
const listedStationData = JSONStationData.find(data => data[0] === station.stationName);
|
const listedStationData = state.sceneryData.find(data => data[0] === station.stationName);
|
||||||
|
|
||||||
if (onlineStationData)
|
if (onlineStationData)
|
||||||
acc.push({
|
acc.push({
|
||||||
@@ -353,7 +367,7 @@ export const store = createStore<State>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
state.stationCount = state.stationList.filter(station => station.online).length;
|
state.stationCount = state.stationList.filter(station => station.online).length;
|
||||||
state.dataConnectionStatus = DataStatus.Loaded;
|
state.dataConnectionStatus = DataStatus.Loaded;
|
||||||
},
|
},
|
||||||
|
|
||||||
UPDATE_TRAINS(state, updatedTrainList: any[]) {
|
UPDATE_TRAINS(state, updatedTrainList: any[]) {
|
||||||
@@ -379,9 +393,9 @@ export const store = createStore<State>({
|
|||||||
|
|
||||||
const stopInfoIndex = timetable.followingStops.findIndex(stop => {
|
const stopInfoIndex = timetable.followingStops.findIndex(stop => {
|
||||||
const stopName = stop.stopNameRAW.toLowerCase();
|
const stopName = stop.stopNameRAW.toLowerCase();
|
||||||
|
|
||||||
|
|
||||||
if (stationName === stopName) return true;
|
|
||||||
|
if (stationName === stopName) return true;
|
||||||
if (stopName.includes(stationName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
if (stopName.includes(stationName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
||||||
if (stationName.includes(stopName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
if (stationName.includes(stopName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
||||||
if (stopName.includes("podg.") && stopName.split(", podg.")[0] && stationName.includes(stopName.split(", podg.")[0])) return true;
|
if (stopName.includes("podg.") && stopName.split(", podg.")[0] && stationName.includes(stopName.split(", podg.")[0])) return true;
|
||||||
@@ -462,7 +476,7 @@ export const store = createStore<State>({
|
|||||||
return acc;
|
return acc;
|
||||||
}, [] as Train[]);
|
}, [] as Train[]);
|
||||||
|
|
||||||
state.timetableDataStatus = DataStatus.Loaded;
|
state.timetableDataStatus = DataStatus.Loaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user