Skip to content

Commit

Permalink
feat: add sources filter account
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Oct 12, 2023
1 parent efef4d2 commit 3c3bf01
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
54 changes: 41 additions & 13 deletions src/main/webapp/src/components/filter/AccountFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ChipsFilter from '@/components/filter/ChipsFilter.vue';
import { CategoriePersonne } from '@/types/enums/CategoriePersonne';
import { Etat } from '@/types/enums/Etat';
import type { SimplePersonne } from '@/types/personneType';
import { isArrayOf } from '@/utils/arrayUtils';
import isEmpty from 'lodash.isempty';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
Expand All @@ -20,22 +21,30 @@ const nbResults = ref<number>(props.searchList ? props.searchList.length : 0);
let searchFilter: string | undefined;
let categoryFilter: Array<string>;
let statusFilter: Array<string>;
let typeFilter: Array<string>;
const setSearchFilter = (newValue: string | undefined) => {
searchFilter = newValue;
filter();
};
const setCategoryFilter = (newValue: Array<number | string>) => {
if (typeof newValue == 'string') {
categoryFilter = newValue;
if (isArrayOf(newValue, 'string')) {
categoryFilter = newValue as string[];
filter();
}
};
const setStatusFilter = (newValue: Array<number | string>) => {
if (typeof newValue == 'string') {
statusFilter = newValue;
if (isArrayOf(newValue, 'string')) {
statusFilter = newValue as string[];
filter();
}
};
const setTypeFilter = (newValue: Array<number | string>) => {
if (isArrayOf(newValue, 'string')) {
typeFilter = newValue as string[];
filter();
}
};
Expand Down Expand Up @@ -64,6 +73,12 @@ const filter = () => {
result = result?.filter((personne) => statusFilter.includes(personne.etat));
}
if (!isEmpty(typeFilter)) {
result = result.filter((personne) =>
typeFilter.includes(personne.source.startsWith('SarapisUi_') ? 'SarapisUi_' : ''),
);
}
nbResults.value = result.length;
emit('update:result', result);
};
Expand Down Expand Up @@ -93,6 +108,11 @@ const statusTags = [
{ id: Etat.Delete, i18n: 'person.status.deleted' },
];
const typeTags = [
{ id: '', i18n: 'source.official' },
{ id: 'SarapisUi_', i18n: 'source.SarapisUi_' },
];
filter();
</script>

Expand All @@ -102,6 +122,7 @@ filter();
<v-text-field
:placeholder="t('search.personne.placeholder')"
variant="solo-filled"
class="mb-3"
rounded
clearable
flat
Expand All @@ -112,15 +133,22 @@ filter();
<v-icon icon="fas fa-search" size="x-small" class="mx-1" />
</template>
</v-text-field>
<div class="mb-2">
<h2 class="text-h6">{{ t('person.information.profile') }}</h2>
<chips-filter :tags="categoryTags" @update:selected="setCategoryFilter" />
</div>
<div class="mb-2">
<h2 class="text-h6">{{ t('person.information.status') }}</h2>
<chips-filter :tags="statusTags" @update:selected="setStatusFilter" />
</div>
<div class="mb-2">
<h2 class="text-h6">{{ t('person.information.source') }}</h2>
<chips-filter :tags="typeTags" @update:selected="setTypeFilter" />
</div>
<div class="d-flex">
<v-spacer />
<div>{{ nbResults }} {{ t('result', nbResults) }}</div>
</div>
</v-card-text>
<v-card-text>
<h2 class="text-h6 mb-2">{{ t('person.information.profile') }}</h2>
<chips-filter :tags="categoryTags" @update:selected="setCategoryFilter" />
</v-card-text>
<v-card-text>
<h2 class="text-h6 mb-2">{{ t('person.information.status') }}</h2>
<chips-filter :tags="statusTags" @update:selected="setStatusFilter" />
</v-card-text>
<v-card-text>{{ nbResults }} {{ t('result', nbResults) }}</v-card-text>
</v-card>
</template>
2 changes: 1 addition & 1 deletion src/main/webapp/src/components/filter/ChipsFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ const filter = (payload: Array<number>) => {

<template>
<v-chip-group column multiple selected-class="text-primary" @update:model-value="filter">
<v-chip v-for="(tag, index) in tags" :key="index" rounded>{{ t(tag.i18n) }}</v-chip>
<v-chip v-for="(tag, index) in tags" :key="index" :text="t(tag.i18n)" rounded />
</v-chip-group>
</template>
4 changes: 3 additions & 1 deletion src/main/webapp/src/locales/en/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"SarapisUi_CFA-CENTRE": "",
"SarapisUi_EF2S-CENTRE": "",
"SarapisUi_GIP-RECIA": "",
"SarapisUi_LA-CENTRE": ""
"SarapisUi_LA-CENTRE": "",
"SarapisUi_": "",
"official": ""
}
}
4 changes: 3 additions & 1 deletion src/main/webapp/src/locales/fr/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"SarapisUi_CFA-CENTRE": "Compte local établissement",
"SarapisUi_EF2S-CENTRE": "Compte local établissement",
"SarapisUi_GIP-RECIA": "Compte local GIP RECIA",
"SarapisUi_LA-CENTRE": "Compte local enseignement agricole"
"SarapisUi_LA-CENTRE": "Compte local enseignement agricole",
"SarapisUi_": "Compte local",
"official": "Annuaire"
}
}

0 comments on commit 3c3bf01

Please sign in to comment.