diff --git a/src/App.vue b/src/App.vue index 6d15145..e9dab73 100644 --- a/src/App.vue +++ b/src/App.vue @@ -10,7 +10,7 @@
- + diff --git a/src/components/JournalView/JournalDispatcherStats.vue b/src/components/JournalView/JournalDispatchers/JournalDispatcherStats.vue similarity index 94% rename from src/components/JournalView/JournalDispatcherStats.vue rename to src/components/JournalView/JournalDispatchers/JournalDispatcherStats.vue index cc40d74..3c09fcd 100644 --- a/src/components/JournalView/JournalDispatcherStats.vue +++ b/src/components/JournalView/JournalDispatchers/JournalDispatcherStats.vue @@ -61,8 +61,8 @@ diff --git a/src/components/JournalView/JournalDispatchersList.vue b/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue similarity index 91% rename from src/components/JournalView/JournalDispatchersList.vue rename to src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue index 45708fa..b71fa2e 100644 --- a/src/components/JournalView/JournalDispatchersList.vue +++ b/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue @@ -123,15 +123,15 @@ diff --git a/src/router/index.ts b/src/router/index.ts index c76dcad..69a894c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -37,21 +37,12 @@ const routes: Array = [ { path: '/journal/timetables', name: 'JournalTimetables', - component: JournalTimetablesVue, - props: (route) => ({ - trainNo: route.query.trainNo, - driverName: route.query.driverName, - timetableId: route.query.timetableId - }) + component: JournalTimetablesVue }, { path: '/journal/dispatchers', name: 'JournalDispatchers', - component: JournalDispatchersVue, - props: (route) => ({ - sceneryName: route.query.sceneryName, - dispatcherName: route.query.dispatcherName - }) + component: JournalDispatchersVue }, { path: '/:catchAll(.*)', diff --git a/src/store/mainStore.ts b/src/store/mainStore.ts index 56db71f..3dffad6 100644 --- a/src/store/mainStore.ts +++ b/src/store/mainStore.ts @@ -9,6 +9,7 @@ import { Status } from '../typings/common'; import Station from '../scripts/interfaces/Station'; import { useApiStore } from './apiStore'; import { API } from '../typings/api'; +import http from '../http'; export const useMainStore = defineStore('store', { state: () => @@ -18,7 +19,6 @@ export const useMainStore = defineStore('store', { isOffline: false, dispatcherStatsName: '', - dispatcherStatsData: undefined, dispatcherStatsStatus: Status.Data.Initialized, driverStatsName: '', diff --git a/src/views/JournalDispatchers.vue b/src/views/JournalDispatchers.vue index e157ead..db9b1a3 100644 --- a/src/views/JournalDispatchers.vue +++ b/src/views/JournalDispatchers.vue @@ -44,8 +44,8 @@ import { Journal } from '../components/JournalView/typings'; import { API } from '../typings/api'; import { Status } from '../typings/common'; +import JournalDispatchersList from '../components/JournalView/JournalDispatchers/JournalDispatchersList.vue'; import JournalOptions from '../components/JournalView/JournalOptions.vue'; -import JournalDispatchersList from '../components/JournalView/JournalDispatchersList.vue'; import JournalHeader from '../components/JournalView/JournalHeader.vue'; import JournalStats from '../components/JournalView/JournalStats.vue'; @@ -61,9 +61,9 @@ const statsButtons: Journal.StatsButton[] = [ export default defineComponent({ components: { JournalOptions, - JournalDispatchersList, JournalHeader, - JournalStats + JournalStats, + JournalDispatchersList }, name: 'JournalDispatchers', @@ -142,6 +142,10 @@ export default defineComponent({ 'mainStore.dispatcherStatsData'(stats) { this.statsButtons.find((sb) => sb.tab == Journal.StatsTab.DISPATCHER_STATS)!.disabled = stats === undefined; + }, + + async 'mainStore.dispatcherStatsName'() { + this.fetchDispatcherStats(); } }, @@ -189,6 +193,29 @@ export default defineComponent({ this.setOptions(query as any); }, + async fetchDispatcherStats() { + if (!this.mainStore.dispatcherStatsName) { + this.mainStore.dispatcherStatsData = undefined; + return; + } + + try { + const statsData: API.DispatcherStats.Response = await ( + await http.get('api/getDispatcherStats', { + params: { + name: this.mainStore.dispatcherStatsName + } + }) + ).data; + + this.mainStore.dispatcherStatsData = statsData; + } catch (error) { + this.mainStore.dispatcherStatsData = undefined; + + console.error('Ups! Wystąpił błąd przy próbie pobrania statystyk dyżurnego! :/'); + } + }, + setOptions(searchers: { [key: string]: string }) { this.searchersValues['search-date'] = searchers['search-date'] ?? ''; this.searchersValues['search-station'] = searchers['search-station'] ?? ''; @@ -198,8 +225,6 @@ export default defineComponent({ resetOptions() { this.setOptions({}); this.sorterActive.id = 'timestampFrom'; - - this.fetchHistoryData(); }, async addHistoryData() { diff --git a/src/views/JournalTimetables.vue b/src/views/JournalTimetables.vue index f7b757b..b9c9f14 100644 --- a/src/views/JournalTimetables.vue +++ b/src/views/JournalTimetables.vue @@ -5,7 +5,6 @@
sb.tab == Journal.StatsTab.DRIVER_STATS)!.disabled = driverStats === undefined; + }, + + async 'mainStore.driverStatsName'() { + this.fetchDriverStats(); } }, @@ -249,10 +256,6 @@ export default defineComponent({ }, methods: { - onSearchConfirm() { - this.fetchHistoryData(); - }, - handleScroll(e: Event) { const listElement = e.target as HTMLElement; const scrollTop = listElement.scrollTop; @@ -268,6 +271,29 @@ export default defineComponent({ this.setOptions(query as any); }, + async fetchDriverStats() { + if (!this.mainStore.driverStatsName) { + this.mainStore.driverStatsData = undefined; + this.mainStore.driverStatsStatus = Status.Data.Initialized; + return; + } + + try { + this.mainStore.driverStatsStatus = Status.Data.Loading; + + const statsData: API.DriverStats.Response = await ( + await http.get(`api/getDriverInfo?name=${this.mainStore.driverStatsName}`) + ).data; + + this.mainStore.driverStatsData = statsData; + this.mainStore.driverStatsStatus = Status.Data.Loaded; + } catch (error) { + this.mainStore.driverStatsData = undefined; + this.mainStore.driverStatsStatus = Status.Data.Error; + console.error('Ups! Wystąpił błąd przy próbie pobrania statystyk maszynisty! :/'); + } + }, + setOptions(options: { [key: string]: string }) { this.searchersValues['search-date'] = options['search-date'] ?? ''; this.searchersValues['search-driver'] = options['search-driver'] ?? ''; @@ -287,17 +313,6 @@ export default defineComponent({ resetOptions() { this.setOptions({}); - - // this.sorterActive.id = 'timetableId'; - - // this.filterList.forEach( - // (f) => - // (f.isActive = - // this.initFilters.find((initFilter) => initFilter.id == f.id)?.isActive || false) - // ); - - // this.handleRouteParams(); - this.fetchHistoryData(); }, async addHistoryData() { @@ -326,13 +341,19 @@ export default defineComponent({ const driverName = this.searchersValues['search-driver'].trim() || undefined; const trainNo = this.searchersValues['search-train'].trim() || undefined; const authorName = this.searchersValues['search-dispatcher'].trim() || undefined; - const dateString = this.searchersValues['search-date'].trim() || undefined; + const dateFrom = this.searchersValues['search-date'].trim() || undefined; const issuedFrom = this.searchersValues['search-issuedFrom'].trim() || undefined; - const timestampFrom = dateString - ? Date.parse(new Date(dateString).toISOString()) - 120 * 60 * 1000 - : undefined; - const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined; + let dateTo: string | undefined = undefined; + + if (dateFrom) { + const d = new Date(dateFrom); + d.setDate(d.getDate() + 1); + + dateTo = d.toISOString().split('T')[0]; + } + // const timestampFrom = dateString ? Date.parse(new Date(dateString).toISOString()) : undefined; + // const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined; const queryParams: TimetablesQueryParams = {}; @@ -367,7 +388,7 @@ export default defineComponent({ case Journal.TimetableFilterId.TWR: queryParams['twr'] = 1; - queryParams['skr'] = undefined; + queryParams['skr'] = 0; break; case Journal.TimetableFilterId.SKR: @@ -391,8 +412,8 @@ export default defineComponent({ queryParams['countLimit'] = undefined; queryParams['authorName'] = authorName; - queryParams['timestampFrom'] = timestampFrom; - queryParams['timestampTo'] = timestampTo; + queryParams['dateFrom'] = dateFrom; + queryParams['dateTo'] = dateTo; queryParams['issuedFrom'] = issuedFrom; queryParams['sortBy'] = this.sorterActive.id != 'timetableId' ? this.sorterActive.id : undefined;