From 4f33de1257a09dfb97042eb4fabe939a2cb8d69d Mon Sep 17 00:00:00 2001 From: Sven Roman Reinhard Date: Thu, 13 Nov 2025 13:39:27 +0100 Subject: [PATCH 1/2] added sorting narators by name and book count --- client/pages/library/_library/narrators.vue | 38 ++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/client/pages/library/_library/narrators.vue b/client/pages/library/_library/narrators.vue index 9e58bf14..089c969a 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() { From 5148502da78cb251bb1a4eddddc78301d2180a67 Mon Sep 17 00:00:00 2001 From: Sven Roman Reinhard <75866827+S-Reinhard@users.noreply.github.com> Date: Tue, 10 Mar 2026 04:23:49 +0100 Subject: [PATCH 2/2] implemented server side sort --- client/pages/library/_library/narrators.vue | 44 ++++++++++----------- server/controllers/LibraryController.js | 8 +++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/client/pages/library/_library/narrators.vue b/client/pages/library/_library/narrators.vue index 089c969a..80dafddb 100644 --- a/client/pages/library/_library/narrators.vue +++ b/client/pages/library/_library/narrators.vue @@ -4,11 +4,11 @@
- - + + - +
{{ $strings.LabelName }} {{ sortingArrow('name') }}{{ $strings.LabelBooks }} {{ sortingArrow('numBooks') }}{{ $strings.LabelName }} {{ sortingArrow('name') }}{{ $strings.LabelBooks }} {{ sortingArrow('numBooks') }}
{{ narrator.name }} @@ -64,8 +64,8 @@ export default { narrators: [], selectedNarrator: null, newNarratorName: null, - currentSortAttribute: '', - currentSortOrder: 'asc' + sortBy: 'name', + sortOrder: 'asc' } }, computed: { @@ -77,14 +77,6 @@ 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: { @@ -153,8 +145,12 @@ export default { }) }, async init() { + await this.fetchNarrators() + }, + async fetchNarrators() { + this.loading = true this.narrators = await this.$axios - .$get(`/api/libraries/${this.currentLibraryId}/narrators`) + .$get(`/api/libraries/${this.currentLibraryId}/narrators`, {params: {sortOrder: this.sortOrder, sortBy: this.sortBy}}) .then((response) => response.narrators) .catch((error) => { console.error('Failed to load narrators', error) @@ -162,22 +158,22 @@ export default { }) this.loading = false }, - sortNarratorsBy(attribute) { - if (this.currentSortAttribute == attribute) { - if (this.currentSortOrder == 'asc') { - this.currentSortOrder = 'desc'; + async sortNarratorsBy(attribute) { + if (this.sortBy == attribute) { + if (this.sortOrder == 'asc') { + this.sortOrder = 'desc'; } else { - this.currentSortOrder = 'asc'; + this.sortOrder = 'asc'; } } else { - this.currentSortAttribute = attribute; - this.currentSortOrder = 'asc' + this.sortBy = attribute; + this.sortOrder = 'asc'; } - + await this.fetchNarrators(); }, sortingArrow(attribute) { - if (this.currentSortAttribute == attribute) { - return this.currentSortOrder == 'asc'? '↓' : '↑'; + if (this.sortBy == attribute) { + return this.sortOrder == 'asc'? '▲' : '▼'; } else { return ''; } diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 55ef4569..838be675 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -1140,8 +1140,14 @@ class LibraryController { }) } + // sorting + const key = req.query.sortBy === 'numBooks' ? 'numBooks' : 'name'; + const order = req.query.sortOrder === 'desc' ? 'desc' : 'asc'; + const narratorArr = Object.values(narrators); + const sorted = naturalSort(narratorArr)[order]((n) => n[key]) + res.json({ - narrators: naturalSort(Object.values(narrators)).asc((n) => n.name) + narrators: sorted }) }