diff --git a/client/pages/library/_library/narrators.vue b/client/pages/library/_library/narrators.vue index 9e58bf146..089c969a4 100644 --- a/client/pages/library/_library/narrators.vue +++ b/client/pages/library/_library/narrators.vue @@ -4,11 +4,11 @@
- - + + - +
{{ $strings.LabelName }}{{ $strings.LabelBooks }}{{ $strings.LabelName }} {{ sortingArrow('name') }}{{ $strings.LabelBooks }} {{ sortingArrow('numBooks') }}
{{ narrator.name }}
@@ -63,7 +63,9 @@ export default { loading: true, narrators: [], selectedNarrator: null, - newNarratorName: null + newNarratorName: null, + currentSortAttribute: '', + currentSortOrder: 'asc' } }, computed: { @@ -75,6 +77,14 @@ export default { }, userCanUpdate() { return this.$store.getters['user/getUserCanUpdate'] + }, + sortedNarrators() { + return this.narrators.sort((a,b) => { + let modifier = this.currentSortOrder == 'asc'? 1: -1; + if (a[this.currentSortAttribute] < b[this.currentSortAttribute]) return -1*modifier; + if (a[this.currentSortAttribute] > b[this.currentSortAttribute]) return modifier; + return 0; + }) } }, methods: { @@ -151,6 +161,26 @@ export default { return [] }) this.loading = false + }, + sortNarratorsBy(attribute) { + if (this.currentSortAttribute == attribute) { + if (this.currentSortOrder == 'asc') { + this.currentSortOrder = 'desc'; + } else { + this.currentSortOrder = 'asc'; + } + } else { + this.currentSortAttribute = attribute; + this.currentSortOrder = 'asc' + } + + }, + sortingArrow(attribute) { + if (this.currentSortAttribute == attribute) { + return this.currentSortOrder == 'asc'? '↓' : '↑'; + } else { + return ''; + } } }, mounted() {