From e2bb0cfb7cb7fb4587eaf0ff346296c37c24b315 Mon Sep 17 00:00:00 2001 From: KeyboardHammer Date: Sat, 3 Feb 2024 21:48:35 -0600 Subject: [PATCH 1/3] add sorting to author page --- client/components/app/BookShelfToolbar.vue | 30 +++++++++++++++++++ .../pages/library/_library/authors/index.vue | 23 +++++++++++++- client/store/user.js | 4 ++- server/controllers/LibraryController.js | 1 + 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/client/components/app/BookShelfToolbar.vue b/client/components/app/BookShelfToolbar.vue index bd31768b..74ab02f1 100644 --- a/client/components/app/BookShelfToolbar.vue +++ b/client/components/app/BookShelfToolbar.vue @@ -98,6 +98,9 @@ @@ -183,6 +186,30 @@ export default { } ] }, + authorSortItems() { + return [ + { + text: this.$strings.LabelAuthorFirstLast, + value: 'name' + }, + { + text: this.$strings.LabelAuthorLastFirst, + value: 'lastFirst' + }, + { + text: this.$strings.LabelNumberOfBooks, + value: 'numBooks' + }, + { + text: this.$strings.LabelAddedAt, + value: 'addedAt' + }, + { + text: this.$strings.LabelLastUpdated, + value: 'lastUpdated' + } + ] + }, userIsAdminOrUp() { return this.$store.getters['user/getIsAdminOrUp'] }, @@ -455,6 +482,9 @@ export default { updateCollapseBookSeries() { this.saveSettings() }, + updateAuthorSort() { + this.saveSettings() + }, saveSettings() { this.$store.dispatch('user/updateUserSettings', this.settings) }, diff --git a/client/pages/library/_library/authors/index.vue b/client/pages/library/_library/authors/index.vue index 1f8e385b..a81865a5 100644 --- a/client/pages/library/_library/authors/index.vue +++ b/client/pages/library/_library/authors/index.vue @@ -48,9 +48,12 @@ export default { }, methods: { async init() { + this.settings = { ...this.$store.state.user.settings } this.authors = await this.$axios .$get(`/api/libraries/${this.currentLibraryId}/authors`) - .then((response) => response.authors) + .then((response) => { + return this.sortAuthors(response.authors) + }) .catch((error) => { console.error('Failed to load authors', error) return [] @@ -78,15 +81,33 @@ export default { }, editAuthor(author) { this.$store.commit('globals/showEditAuthorModal', author) + }, + sortAuthors(authors) { + const sortProp = this.settings.authorSortBy + const bDesc = this.settings.authorSortDesc === true ? -1 : 1 + return authors.sort((a, b) => { + if (typeof a[sortProp] === 'number' && typeof b[sortProp] === 'number') { + return a[sortProp] > b[sortProp] ? 1 * bDesc : -1 * bDesc + } + return a[sortProp].localeCompare(b[sortProp], undefined, { sensitivity: 'base' }) * bDesc + }) + }, + settingsUpdated(settings) { + for (const key in settings) { + this.settings[key] = settings[key] + } + this.sortAuthors(this.authors) } }, mounted() { this.init() + this.$eventBus.$on('user-settings', this.settingsUpdated) this.$root.socket.on('author_added', this.authorAdded) this.$root.socket.on('author_updated', this.authorUpdated) this.$root.socket.on('author_removed', this.authorRemoved) }, beforeDestroy() { + this.$eventBus.$off('user-settings', this.settingsUpdated) this.$root.socket.off('author_added', this.authorAdded) this.$root.socket.off('author_updated', this.authorUpdated) this.$root.socket.off('author_removed', this.authorRemoved) diff --git a/client/store/user.js b/client/store/user.js index 85babb09..40a8813f 100644 --- a/client/store/user.js +++ b/client/store/user.js @@ -11,7 +11,9 @@ export const state = () => ({ useChapterTrack: false, seriesSortBy: 'name', seriesSortDesc: false, - seriesFilterBy: 'all' + seriesFilterBy: 'all', + authorSortBy: 'name', + authorSortDesc: false, } }) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 70baff85..b2500d4f 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -636,6 +636,7 @@ class LibraryController { for (const author of authors) { const oldAuthor = author.getOldAuthor().toJSON() oldAuthor.numBooks = author.books.length + oldAuthor.lastFirst = author.lastFirst oldAuthors.push(oldAuthor) } From d24427aad8dd613d2035e0424930f705527b185a Mon Sep 17 00:00:00 2001 From: KeyboardHammer Date: Sat, 3 Feb 2024 22:04:40 -0600 Subject: [PATCH 2/3] fix property --- client/components/app/BookShelfToolbar.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/components/app/BookShelfToolbar.vue b/client/components/app/BookShelfToolbar.vue index 74ab02f1..9064c914 100644 --- a/client/components/app/BookShelfToolbar.vue +++ b/client/components/app/BookShelfToolbar.vue @@ -205,8 +205,8 @@ export default { value: 'addedAt' }, { - text: this.$strings.LabelLastUpdated, - value: 'lastUpdated' + text: this.$strings.LabelUpdatedAt, + value: 'updatedAt' } ] }, From 305689d5130eb8c481005ef5e9c08e7612af14de Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 7 Mar 2024 12:26:04 -0600 Subject: [PATCH 3/3] Update authors sort --- .../pages/library/_library/authors/index.vue | 41 ++++++++----------- client/store/user.js | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/client/pages/library/_library/authors/index.vue b/client/pages/library/_library/authors/index.vue index a81865a5..3906f671 100644 --- a/client/pages/library/_library/authors/index.vue +++ b/client/pages/library/_library/authors/index.vue @@ -3,7 +3,7 @@
-