Newer
Older
<script>
export default {
props: {
defaultOrdering: {type: String, required: false}
},
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
computed: {
paginateBy: {
set(paginateBy) {
this.$store.commit('ui/paginateBy', {
route: this.$route.name,
value: paginateBy
})
},
get() {
return this.$store.state.ui.routePreferences[this.$route.name].paginateBy
}
},
ordering: {
set(ordering) {
this.$store.commit('ui/ordering', {
route: this.$route.name,
value: ordering
})
},
get() {
return this.$store.state.ui.routePreferences[this.$route.name].ordering
}
},
orderingDirection: {
set(orderingDirection) {
this.$store.commit('ui/orderingDirection', {
route: this.$route.name,
value: orderingDirection
})
},
get() {
return this.$store.state.ui.routePreferences[this.$route.name].orderingDirection
}
},
},
methods: {
getOrderingFromString (s) {
let parts = s.split('-')
if (parts.length > 1) {
return {
direction: '-',
field: parts.slice(1).join('-')
}
} else {
return {
field: s
}
}
},
getOrderingAsString () {
let direction = this.orderingDirection
if (direction === '+') {
direction = ''
}
return [direction, this.ordering].join('')