Optymalizacja pobierania danych

This commit is contained in:
2022-12-21 18:10:54 +01:00
parent 9f68d628d0
commit d06f2d5d2e
+31 -29
View File
@@ -4,7 +4,7 @@
<div class="journal_wrapper"> <div class="journal_wrapper">
<JournalOptions <JournalOptions
@on-search-confirm="searchHistory" @on-search-confirm="fetchHistoryData"
@on-options-reset="resetOptions" @on-options-reset="resetOptions"
:sorter-option-ids="['timestampFrom', 'duration']" :sorter-option-ids="['timestampFrom', 'duration']"
:data-status="dataStatus" :data-status="dataStatus"
@@ -68,6 +68,7 @@ import { JournalDispatcherSearcher, JournalDispatcherSorter } from '../types/Jou
import { DispatcherHistory } from '../scripts/interfaces/api/DispatchersAPIData'; import { DispatcherHistory } from '../scripts/interfaces/api/DispatchersAPIData';
import { JournalTimetableFilter } from '../types/Journal/JournalTimetablesTypes'; import { JournalTimetableFilter } from '../types/Journal/JournalTimetablesTypes';
import JournalHeader from '../components/JournalView/JournalHeader.vue'; import JournalHeader from '../components/JournalView/JournalHeader.vue';
import { LocationQuery } from 'vue-router';
const DISPATCHERS_API_URL = `${URLs.stacjownikAPI}/api/getDispatchers`; const DISPATCHERS_API_URL = `${URLs.stacjownikAPI}/api/getDispatchers`;
@@ -160,17 +161,19 @@ export default defineComponent({
}, },
}, },
beforeRouteUpdate(to, _) {
this.handleQueries(to.query);
this.fetchHistoryData();
},
activated() { activated() {
if (this.sceneryName || this.dispatcherName) { this.handleQueries(this.$route.query);
this.searchersValues['search-station'] = this.sceneryName?.toString() || ''; this.fetchHistoryData();
this.searchersValues['search-dispatcher'] = this.dispatcherName?.toString() || '';
this.searchHistory();
}
}, },
mounted() { mounted() {
if (!this.sceneryName && !this.dispatcherName) { if (!this.sceneryName && !this.dispatcherName) {
this.searchHistory(); this.fetchHistoryData();
} }
}, },
@@ -185,22 +188,22 @@ export default defineComponent({
if (scrollTop > elementHeight * 0.85) this.addHistoryData(); if (scrollTop > elementHeight * 0.85) this.addHistoryData();
}, },
resetOptions() { handleQueries(query: LocationQuery) {
this.searchersValues['search-station'] = ''; if ('sceneryName' in query) this.searchersValues['search-station'] = `${query.sceneryName}`;
this.searchersValues['search-dispatcher'] = ''; if ('dispatcherName' in query) this.searchersValues['search-dispatcher'] = `${query.dispatcherName}`;
this.searchersValues['search-date'] = '';
this.sorterActive.id = 'timestampFrom';
this.searchHistory();
}, },
searchHistory() { setSearchers(date: string, station: string, dispatcher: string) {
this.fetchHistoryData({ this.searchersValues['search-date'] = date;
searchers: this.searchersValues, this.searchersValues['search-station'] = station;
}); this.searchersValues['search-dispatcher'] = dispatcher;
},
this.scrollNoMoreData = false; resetOptions() {
this.scrollDataLoaded = true; this.setSearchers('', '', '');
this.sorterActive.id = 'timestampFrom';
this.fetchHistoryData();
}, },
async addHistoryData() { async addHistoryData() {
@@ -223,19 +226,15 @@ export default defineComponent({
this.scrollDataLoaded = true; this.scrollDataLoaded = true;
}, },
async fetchHistoryData( async fetchHistoryData() {
props: {
searchers?: JournalDispatcherSearcher;
filter?: JournalTimetableFilter;
} = {}
) {
this.dataStatus = DataStatus.Loading; this.dataStatus = DataStatus.Loading;
const queries: string[] = []; const queries: string[] = [];
const dispatcher = props.searchers?.['search-dispatcher'].trim(); const dispatcher = this.searchersValues['search-dispatcher'].trim();
const station = props.searchers?.['search-station'].trim(); const station = this.searchersValues['search-station'].trim();
const dateString = props.searchers?.['search-date'].trim(); const dateString = this.searchersValues['search-date'].trim();
const timestampFrom = dateString ? Date.parse(new Date(dateString).toISOString()) - 120 * 60 * 1000 : undefined; const timestampFrom = dateString ? Date.parse(new Date(dateString).toISOString()) - 120 * 60 * 1000 : undefined;
const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined; const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined;
@@ -278,6 +277,9 @@ export default defineComponent({
} catch (error) { } catch (error) {
this.dataStatus = DataStatus.Error; this.dataStatus = DataStatus.Error;
} }
this.scrollNoMoreData = false;
this.scrollDataLoaded = true;
}, },
}, },
}); });