diff --git a/components/btn/Sort.vue b/components/btn/Sort.vue index 369e77dfdbd86eacb72ed3f32b4b043edce7771b..8643b12d1084b93c1c798dc547d307b175b212bf 100644 --- a/components/btn/Sort.vue +++ b/components/btn/Sort.vue @@ -1,5 +1,10 @@ <template> - <div class="btn-sort pointer px-2" tabindex="0" :title="$t('tri.action')"> + <div + class="btn-sort pointer px-2" + tabindex="0" + :title="$t('tri.action')" + @click="sort(fieldName)" + @keyup.enter="sort(fieldName)"> <span class="text-truncate">{{ title }}</span> <solid-sort-ascending-icon aria-hidden="true" @@ -23,6 +28,10 @@ export default { type: String, required: true }, + tableName: { + type: String, + required: true + }, currentSort: { type: String, required: true @@ -34,6 +43,63 @@ export default { return ["asc", "desc"].indexOf(value) !== -1 } } + }, + methods: { + sort(s) { + if (s === this.currentSort) { + this.$parent.currentSortDir = + this.currentSortDir === "asc" ? "desc" : "asc" + } else { + this.$parent.currentSortDir = "asc" + } + this.$parent.currentSort = s + + let query = this.$route.query + let newQuery = {} + let same_array = false + + if (Object.keys(query).length !== 0) { + for (const param in query) { + if (param.includes(this.tableName + "_")) { + same_array = true + newQuery[this.tableName + "_" + this.fieldName] = + this.$parent.currentSortDir + } else { + newQuery[param] = query[param] + } + } + } + + if (!same_array) { + newQuery[this.tableName + "_" + this.fieldName] = + this.$parent.currentSortDir + } + + this.$router.push({ + hash: this.$route.hash, + query: newQuery + }) + }, + retrieveQuery() { + let query = this.$route.query + + if (Object.keys(query).length !== 0) { + for (const param in query) { + if (param.replace(this.tableName + "_", "") == this.fieldName) { + this.$parent.currentSort = this.fieldName + this.$parent.currentSortDir = query[param] + } + } + } + } + }, + mounted() { + this.retrieveQuery() + }, + watch: { + $route(n, o) { + this.retrieveQuery() + } } } </script> diff --git a/components/certif/List.vue b/components/certif/List.vue index 3369d44854997e8cbfa4bf5d28b989d25c65847d..0835544b58ad12e7c8ac10d4b45e72dfd6595b75 100644 --- a/components/certif/List.vue +++ b/components/certif/List.vue @@ -38,20 +38,19 @@ class="table table-striped table-hover table-fixed sortable border m-0"> <thead class="thead-light"> <tr> - <th class="p-0" @click="sort('uid')" @keyup.enter="sort('uid')"> + <th class="p-0"> <BtnSort :title="$t('membre.title')" fieldName="uid" + :tableName="collapseId" :currentSort="currentSort" :currentSortDir="currentSortDir" /> </th> - <th - class="p-0 col-4" - @click="sort('expires_on')" - @keyup.enter="sort('expires_on')"> + <th class="p-0 col-4"> <BtnSort :title="$t('expire')" fieldName="expires_on" + :tableName="collapseId" :currentSort="currentSort" :currentSortDir="currentSortDir" /> </th> @@ -138,14 +137,6 @@ export default { default: false } }, - methods: { - sort(s) { - if (s === this.currentSort) { - this.currentSortDir = this.currentSortDir === "asc" ? "desc" : "asc" - } - this.currentSort = s - } - }, computed: { certifsFiltrees() { return this.certifs.filter((row, index) => { diff --git a/components/member/List.vue b/components/member/List.vue index 5f348ce090f5087fad13610a4eefe9c54f6aaef4..6e39d4d772b4ea965f581a76b021b21593a94b7f 100644 --- a/components/member/List.vue +++ b/components/member/List.vue @@ -4,13 +4,10 @@ class="table table-striped table-hover table-fixed sortable border text-center"> <thead class="thead-light"> <tr> - <th - class="p-0" - scope="col" - @click="sort('uid')" - @keyup.enter="sort('uid')"> + <th class="p-0" scope="col"> <BtnSort fieldName="uid" + :tableName="id" title="UID" :currentSort="currentSort" :currentSortDir="currentSortDir" /> @@ -18,11 +15,10 @@ <th scope="col" class="d-none d-lg-table-cell p-0" - v-if="id != 'default'" - @click="sort('statut')" - @keyup.enter="sort('statut')"> + v-if="id != 'default'"> <BtnSort fieldName="statut" + :tableName="id" :title="$t('statut.title')" :currentSort="currentSort" :currentSortDir="currentSortDir" /> @@ -32,11 +28,10 @@ class="td-quality d-none d-lg-table-cell p-0" v-if=" ['favoris', 'search', 'certificateurs', 'certifies'].includes(id) - " - @click="sort('quality')" - @keyup.enter="sort('quality')"> + "> <BtnSort fieldName="quality" + :tableName="id" :title="$t('membre.qualite.title')" :currentSort="currentSort" :currentSortDir="currentSortDir" /> @@ -46,11 +41,10 @@ class="d-none d-xl-table-cell p-0" v-if=" ['favoris', 'search', 'certificateurs', 'certifies'].includes(id) - " - @click="sort('dispo')" - @keyup.enter="sort('dispo')"> + "> <BtnSort fieldName="dispo" + :tableName="id" :title="$t('membre.disponibilite')" :currentSort="currentSort" :currentSortDir="currentSortDir" /> @@ -58,8 +52,6 @@ <th scope="col" class="td-date d-none d-sm-table-cell p-0" - @click="sort('date_membership')" - @keyup.enter="sort('date_membership')" v-if=" [ 'adhesion', @@ -71,6 +63,7 @@ "> <BtnSort fieldName="date_membership" + :tableName="id" :title=" ['certif', 'adhesion'].includes(id) ? $t('date') @@ -86,8 +79,6 @@ 'd-sm-table-cell': id == 'certif', 'd-md-table-cell': id != 'certif' }" - @click="sort('date_certs')" - @keyup.enter="sort('date_certs')" v-if=" [ 'certif', @@ -99,6 +90,7 @@ "> <BtnSort fieldName="date_certs" + :tableName="id" :title=" ['certif', 'adhesion'].includes(id) ? $t('date') @@ -256,12 +248,6 @@ export default { this.localePath({ name: "membres-profil", query: { hash } }) ) }, - sort(s) { - if (s === this.currentSort) { - this.currentSortDir = this.currentSortDir === "asc" ? "desc" : "asc" - } - this.currentSort = s - }, getDate(member) { if (this.id == "adhesion") return member.limitDate if (this.id == "certif") return member.certsLimit