Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 9380fa6

Browse files
committed
WIP history filters
1 parent 3a8a3da commit 9380fa6

File tree

3 files changed

+113
-23
lines changed

3 files changed

+113
-23
lines changed

src/history/components/HistoryList.vue

+110-22
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,83 @@
11
<template>
2-
<QInfiniteScroll
3-
ref="infiniteScroll"
4-
:disable="!canFetchPast"
5-
@load="maybeFetchPast"
6-
>
7-
<KSpinner v-show="isPending" />
8-
<HistoryEntry
9-
v-for="entry in history"
10-
:key="entry.id"
11-
:entry="entry"
12-
/>
13-
<div v-if="empty">
14-
<QIcon name="fas fa-bug" />
15-
{{ $t('HISTORY.NOTHING_HAPPENEND') }}
2+
<div>
3+
<div
4+
v-if="history.length > 0"
5+
class="row no-wrap items-center justify-between bg-white q-px-sm q-py-xs"
6+
>
7+
<div class="row q-gutter-sm">
8+
<QSelect
9+
v-model="historyType"
10+
:options="historyTypeOptions"
11+
emit-value
12+
map-options
13+
outlined
14+
hide-bottom-space
15+
dense
16+
/>
17+
<QSelect
18+
v-model="userId"
19+
:options="usersOptions"
20+
emit-value
21+
map-options
22+
outlined
23+
hide-bottom-space
24+
dense
25+
/>
26+
</div>
27+
<div class="text-caption q-ml-xs">
28+
{{ filteredHistory.length }} / {{ history.length }}
29+
</div>
1630
</div>
17-
<template v-slot:loading>
18-
<KSpinner />
19-
</template>
20-
</QInfiniteScroll>
31+
<QInfiniteScroll
32+
ref="infiniteScroll"
33+
:disable="!canFetchPast"
34+
@load="maybeFetchPast"
35+
>
36+
<KSpinner v-show="isPending" />
37+
<HistoryEntry
38+
v-for="entry in filteredHistory"
39+
:key="entry.id"
40+
:entry="entry"
41+
/>
42+
<div v-if="empty">
43+
<QIcon name="fas fa-bug" />
44+
{{ $t('HISTORY.NOTHING_HAPPENEND') }}
45+
</div>
46+
<template v-slot:loading>
47+
<KSpinner />
48+
</template>
49+
</QInfiniteScroll>
50+
</div>
2151
</template>
2252

2353
<script>
2454
import {
2555
QIcon,
2656
QInfiniteScroll,
57+
QSelect,
2758
} from 'quasar'
2859
import paginationMixin from '@/utils/mixins/paginationMixin'
2960
import statusMixin from '@/utils/mixins/statusMixin'
61+
import bindRoute from '@/utils/mixins/bindRoute'
3062
import HistoryEntry from '@/history/components/HistoryEntry'
3163
import KSpinner from '@/utils/components/KSpinner'
3264
3365
export default {
3466
components: {
3567
QIcon,
3668
QInfiniteScroll,
69+
QSelect,
3770
HistoryEntry,
3871
KSpinner,
3972
},
40-
mixins: [statusMixin, paginationMixin],
73+
mixins: [
74+
statusMixin,
75+
paginationMixin,
76+
bindRoute({
77+
historyType: 'all',
78+
userId: 'all',
79+
}),
80+
],
4181
props: {
4282
history: { required: true, type: Array },
4383
status: { default: null, type: Object },
@@ -46,9 +86,57 @@ export default {
4686
empty () {
4787
return !this.history.length && !this.status.pending && !this.status.hasValidationErrors
4888
},
89+
historyTypeOptions () {
90+
return [
91+
{
92+
label: `all types (${this.history.length})`,
93+
value: 'all',
94+
},
95+
...(Object.entries(this.history.reduce((acc, cur) => {
96+
acc[cur.typus] = 1 + (acc[cur.typus] || 0)
97+
return acc
98+
}, {})).map(([typus, count]) => ({
99+
label: `${this.historyTypeMessage(typus)} (${count})`,
100+
value: typus,
101+
}))),
102+
]
103+
},
104+
usersOptions () {
105+
return [
106+
{
107+
label: `all users (${this.history.length})`,
108+
value: 'all',
109+
},
110+
...(Object.entries(this.history.reduce((acc, cur) => {
111+
cur.users.forEach(u => {
112+
if (!acc[u.id]) acc[u.id] = { user: u, count: 0 }
113+
acc[u.id].count = 1 + acc[u.id].count
114+
})
115+
return acc
116+
}, {})).map(([_, { user, count }]) => ({
117+
label: `${user.displayName} (${count})`,
118+
value: user.id,
119+
}))),
120+
]
121+
},
122+
filteredHistory () {
123+
if (!this.history) return []
124+
let filtered = this.history
125+
if (this.historyType !== 'all') filtered = filtered.filter(e => this.historyType === e.typus)
126+
if (this.userId !== 'all') filtered = filtered.filter(e => e.users.map(u => u.id).includes(parseInt(this.userId)))
127+
return filtered
128+
},
129+
},
130+
watch: {
131+
'$route.query' (val) {
132+
console.log('refetch', this.$route.params, this.$route.query)
133+
this.$store.dispatch('history/fetch', { ...this.$route.params, ...this.$route.query })
134+
},
135+
},
136+
methods: {
137+
historyTypeMessage (typus) {
138+
return this.$t('HISTORY.' + typus.toUpperCase(), { storeName: '...', name: '...', applicantName: '...' })
139+
},
49140
},
50141
}
51142
</script>
52-
53-
<style scoped lang="stylus">
54-
</style>

src/history/datastore/history.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ export default {
5454
},
5555
actions: {
5656
...withMeta({
57-
async fetch ({ dispatch, commit }, { groupId, placeId, userId }) {
57+
async fetch ({ dispatch, commit }, { groupId, placeId, userId, historyType }) {
5858
const filters = filterTruthy({
5959
place: placeId,
6060
group: groupId,
6161
users: userId,
62+
type: historyType,
6263
})
6364
const entries = await dispatch('pagination/extractCursor', historyAPI.list(filters))
6465
commit('update', entries)

src/utils/mixins/bindRoute.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function bindRoute (params) {
77
const def = params[key]
88
mixin.computed[key] = {
99
get () {
10+
if (!this.$route) return def
1011
if (Object.prototype.hasOwnProperty.call(this.$route.query, key)) {
1112
return this.$route.query[key]
1213
}

0 commit comments

Comments
 (0)