diff --git a/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue b/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue index 91942e0..979a407 100644 --- a/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue +++ b/src/components/JournalView/JournalDispatchers/JournalDispatchersList.vue @@ -1,43 +1,45 @@ - - {{ $t('app.offline') }} - + + + {{ $t('app.offline') }} + - + - - {{ $t('app.error') }} - + + {{ $t('app.error') }} + - - {{ $t('app.no-result') }} - + + {{ $t('app.no-result') }} + - - - + + + + + - + - - + + {{ $t('journal.no-further-data') }} + - - {{ $t('journal.no-further-data') }} - - - - {{ $t('journal.loading-further-data') }} + + {{ $t('journal.loading-further-data') }} + @@ -81,6 +83,15 @@ export default defineComponent({ }; }, + watch: { + '$route.query': { + deep: true, + handler() { + this.extraInfoIndexes.length = 0; + } + } + }, + methods: { toggleExtraInfo(id: number) { const existingIdx = this.extraInfoIndexes.indexOf(id); diff --git a/src/components/JournalView/JournalTimetables/JournalTimetablesList.vue b/src/components/JournalView/JournalTimetables/JournalTimetablesList.vue index 56ddccd..29ff2a8 100644 --- a/src/components/JournalView/JournalTimetables/JournalTimetablesList.vue +++ b/src/components/JournalView/JournalTimetables/JournalTimetablesList.vue @@ -94,6 +94,7 @@ export default defineComponent({ } } }, + methods: { toggleExtraInfo(id: number) { const existingIdx = this.extraInfoIndexes.indexOf(id); diff --git a/src/components/JournalView/typings.ts b/src/components/JournalView/typings.ts index ea6184a..4e3785f 100644 --- a/src/components/JournalView/typings.ts +++ b/src/components/JournalView/typings.ts @@ -19,7 +19,7 @@ export namespace Journal { }; export type TimetableSorterKey = 'timetableId' | 'beginDate' | 'distance' | 'total-stops'; - export type DispatcherSorterKey = 'timestampFrom' | 'duration'; + export type DispatcherSorterKey = 'timestampFrom' | 'currentDuration'; export interface DispatcherSorter { id: DispatcherSorterKey; diff --git a/src/locales/en.json b/src/locales/en.json index 2f78992..efd54f6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -193,7 +193,7 @@ "sort-beginDate": "date", "sort-timetableId": "timetable ID", "sort-timestampFrom": "date", - "sort-duration": "duration", + "sort-currentDuration": "duration", "filter-noComments": "NO COMMENTS", "filter-withComments": "COMMENTS", diff --git a/src/locales/pl.json b/src/locales/pl.json index 268c651..f8e5829 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -182,7 +182,7 @@ "sort-beginDate": "data", "sort-timetableId": "ID rozkładu", "sort-timestampFrom": "data", - "sort-duration": "czas dyżuru", + "sort-currentDuration": "czas dyżuru", "sort-id": "id rozkładu", "sort-mass": "masa", diff --git a/src/views/JournalDispatchers.vue b/src/views/JournalDispatchers.vue index fda4acb..2332ddd 100644 --- a/src/views/JournalDispatchers.vue +++ b/src/views/JournalDispatchers.vue @@ -7,8 +7,8 @@ ({ statsButtons, - currentQuery: '', - currentQueryArray: [] as string[], dataRefreshedAt: null as Date | null, + currentQueryParams: {} as DispatchersQueryParams, scrollDataLoaded: true, scrollNoMoreData: false, @@ -109,9 +130,6 @@ export default defineComponent({ 'search-date': '' } as Journal.DispatcherSearchType); - const countFromIndex = ref(0); - const countLimit = 15; - provide('sorterActive', sorterActive); provide('journalFilterActive', journalFilterActive); provide('searchersValues', searchersValues); @@ -126,19 +144,17 @@ export default defineComponent({ sorterActive, searchersValues, - countFromIndex, - countLimit, - - scrollElement, - maxCount: ref(15) + scrollElement }; }, watch: { - currentQueryArray(q: string[]) { - this.currentOptionsActive = - q.length > 2 || - q.some((qv) => qv.startsWith('sortBy=') && qv.split('=')[1] != 'timestampFrom'); + currentQueryParams(queryParams: DispatchersQueryParams) { + this.currentOptionsActive = Object.keys(queryParams).some( + (k) => + queryParams[k as keyof DispatchersQueryParams] != + defaultQueryParams[k as keyof DispatchersQueryParams] + ); }, 'mainStore.dispatcherStatsData'(stats) { @@ -234,13 +250,10 @@ export default defineComponent({ async addHistoryData() { this.scrollDataLoaded = false; - - this.countFromIndex = this.historyList.length; + this.currentQueryParams['countFrom'] = this.historyList.length; const responseData: API.DispatcherHistory.Response = await ( - await this.apiStore.client!.get( - `api/getDispatchers?${this.currentQuery}&countFrom=${this.countFromIndex}` - ) + await this.apiStore.client!.get(`api/getDispatchers`, { params: this.currentQueryParams }) ).data; if (!responseData) return; @@ -254,43 +267,38 @@ export default defineComponent({ this.scrollDataLoaded = true; }, - async fetchHistoryData(reset = false) { - const queries: string[] = []; + async fetchHistoryData() { + const queryParams: DispatchersQueryParams = {}; - const dispatcher = this.searchersValues['search-dispatcher'].trim(); - const station = this.searchersValues['search-station'].trim(); - const dateString = this.searchersValues['search-date'].trim(); + const dispatcherName = this.searchersValues['search-dispatcher'].trim() || undefined; + const stationName = this.searchersValues['search-station'].trim() || undefined; + const dateString = this.searchersValues['search-date'].trim() || undefined; const timestampFrom = dateString ? Date.parse(new Date(dateString).toISOString()) - 120 * 60 * 1000 : undefined; + const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined; - if (dispatcher) queries.push(`dispatcherName=${dispatcher}`); - - if (station.startsWith("#")) queries.push(`stationHash=${station.slice(1)}`); - else if (station.length > 0) queries.push(`stationName=${station}`); + queryParams['dispatcherName'] = dispatcherName; + queryParams['timestampFrom'] = timestampFrom; + queryParams['timestampTo'] = timestampTo; + queryParams['countLimit'] = 30; - if (timestampFrom && timestampTo) - queries.push(`timestampFrom=${timestampFrom}`, `timestampTo=${timestampTo}`); + if (stationName && stationName.startsWith('#')) + queryParams['stationHash'] = stationName.slice(1); + else queryParams['stationName'] = stationName; - // API: const SORT_TYPES = ['allStopsCount', 'endDate', 'beginDate', 'routeDistance']; - if (this.sorterActive.id == 'timestampFrom') queries.push('sortBy=timestampFrom'); - else if (this.sorterActive.id == 'duration') queries.push('sortBy=currentDuration'); - else queries.push('sortBy=timestampFrom'); + queryParams['sortBy'] = this.sorterActive.id; - queries.push('countLimit=30'); + if (JSON.stringify(this.currentQueryParams) != JSON.stringify(queryParams)) + this.dataStatus = Status.Data.Loading; - if (this.currentQuery != queries.join('&')) this.dataStatus = Status.Data.Loading; - - this.currentQuery = queries.join('&'); - this.currentQueryArray = queries; + this.currentQueryParams = queryParams; try { - if (reset) this.dataStatus = Status.Data.Loading; - const responseData: API.DispatcherHistory.Response = await ( - await this.apiStore.client!.get(`api/getDispatchers?${this.currentQuery}`) + await this.apiStore.client!.get(`api/getDispatchers`, { params: this.currentQueryParams }) ).data; if (!responseData) { diff --git a/src/views/JournalTimetables.vue b/src/views/JournalTimetables.vue index b5afee4..4b97470 100644 --- a/src/views/JournalTimetables.vue +++ b/src/views/JournalTimetables.vue @@ -124,8 +124,6 @@ interface TimetablesQueryParams { timetableId?: string; authorName?: string; - // timestampFrom?: number; - // timestampTo?: number; dateFrom?: string; dateTo?: string; @@ -335,7 +333,7 @@ export default defineComponent({ const responseData: API.TimetableHistory.Response = await ( await this.apiStore.client!.get('api/getTimetables', { - params: { ...this.currentQueryParams } + params: this.currentQueryParams }) ).data;