Wskaźnik aktywnych filtrów dziennika RJ

This commit is contained in:
2022-12-21 15:45:03 +01:00
parent f3e193e68a
commit d64b906dac
3 changed files with 44 additions and 28 deletions
@@ -2,9 +2,10 @@
<div class="filters-options" @keydown.esc="showOptions = false"> <div class="filters-options" @keydown.esc="showOptions = false">
<div class="bg" v-if="showOptions" @click="showOptions = false"></div> <div class="bg" v-if="showOptions" @click="showOptions = false"></div>
<button class="btn--filled btn--image" @click="showOptions = !showOptions" ref="button"> <button class="filter-button btn--filled btn--image" @click="showOptions = !showOptions" ref="button">
<img :src="getIcon('filter2')" alt="Open filters" /> <img :src="getIcon('filter2')" alt="Open filters" />
{{ $t('options.filters') }} [F] {{ $t('options.filters') }} [F]
<span class="active-indicator" v-if="currentOptionsActive"></span>
</button> </button>
<datalist id="search-driver"> <datalist id="search-driver">
@@ -116,6 +117,11 @@ export default defineComponent({
type: Number as PropType<DataStatus>, type: Number as PropType<DataStatus>,
default: DataStatus.Initialized, default: DataStatus.Initialized,
}, },
currentOptionsActive: {
type: Boolean,
default: false
}
}, },
data() { data() {
+9
View File
@@ -6,6 +6,15 @@
margin-bottom: 0.5em; margin-bottom: 0.5em;
} }
.filter-button .active-indicator {
width: 7px;
height: 7px;
background-color: lightgreen;
border-radius: 50%;
margin-left: 10px;
}
h1.option-title { h1.option-title {
position: relative; position: relative;
font-size: 1.1em; font-size: 1.1em;
+28 -27
View File
@@ -4,10 +4,11 @@
<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="['timetableId', 'beginDate', 'distance', 'total-stops']" :sorter-option-ids="['timetableId', 'beginDate', 'distance', 'total-stops']"
:filters="journalTimetableFilters" :filters="journalTimetableFilters"
:currentOptionsActive="currentOptionsActive"
:data-status="dataStatus" :data-status="dataStatus"
/> />
@@ -48,7 +49,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, provide, reactive, Ref, ref } from 'vue'; import { defineComponent, provide, reactive, Ref, ref, watch } from 'vue';
import axios from 'axios'; import axios from 'axios';
import DriverStats from '../components/JournalView/JournalDriverStats.vue'; import DriverStats from '../components/JournalView/JournalDriverStats.vue';
@@ -87,11 +88,14 @@ export default defineComponent({
data: () => ({ data: () => ({
currentQuery: '', currentQuery: '',
currentQueryArray: [] as string[],
scrollDataLoaded: true, scrollDataLoaded: true,
scrollNoMoreData: false, scrollNoMoreData: false,
showReturnButton: false, showReturnButton: false,
statsCardOpen: false, statsCardOpen: false,
currentOptionsActive: false,
timetableHistory: [] as TimetableHistory[], timetableHistory: [] as TimetableHistory[],
journalTimetableFilters, journalTimetableFilters,
@@ -131,19 +135,27 @@ export default defineComponent({
countLimit, countLimit,
scrollElement, scrollElement,
store: useStore(), store: useStore(),
}; };
}, },
watch: {
currentQueryArray(q: string[]) {
this.currentOptionsActive =
q.length > 2 || q.some((qv) => qv.startsWith('sortBy=') && qv.split('=')[1] != 'timetableId');
},
},
// Handle route updates for route-links // Handle route updates for route-links
beforeRouteUpdate(to, from) { beforeRouteUpdate(to, _) {
this.handleQueries(to.query); this.handleQueries(to.query);
this.searchHistory(); this.fetchHistoryData();
}, },
activated() { activated() {
this.handleQueries(this.$route.query); this.handleQueries(this.$route.query);
this.searchHistory(); this.fetchHistoryData();
}, },
methods: { methods: {
@@ -174,17 +186,7 @@ export default defineComponent({
this.journalFilterActive = this.journalTimetableFilters[0]; this.journalFilterActive = this.journalTimetableFilters[0];
this.sorterActive.id = 'timetableId'; this.sorterActive.id = 'timetableId';
this.searchHistory(); this.fetchHistoryData();
},
searchHistory() {
this.fetchHistoryData({
searchers: this.searchersValues,
filter: this.journalFilterActive,
});
this.scrollNoMoreData = false;
this.scrollDataLoaded = true;
}, },
async addHistoryData() { async addHistoryData() {
@@ -207,21 +209,16 @@ export default defineComponent({
this.scrollDataLoaded = true; this.scrollDataLoaded = true;
}, },
async fetchHistoryData( async fetchHistoryData() {
props: {
searchers?: JournalTimetableSearchType;
filter?: JournalTimetableFilter;
} = {}
) {
this.dataStatus = DataStatus.Loading; this.dataStatus = DataStatus.Loading;
const queries: string[] = []; const queries: string[] = [];
const driverName = props.searchers?.['search-driver'].trim(); const driverName = this.searchersValues['search-driver'].trim();
const trainNo = props.searchers?.['search-train'].trim(); const trainNo = this.searchersValues['search-train'].trim();
const authorName = props.searchers?.['search-dispatcher'].trim(); const authorName = this.searchersValues['search-dispatcher'].trim();
const dateString = this.searchersValues['search-date'].trim();
const dateString = props.searchers?.['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;
@@ -239,7 +236,7 @@ export default defineComponent({
queries.push('countLimit=15'); queries.push('countLimit=15');
switch (props.filter?.id) { switch (this.journalFilterActive.id) {
case JournalFilterType.abandoned: case JournalFilterType.abandoned:
queries.push('fulfilled=0', 'terminated=1'); queries.push('fulfilled=0', 'terminated=1');
break; break;
@@ -257,6 +254,7 @@ export default defineComponent({
} }
this.currentQuery = queries.join('&'); this.currentQuery = queries.join('&');
this.currentQueryArray = queries;
try { try {
const responseData: TimetableHistory[] = await ( const responseData: TimetableHistory[] = await (
@@ -285,6 +283,9 @@ export default defineComponent({
this.dataStatus = DataStatus.Error; this.dataStatus = DataStatus.Error;
this.dataErrorMessage = 'Ups! Coś poszło nie tak!'; this.dataErrorMessage = 'Ups! Coś poszło nie tak!';
} }
this.scrollNoMoreData = false;
this.scrollDataLoaded = true;
}, },
}, },
}); });