mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 22:08:12 +00:00
DEV: zmiana w pobieraniu danych z API
This commit is contained in:
+2
-1
@@ -102,6 +102,7 @@ import { StoreData } from './scripts/interfaces/StoreData';
|
|||||||
import { useStore } from './store';
|
import { useStore } from './store';
|
||||||
|
|
||||||
import packageInfo from '.././package.json';
|
import packageInfo from '.././package.json';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@@ -149,7 +150,7 @@ export default defineComponent({
|
|||||||
this.loadLang();
|
this.loadLang();
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
async mounted() {
|
||||||
if (StorageManager.getStringValue('version') != this.VERSION) {
|
if (StorageManager.getStringValue('version') != this.VERSION) {
|
||||||
StorageManager.setStringValue('version', this.VERSION);
|
StorageManager.setStringValue('version', this.VERSION);
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
v-if="Number(stationInfo.reqLevel) < 0"
|
v-if="stationInfo.reqLevel < 0"
|
||||||
:src="unknownIcon"
|
:src="unknownIcon"
|
||||||
alt="icon-unknown"
|
alt="icon-unknown"
|
||||||
:title="$t('desc.unknown')"
|
:title="$t('desc.unknown')"
|
||||||
|
|||||||
@@ -52,11 +52,9 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="station_level">
|
<td class="station_level">
|
||||||
<span v-if="station.reqLevel" :style="calculateExpStyle(station.reqLevel, station.supportersOnly)">
|
<span :style="calculateExpStyle(station.reqLevel, station.supportersOnly)">
|
||||||
{{ Number(station.reqLevel) > -1 ? (Number(station.reqLevel) >= 2 ? station.reqLevel : 'L') : '?' }}
|
{{ station.reqLevel > -1 ? (station.reqLevel >= 2 ? station.reqLevel : 'L') : '?' }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span v-else>?</span>
|
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="station_status">
|
<td class="station_status">
|
||||||
@@ -140,7 +138,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
v-if="station.nonPublic && Number(station.reqLevel) > -1"
|
v-if="station.nonPublic && station.reqLevel > -1"
|
||||||
:src="lockIcon"
|
:src="lockIcon"
|
||||||
alt="non-public"
|
alt="non-public"
|
||||||
:title="$t('desc.non-public')"
|
:title="$t('desc.non-public')"
|
||||||
@@ -154,7 +152,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
v-if="Number(station.reqLevel) < 0"
|
v-if="station.reqLevel < 0"
|
||||||
:src="unknownIcon"
|
:src="unknownIcon"
|
||||||
alt="icon-unknown"
|
alt="icon-unknown"
|
||||||
:title="$t('desc.unknown')"
|
:title="$t('desc.unknown')"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { defineComponent } from 'vue';
|
|||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
calculateExpStyle(exp: string | number, isSupporter = false): string {
|
calculateExpStyle(exp: number, isSupporter = false): string {
|
||||||
const bgColor = exp > -1 ? (exp < 2 ? '#26B0D9' : `hsl(${-exp * 5 + 100}, 85%, 50%)`) : '#666';
|
const bgColor = exp > -1 ? (exp < 2 ? '#26B0D9' : `hsl(${-exp * 5 + 100}, 85%, 50%)`) : '#666';
|
||||||
|
|
||||||
const fontColor = exp > 15 || exp == -1 ? 'white' : 'black';
|
const fontColor = exp > 15 || exp == -1 ? 'white' : 'black';
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default interface Station {
|
|||||||
stationLines: string;
|
stationLines: string;
|
||||||
stationProject: string;
|
stationProject: string;
|
||||||
|
|
||||||
reqLevel: string;
|
reqLevel: number;
|
||||||
supportersOnly: boolean;
|
supportersOnly: boolean;
|
||||||
|
|
||||||
SBL: string;
|
SBL: string;
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ import StorageManager from './storageManager';
|
|||||||
const sortStations = (a: Station, b: Station, sorter: { index: number; dir: number }) => {
|
const sortStations = (a: Station, b: Station, sorter: { index: number; dir: number }) => {
|
||||||
switch (sorter.index) {
|
switch (sorter.index) {
|
||||||
case 1:
|
case 1:
|
||||||
const aLevel = a.reqLevel == "" ? -1 : parseInt(a.reqLevel);
|
if (a.reqLevel > b.reqLevel) return sorter.dir;
|
||||||
const bLevel = b.reqLevel == "" ? -1 : parseInt(b.reqLevel);
|
if (a.reqLevel < b.reqLevel) return -sorter.dir;
|
||||||
|
|
||||||
if (aLevel > bLevel) return sorter.dir;
|
|
||||||
if (aLevel < bLevel) return -sorter.dir;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
@@ -85,9 +82,9 @@ const filterStations = (station: Station, filters: Filter) => {
|
|||||||
if (filters['real'] && station.stationLines != '') return returnMode;
|
if (filters['real'] && station.stationLines != '') return returnMode;
|
||||||
if (filters['fictional'] && station.stationLines == '') return returnMode;
|
if (filters['fictional'] && station.stationLines == '') return returnMode;
|
||||||
|
|
||||||
if (station.reqLevel == '-1') return true;
|
if (station.reqLevel == -1) return true;
|
||||||
if (parseInt(station.reqLevel) < filters['minLevel']) return returnMode;
|
if (station.reqLevel < filters['minLevel']) return returnMode;
|
||||||
if (parseInt(station.reqLevel) > filters['maxLevel']) return returnMode;
|
if (station.reqLevel > filters['maxLevel']) return returnMode;
|
||||||
|
|
||||||
if (filters['no-1track'] && (station.routes.oneWay.catenary != 0 || station.routes.oneWay.noCatenary != 0)) return returnMode;
|
if (filters['no-1track'] && (station.routes.oneWay.catenary != 0 || station.routes.oneWay.noCatenary != 0)) return returnMode;
|
||||||
if (filters['no-2track'] && (station.routes.twoWay.catenary != 0 || station.routes.twoWay.noCatenary != 0)) return returnMode;
|
if (filters['no-2track'] && (station.routes.twoWay.catenary != 0 || station.routes.twoWay.noCatenary != 0)) return returnMode;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const URLs = {
|
export const URLs = {
|
||||||
sceneryData: "https://spythere.github.io/api/stationData.json",
|
sceneryData: "https://spythere.github.io/api/stationData.json",
|
||||||
|
sceneryDataDev: "http://127.0.0.1:8000/data",
|
||||||
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",
|
||||||
|
|||||||
+98
-26
@@ -42,6 +42,28 @@ export interface State {
|
|||||||
listenerLaunched: boolean;
|
listenerLaunched: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SceneryData {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
project_lines: string;
|
||||||
|
project_name: string;
|
||||||
|
req_level?: number;
|
||||||
|
supporters_only: boolean;
|
||||||
|
signal_type: string;
|
||||||
|
control_type: string;
|
||||||
|
sbl_routes: string;
|
||||||
|
twb_routes: string;
|
||||||
|
track_oneway_e: number;
|
||||||
|
track_oneway_ne: number;
|
||||||
|
track_twoway_e: number;
|
||||||
|
track_twoway_ne: number;
|
||||||
|
checkpoints?: string;
|
||||||
|
is_default: boolean;
|
||||||
|
is_nonpublic: boolean;
|
||||||
|
is_unavailable: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export const key: InjectionKey<Store<State>> = Symbol()
|
export const key: InjectionKey<Store<State>> = Symbol()
|
||||||
|
|
||||||
export const store = createStore<State>({
|
export const store = createStore<State>({
|
||||||
@@ -107,8 +129,14 @@ export const store = createStore<State>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sceneryData = await (await axios.get(sceneryDataQuery)).data;
|
const sceneryData = await (await axios.get(sceneryDataQuery)).data;
|
||||||
|
// const sceneryData = await (await axios.get(sceneryDataQuery)).data;
|
||||||
|
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA, sceneryData);
|
const sceneryData2 = await (await axios.get('http://127.0.0.1:8000/data')).data;
|
||||||
|
console.log(sceneryData2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
commit(MUTATIONS.SET_SCENERY_DATA, sceneryData2);
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
||||||
|
|
||||||
dispatch(ACTIONS.fetchOnlineData);
|
dispatch(ACTIONS.fetchOnlineData);
|
||||||
@@ -122,8 +150,6 @@ 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;
|
||||||
@@ -291,35 +317,37 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SCENERY_DATA(state, data: any[][]) {
|
SET_SCENERY_DATA(state, data: SceneryData[]) {
|
||||||
state.sceneryData = [...data];
|
// state.sceneryData = [...data];
|
||||||
|
console.log('Data:', data);
|
||||||
|
|
||||||
state.stationList = data.map(station => ({
|
|
||||||
stationName: station[0] as string,
|
state.stationList = data.map(scenery => ({
|
||||||
stationURL: station[1] as string,
|
stationName: scenery.name,
|
||||||
stationLines: station[2] as string,
|
stationURL: scenery.url,
|
||||||
stationProject: station[3] as string,
|
stationLines: scenery.project_lines,
|
||||||
reqLevel: station[4] as string,
|
stationProject: scenery.project_name,
|
||||||
supportersOnly: station[5] == "TAK",
|
reqLevel: scenery.req_level === undefined ? -1 : scenery.req_level,
|
||||||
signalType: station[6] as string,
|
supportersOnly: scenery.supporters_only,
|
||||||
controlType: station[7] as string,
|
signalType: scenery.signal_type,
|
||||||
SBL: station[8] as string,
|
controlType: scenery.control_type,
|
||||||
TWB: station[9] as string,
|
SBL: scenery.sbl_routes,
|
||||||
|
TWB: scenery.twb_routes,
|
||||||
routes: {
|
routes: {
|
||||||
oneWay: {
|
oneWay: {
|
||||||
catenary: station[10] as number,
|
catenary: scenery.track_oneway_e,
|
||||||
noCatenary: station[11] as number
|
noCatenary: scenery.track_oneway_ne
|
||||||
},
|
},
|
||||||
twoWay: {
|
twoWay: {
|
||||||
catenary: station[12] as number,
|
catenary: scenery.track_twoway_e,
|
||||||
noCatenary: station[13] as number
|
noCatenary: scenery.track_twoway_ne
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkpoints: station[14] ? (station[14] as string).split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
|
checkpoints: scenery.checkpoints ? scenery.checkpoints.split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
|
||||||
|
|
||||||
default: station[15] as boolean,
|
default: scenery.is_default,
|
||||||
nonPublic: station[16] as boolean,
|
nonPublic: scenery.is_nonpublic,
|
||||||
unavailable: station[17] as boolean,
|
unavailable: scenery.is_unavailable,
|
||||||
|
|
||||||
stationHash: "",
|
stationHash: "",
|
||||||
maxUsers: 0,
|
maxUsers: 0,
|
||||||
@@ -338,6 +366,50 @@ export const store = createStore<State>({
|
|||||||
spawns: []
|
spawns: []
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// state.stationList = data.map(station => ({
|
||||||
|
// stationName: station[0] as string,
|
||||||
|
// stationURL: station[1] as string,
|
||||||
|
// stationLines: station[2] as string,
|
||||||
|
// stationProject: station[3] as string,
|
||||||
|
// reqLevel: station[4] as string,
|
||||||
|
// supportersOnly: station[5] == "TAK",
|
||||||
|
// signalType: station[6] as string,
|
||||||
|
// controlType: station[7] as string,
|
||||||
|
// SBL: station[8] as string,
|
||||||
|
// TWB: station[9] as string,
|
||||||
|
// routes: {
|
||||||
|
// oneWay: {
|
||||||
|
// catenary: station[10] as number,
|
||||||
|
// noCatenary: station[11] as number
|
||||||
|
// },
|
||||||
|
// twoWay: {
|
||||||
|
// catenary: station[12] as number,
|
||||||
|
// noCatenary: station[13] as number
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// checkpoints: station[14] ? (station[14] as string).split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
|
||||||
|
|
||||||
|
// default: station[15] as boolean,
|
||||||
|
// nonPublic: station[16] as boolean,
|
||||||
|
// unavailable: station[17] as boolean,
|
||||||
|
|
||||||
|
// stationHash: "",
|
||||||
|
// maxUsers: 0,
|
||||||
|
// currentUsers: 0,
|
||||||
|
// dispatcherName: "",
|
||||||
|
// dispatcherRate: 0,
|
||||||
|
// dispatcherExp: -1,
|
||||||
|
// dispatcherId: 0,
|
||||||
|
// dispatcherIsSupporter: false,
|
||||||
|
// online: false,
|
||||||
|
// statusTimestamp: -3,
|
||||||
|
// statusID: "free",
|
||||||
|
// statusTimeString: "",
|
||||||
|
// stationTrains: [],
|
||||||
|
// scheduledTrains: [],
|
||||||
|
// spawns: []
|
||||||
|
// }));
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -361,7 +433,7 @@ export const store = createStore<State>({
|
|||||||
|
|
||||||
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 = state.sceneryData.find(data => data[0] === station.stationName);
|
const listedStationData = state.stationList.find(data => data.stationName === station.stationName);
|
||||||
|
|
||||||
if (onlineStationData)
|
if (onlineStationData)
|
||||||
acc.push({
|
acc.push({
|
||||||
@@ -400,7 +472,7 @@ export const store = createStore<State>({
|
|||||||
stationTrains: uStation.stationTrains || [],
|
stationTrains: uStation.stationTrains || [],
|
||||||
subStations: [],
|
subStations: [],
|
||||||
online: true,
|
online: true,
|
||||||
reqLevel: "-1",
|
reqLevel: -1,
|
||||||
nonPublic: true
|
nonPublic: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user