Skip to content

Commit 49d8c1b

Browse files
committed
feat: ajouter le support des types booléens dans les filtres et améliorer la gestion des valeurs
1 parent d3adac9 commit 49d8c1b

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

apps/web/src/components/core/edit-filters.vue

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
q-card.transparent(style='min-width: 40vw; max-width: 80vw')
2+
q-card.transparent(style='min-width: 45vw; max-width: 90vw')
33
q-toolbar.bg-secondary.text-white(dense flat style='height: 32px;')
44
q-toolbar-title
55
span {{ title }}&nbsp;
@@ -26,7 +26,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
2626
.flex.q-col-gutter-md
2727
q-select.col(
2828
ref='field'
29-
style='min-width: 180px; max-width: 220px'
29+
style='min-width: 150px; max-width: 220px'
3030
v-model='filter.key'
3131
:readonly='!!initialFilter?.field'
3232
:use-input='!initialFilter?.field'
@@ -59,6 +59,16 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
5959
| Ajouter le filtre personnalisé
6060
| &nbsp;
6161
code <{{ inputValue }}>
62+
q-select.col-1(
63+
style='min-width: 120px'
64+
v-model='fieldType'
65+
label='Type'
66+
:options='["text", "number", "date", "boolean", "array"]'
67+
:readonly='!filter.key || !!columnExists(filter.key || "")'
68+
dense
69+
outlined
70+
options-dense
71+
)
6272
q-select.col-1(
6373
style='min-width: 130px'
6474
v-model='filter.operator'
@@ -84,7 +94,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
8494
span {{ scope.opt.label }}
8595
q-input.col(
8696
style='min-width: 300px'
87-
v-show="!comparator?.multiplefields && optionsMapping.length === 0"
97+
v-if="!comparator?.multiplefields && optionsMapping.length === 0 && comparator?.querySign !== '?'"
8898
v-model='filter.value'
8999
label='Valeur'
90100
:prefix="comparator?.prefix"
@@ -95,9 +105,20 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
95105
dense
96106
outlined
97107
)
108+
q-toggle(
109+
style='min-width: 140px'
110+
v-if="!comparator?.multiplefields && comparator?.querySign === '?'"
111+
v-model="filter.value"
112+
:readonly='!filter.operator'
113+
:label="filter.value ? 'Positif' : 'Négatif'"
114+
true-value="true"
115+
false-value="false"
116+
color="gray"
117+
dense
118+
)
98119
q-select.col(
99120
style='min-width: 300px'
100-
v-show="!comparator?.multiplefields && optionsMapping.length > 0"
121+
v-if="!comparator?.multiplefields && optionsMapping.length > 0"
101122
v-model='filter.value'
102123
label='Valeur'
103124
:prefix="comparator?.prefix"
@@ -114,7 +135,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
114135
)
115136
q-input.col(
116137
style='min-width: 200px'
117-
v-show="comparator?.multiplefields && comparator?.querySign === '<<'"
138+
v-if="comparator?.multiplefields && comparator?.querySign === '<<'"
118139
v-model="filter.min"
119140
:type='searchInputType'
120141
:readonly='!filter.operator'
@@ -125,7 +146,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
125146
)
126147
q-input.col(
127148
style='min-width: 200px'
128-
v-show="comparator?.multiplefields && comparator?.querySign === '<<'"
149+
v-if="comparator?.multiplefields && comparator?.querySign === '<<'"
129150
v-model="filter.max"
130151
:type='searchInputType'
131152
:readonly='!filter.operator'
@@ -136,7 +157,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
136157
)
137158
q-select.col(
138159
style='min-width: 300px'
139-
v-show="comparator?.multiplefields && comparator?.querySign === '@'"
160+
v-if="comparator?.multiplefields && comparator?.querySign === '@'"
140161
v-model="filter.items"
141162
label="Valeur"
142163
:prefix="comparator?.prefix"
@@ -159,7 +180,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
159180
q-space
160181
q-btn(
161182
@click='writeFilter(filter)'
162-
:disabled='!filter.key || !filter.operator || (!filter.value && !filter.items?.length)'
183+
:disabled='!filter.key || !filter.operator || (typeof filter.value === "undefined" && !filter.items?.length)'
163184
label='Valider'
164185
color='positive'
165186
icon-right='mdi-check'
@@ -176,7 +197,7 @@ import dayjs from 'dayjs'
176197
type Filter = {
177198
operator: string
178199
key: string | undefined
179-
value: string | number | undefined
200+
value: string | number | boolean | undefined
180201
181202
min?: string
182203
max?: string
@@ -344,20 +365,21 @@ export default defineNuxtComponent({
344365
}
345366
},
346367
computed: {
347-
comparator(): { label: string; value: string; prefix?: string; suffix?: string; multiplefields?: boolean } | undefined {
368+
comparator(): { label: string; value: string; prefix?: string; suffix?: string; multiplefields?: boolean; type?: string[] } | undefined {
348369
return this.comparatorTypes.find((comp) => comp.value === this.filter.operator)
349370
},
350371
searchInputType(): string {
351-
if (this.fieldType === undefined || this.fieldType === null) return 'text'
352-
return this.fieldType
372+
if (!this.fieldType) {
373+
return this.comparator?.type ? this.comparator.type[0] : 'text'
374+
}
375+
376+
return this.fieldType || 'text'
353377
},
354378
availableComparators(): { label: string; value: string; prefix?: string; suffix?: string; multiplefields?: boolean }[] {
355-
if (!this.columnExists(this.filter.key || '')) {
356-
return this.comparatorTypes
379+
if (!this.columnExists(this.filter.key || '') && !this.fieldType) {
380+
return this.comparatorTypes || []
357381
}
358382
359-
if (this.fieldType === undefined || this.fieldType === null) return []
360-
361383
return this.comparatorTypes.filter((comparator) => {
362384
return comparator.type.includes(this.fieldType!)
363385
})

apps/web/src/composables/useFiltersQuery.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export type ColumnType = {
3636
}
3737

3838
const comparatorTypes = ref<ComparatorType[]>([
39+
{
40+
label: 'Est un booléen',
41+
querySign: '?',
42+
value: '?',
43+
icon: 'mdi-help',
44+
type: ['boolean'],
45+
multiplefields: false,
46+
prefix: '',
47+
suffix: '',
48+
},
3949
{
4050
label: 'Égal à',
4151
querySign: ':',
@@ -343,7 +353,7 @@ export function useFiltersQuery(columns: Ref<QTableProps['columns'] & { type: st
343353
const hasFilters = computed(() => countFilters.value > 0)
344354

345355
const getFilters = computed(() => {
346-
const filters: Record<string, { label: string; field: string; comparator: string; value: string; querySign: string; search: string }> = {}
356+
const filters: Record<string, { label: string; field: string; comparator: string; value: unknown; querySign: string; search: string }> = {}
347357

348358
for (const key in $route.query) {
349359
if (key.includes(FILTER_PREFIX)) {
@@ -370,7 +380,7 @@ export function useFiltersQuery(columns: Ref<QTableProps['columns'] & { type: st
370380

371381
const comparatorObj = getComparatorObject(extract.comparator, rawValue)
372382

373-
console.log('comparatorObj', comparatorObj, 'for key', key, 'with rawValue', rawValue)
383+
// console.log('comparatorObj', comparatorObj, 'for key', key, 'with rawValue', rawValue)
374384

375385
filters[key] = {
376386
label,
@@ -399,7 +409,7 @@ export function useFiltersQuery(columns: Ref<QTableProps['columns'] & { type: st
399409
})
400410
}
401411

402-
const writeFilter = (filter: { key: string; operator: string; value: string, min?: string, max?: string, items?: (string | number)[] }) => {
412+
const writeFilter = (filter: { key: string; operator: string; value: any, min?: string, max?: string, items?: (string | number)[] }) => {
403413
const router = useRouter()
404414
const query = { ...$route.query }
405415
const comparator = comparatorTypes.value.find((comp) => comp.value === filter.operator)

0 commit comments

Comments
 (0)