Adds sorting on SearchControl.
This commit is contained in:
parent
7e1e0de7cc
commit
dae37e9882
|
@ -30,15 +30,15 @@
|
|||
<option
|
||||
v-for="(field, index) in tableFields"
|
||||
v-if="field.id != undefined"
|
||||
:value="field"
|
||||
:value="field.id"
|
||||
:key="index">
|
||||
{{ field.label }}
|
||||
</option>
|
||||
</b-select>
|
||||
<button
|
||||
class="button is-small"
|
||||
@click="onChangeOrderAsc()">
|
||||
<b-icon :icon="orderAsc ? 'sort-ascending' : 'sort-descending'"/>
|
||||
@click="onChangeOrder()">
|
||||
<b-icon :icon="order == 'ASC' ? 'sort-ascending' : 'sort-descending'"/>
|
||||
</button>
|
||||
</b-field>
|
||||
</div>
|
||||
|
@ -46,27 +46,33 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions } from 'vuex';
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import { eventSearchBus } from '../../../js/event-search-bus';
|
||||
|
||||
export default {
|
||||
name: 'SearchControl',
|
||||
data() {
|
||||
return {
|
||||
orderBy: 'date',
|
||||
orderAsc: false
|
||||
}
|
||||
},
|
||||
props: {
|
||||
collectionId: Number,
|
||||
isRepositoryLevel: false,
|
||||
tableFields: Array,
|
||||
prefTableFields: Array
|
||||
},
|
||||
computed: {
|
||||
orderBy() {
|
||||
return this.getOrderBy();
|
||||
},
|
||||
order() {
|
||||
return this.getOrder();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('fields', [
|
||||
'fetchFields'
|
||||
]),
|
||||
...mapGetters('search', [
|
||||
'getOrderBy',
|
||||
'getOrder'
|
||||
]),
|
||||
onChangeTableFields(field) {
|
||||
// let prevValue = this.prefTableFields;
|
||||
// let index = this.prefTableFields.findIndex(alteredField => alteredField.slug === field.slug);
|
||||
|
@ -82,13 +88,11 @@ export default {
|
|||
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, prevValue);
|
||||
},
|
||||
onChangeOrderBy(event) {
|
||||
this.orderBy = event.id;
|
||||
eventSearchBus.setOrderBy(this.orderBy);
|
||||
onChangeOrderBy(fieldId) {
|
||||
eventSearchBus.setOrderBy(fieldId);
|
||||
},
|
||||
onChangeOrderAsc() {
|
||||
this.orderAsc = !this.orderAsc;
|
||||
eventSearchBus.setOrderAsc(this.orderAsc);
|
||||
onChangeOrder() {
|
||||
this.order == 'DESC' ? eventSearchBus.setOrder('ASC') : eventSearchBus.setOrder('DESC');
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
|
|
@ -24,6 +24,10 @@ export const eventSearchBus = new Vue({
|
|||
this.$route.query.perpage = 12;
|
||||
if (this.$route.query.paged == undefined)
|
||||
this.$route.query.paged = 1;
|
||||
if (this.$route.query.order == undefined)
|
||||
this.$route.query.order = 'DESC';
|
||||
if (this.$route.query.orderby == undefined)
|
||||
this.$route.query.orderby = 'date';
|
||||
|
||||
store.dispatch('search/set_postquery', this.$route.query);
|
||||
//console.log(this.$route.query);
|
||||
|
@ -63,8 +67,8 @@ export const eventSearchBus = new Vue({
|
|||
store.dispatch('search/setOrderBy', newOrderBy);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setOrderAsc(newOrderAsc) {
|
||||
store.dispatch('search/setOrderBy', newOrderAsc);
|
||||
setOrder(newOrder) {
|
||||
store.dispatch('search/setOrder', newOrder);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
updateURLQueries() {
|
||||
|
|
|
@ -38,11 +38,8 @@ export const setOrderBy = ({ commit }, orderBy ) => {
|
|||
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy } );
|
||||
};
|
||||
|
||||
export const setOrder = ({ commit }, isOrderAsc ) => {
|
||||
if (isOrderAsc)
|
||||
commit('setPostQueryAttribute', { attr: 'order', value: 'ASC' } );
|
||||
else
|
||||
commit('setPostQueryAttribute', { attr: 'order', value: 'DESC' } );
|
||||
export const setOrder = ({ commit }, order ) => {
|
||||
commit('setPostQueryAttribute', { attr: 'order', value: order } );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -21,3 +21,11 @@ export const getPage = state => {
|
|||
export const getItemsPerPage = state => {
|
||||
return state.postquery.perpage;
|
||||
};
|
||||
|
||||
export const getOrder = state => {
|
||||
return state.postquery.order;
|
||||
}
|
||||
|
||||
export const getOrderBy = state => {
|
||||
return state.postquery.orderby;
|
||||
};
|
Loading…
Reference in New Issue