diff --git a/src/assets/sound.wav b/src/assets/sound.wav deleted file mode 100644 index 920d6fd..0000000 Binary files a/src/assets/sound.wav and /dev/null differ diff --git a/src/router/index.ts b/src/router/index.ts index 6090d83..144492e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -18,12 +18,6 @@ const routes: Array = [ component: TrainsView, props: true, }, - { - path: '/timetable', - name: 'TimetableView', - component: () => import('@/views/TimetableView.vue'), - props: true, - }, { path: '/scenery', name: 'SceneryView', diff --git a/src/scripts/interfaces/ISceneryInfoData.ts b/src/scripts/interfaces/ISceneryInfoData.ts new file mode 100644 index 0000000..1ee10ec --- /dev/null +++ b/src/scripts/interfaces/ISceneryInfoData.ts @@ -0,0 +1,33 @@ +interface ISceneryInfoData { + stationName: string; + stationURL: string; + stationLines: string; + stationProject: string; + + reqLevel: string; + supportersOnly: string; + signalType: string; + controlType: string; + SBL: string; + twoWayBlock: string; + + routesOneWayCatenary: number; + routesOneWayOther: number; + routesTwoWayCatenary: number; + routesToWayOther: number; + + default: boolean; + nonPublic: boolean; + unavailable: boolean; + hasData: boolean; + + stops: string[]; + checkpoints: string[]; + + currentDispatcher: string; + currentDispatcherId: number; + currentDispatcherFrom: number; + dispatcherHistory: { dispatcherName: string; dispatcherId: number; dispatcherFrom: number; dispatcherTo: number }[]; +} + +export default ISceneryInfoData; diff --git a/src/store/store.ts b/src/store/store.ts index c17481f..03d3c2a 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -14,7 +14,7 @@ enum Status { Loaded = 2, } -interface TimetableData { +interface ITimetableData { trainNo: number; driverName: string; driverId: number; @@ -30,8 +30,6 @@ interface TimetableData { followingSceneries: string[]; } -// const devEnv = true; - const URLs = { stations: 'https://api.td2.info.pl:9640/?method=getStationsOnline', trains: 'https://api.td2.info.pl:9640/?method=getTrainsOnline', @@ -123,6 +121,7 @@ export default class Store extends VuexModule { private stationCount: number = 0; private dataConnectionStatus: Status = Status.Loading; + private sceneryDataStatus: Status = Status.Loading; private timetableLoaded: Status = Status.Loading; private stationList: Station[] = []; @@ -155,11 +154,31 @@ export default class Store extends VuexModule { get getDataStatus() { return this.dataConnectionStatus; } + get getSceneryDataStatus() { + return this.sceneryDataStatus; + } //ACTIONS @Action async synchronizeData() { - this.context.commit('setJSONData'); + // axios + // .get(URLs.sceneryInfo) + // .then(response => { + // const data: ISceneryInfoData[] = response.data; + + // this.context.commit('setSceneryData', data); + // this.context.commit('setSceneryDataStatus', Status.Loaded); + + // this.context.dispatch('fetchOnlineData'); + // setInterval(() => this.context.dispatch('fetchOnlineData'), 20000); + // }) + // .catch(err => { + // this.context.commit('setSceneryDataStatus', Status.Error); + // console.error('Ups! Coś poszło nie tak!', err); + // }); + + this.context.commit('setSceneryData'); + this.context.commit('setSceneryDataStatus', Status.Loaded); this.context.dispatch('fetchOnlineData'); setInterval(() => this.context.dispatch('fetchOnlineData'), 20000); @@ -167,7 +186,7 @@ export default class Store extends VuexModule { @Action({ commit: 'updateTimetableData' }) async fetchTimetableData() { - return this.trainList.reduce(async (acc: Promise, train) => { + return this.trainList.reduce(async (acc: Promise, train) => { const timetable = await (await axios.get(timetableURL(train.trainNo))).data.message; const trainInfo = timetable.trainInfo; @@ -309,7 +328,13 @@ export default class Store extends VuexModule { this.dataConnectionStatus = status; } - @Mutation setJSONData() { + @Mutation + private setSceneryDataStatus(status: Status) { + this.sceneryDataStatus = status; + } + + @Mutation + private setSceneryData() { /* 0: stationName, 1: stationURL, @@ -377,6 +402,54 @@ export default class Store extends VuexModule { })); } + // @Mutation setSceneryData(data: ISceneryInfoData[]) { + // this.sceneryData = data; + + // this.stationList = data.map(scenery => ({ + // stationName: scenery.stationName, + // stationURL: scenery.stationURL, + // stationLines: scenery.stationLines, + // stationProject: scenery.stationProject, + // reqLevel: scenery.reqLevel, + // supportersOnly: scenery.supportersOnly, + // signalType: scenery.signalType, + // controlType: scenery.controlType, + // SBL: scenery.SBL, + // TWB: scenery.twoWayBlock, + // routes: { + // oneWay: { + // catenary: scenery.routesOneWayCatenary, + // noCatenary: scenery.routesOneWayOther, + // }, + // twoWay: { + // catenary: scenery.routesTwoWayCatenary, + // noCatenary: scenery.routesToWayOther, + // }, + // }, + // checkpoints: scenery.checkpoints.length ? scenery.checkpoints.map(cp => ({ checkpointName: cp, scheduledTrains: [] })) : null, + // stops: scenery.stops, + + // default: scenery.default, + // nonPublic: scenery.nonPublic, + // unavailable: scenery.unavailable, + + // stationHash: '', + // maxUsers: 0, + // currentUsers: 0, + // dispatcherName: '', + // dispatcherRate: 0, + // dispatcherExp: -1, + // dispatcherId: 0, + // dispatcherIsSupporter: false, + // online: false, + // occupiedTo: 'WOLNA', + // statusTimestamp: -3, + // stationTrains: [], + // scheduledTrains: [], + // spawns: [], + // })); + // } + @Mutation private updateOnlineStations(updatedStationList: any[]) { this.stationList = this.stationList.reduce((acc, station) => { @@ -426,25 +499,6 @@ export default class Store extends VuexModule { }); }); - // Dodawanie do listy online potencjalnych scenerii niewpisanych do bazy - // updatedStationList.forEach(updatedStation => { - // const alreadyInList: any = this.stationList.some(station => station.stationName === updatedStation.stationName); - - // console.log(updatedStation, alreadyInList); - - // if (!alreadyInList) { - // this.stationList.push({ - // ...updatedStation, - // scheduledTrains: [], - // stationTrains: [], - // subStations: [], - // online: true, - // reqLevel: '-1', - // nonPublic: true, - // }); - // } - // }); - this.stationCount = this.stationList.filter(station => station.online).length; this.dataConnectionStatus = Status.Loaded; } @@ -465,10 +519,10 @@ export default class Store extends VuexModule { } @Mutation - private updateTimetableData(timetableList: TimetableData[]) { + private updateTimetableData(timetableList: ITimetableData[]) { this.stationList = this.stationList.map(station => { const stationName = station.stationName.toLowerCase(); - const scheduledTrains: Station['scheduledTrains'] = timetableList.reduce((acc: Station['scheduledTrains'], timetableData: TimetableData, index) => { + const scheduledTrains: Station['scheduledTrains'] = timetableList.reduce((acc: Station['scheduledTrains'], timetableData: ITimetableData, index) => { if (!timetableData.followingSceneries.includes(station.stationHash)) return acc; const stopInfoIndex = timetableData.followingStops.findIndex(stop => { diff --git a/src/views/HistoryView.vue b/src/views/HistoryView.vue index 8c79417..919e7f2 100644 --- a/src/views/HistoryView.vue +++ b/src/views/HistoryView.vue @@ -26,7 +26,7 @@
-
    +
    • {{ currentDispatcher}} @@ -67,41 +67,30 @@ import { Component, Vue, Watch } from "vue-property-decorator"; import { Getter } from "vuex-class"; import Station from "@/scripts/interfaces/Station"; - -interface ISceneryHistory { - _id: string; - stationHash: string; - stationName: string; - currentDispatcher: string; - currentDispatcherId: number; - currentDispatcherFrom: number; - currentDispatcherTo: number; - dispatcherHistory: { - dispatcherName: string; - dispatcherFrom: number; - dispatcherId: number; - dispatcherTo: number; - }[]; -} +import ISceneryInfoData from "@/scripts/interfaces/ISceneryInfoData"; @Component export default class HistoryView extends Vue { @Getter("getStationList") stationList!: Station[]; - sceneryHistoryList: ISceneryHistory[] = []; + sceneryHistoryList: ISceneryInfoData[] = []; + currentSceneryHistory: ISceneryInfoData["dispatcherHistory"] = []; - currentSceneryHistory: ISceneryHistory["dispatcherHistory"] = []; currentDispatcher: string = ""; currentDispatcherId: number = 0; currentDispatcherFrom: number = -1; inputStationName = ""; - dataLoading = true; + + dataLoading = true; /* Initial data */ + historyLoading = false; /* History loaded after input is checked */ async mounted() { try { - const responseData: ISceneryHistory[] = await ( - await axios.get("https://stacjownik.herokuapp.com/api/getSceneryInfo") + const responseData: ISceneryInfoData[] = await ( + await axios.get( + "https://stacjownik.herokuapp.com/api/getSceneryInfo?items=-1" + ) ).data; this.sceneryHistoryList = responseData; @@ -147,17 +136,25 @@ export default class HistoryView extends Vue { .reverse(); } - itemSelected(itemName: string) { - const selectedScenery = this.sceneryHistoryList.find( - (scenery) => scenery.stationName == itemName - ); + async itemSelected(itemName: string) { + try { + this.historyLoading = true; - if (!selectedScenery) return; + const selectedScenery: ISceneryInfoData = await ( + await axios.get( + `https://stacjownik.herokuapp.com/api/getSceneryInfo?name=${itemName}&items=10` + ) + ).data; - this.currentSceneryHistory = selectedScenery.dispatcherHistory; - this.currentDispatcher = selectedScenery.currentDispatcher; - this.currentDispatcherId = selectedScenery.currentDispatcherId; - this.currentDispatcherFrom = selectedScenery.currentDispatcherFrom; + this.currentSceneryHistory = selectedScenery.dispatcherHistory; + this.currentDispatcher = selectedScenery.currentDispatcher; + this.currentDispatcherId = selectedScenery.currentDispatcherId; + this.currentDispatcherFrom = selectedScenery.currentDispatcherFrom; + } catch (error) { + console.error(error); + } + + this.historyLoading = false; } } @@ -278,7 +275,7 @@ export default class HistoryView extends Vue { } &_content { - max-height: 550px; + max-height: 600px; overflow: auto; padding: 0.2em 0.5em; diff --git a/src/views/TimetableView.vue b/src/views/TimetableView.vue deleted file mode 100644 index 4469712..0000000 --- a/src/views/TimetableView.vue +++ /dev/null @@ -1,770 +0,0 @@ - - - - - \ No newline at end of file