Merge pull request #2580 from KeyboardHammer/authorSort

Add sorting to author page
This commit is contained in:
advplyr 2024-03-07 12:28:55 -06:00 committed by GitHub
commit 153f149d58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 2 deletions

View File

@ -98,6 +98,9 @@
<template v-else-if="page === 'authors'"> <template v-else-if="page === 'authors'">
<div class="flex-grow" /> <div class="flex-grow" />
<ui-btn v-if="userCanUpdate && authors && authors.length && !isBatchSelecting" :loading="processingAuthors" color="primary" small @click="matchAllAuthors">{{ $strings.ButtonMatchAllAuthors }}</ui-btn> <ui-btn v-if="userCanUpdate && authors && authors.length && !isBatchSelecting" :loading="processingAuthors" color="primary" small @click="matchAllAuthors">{{ $strings.ButtonMatchAllAuthors }}</ui-btn>
<!-- author sort select -->
<controls-sort-select v-if="authors && authors.length" v-model="settings.authorSortBy" :descending.sync="settings.authorSortDesc" :items="authorSortItems" class="w-36 sm:w-44 md:w-48 h-7.5 ml-1 sm:ml-4" @change="updateAuthorSort" />
</template> </template>
</div> </div>
</div> </div>
@ -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.LabelUpdatedAt,
value: 'updatedAt'
}
]
},
userIsAdminOrUp() { userIsAdminOrUp() {
return this.$store.getters['user/getIsAdminOrUp'] return this.$store.getters['user/getIsAdminOrUp']
}, },
@ -455,6 +482,9 @@ export default {
updateCollapseBookSeries() { updateCollapseBookSeries() {
this.saveSettings() this.saveSettings()
}, },
updateAuthorSort() {
this.saveSettings()
},
saveSettings() { saveSettings() {
this.$store.dispatch('user/updateUserSettings', this.settings) this.$store.dispatch('user/updateUserSettings', this.settings)
}, },

View File

@ -3,7 +3,7 @@
<app-book-shelf-toolbar page="authors" is-home :authors="authors" /> <app-book-shelf-toolbar page="authors" is-home :authors="authors" />
<div id="bookshelf" class="w-full h-full p-8 overflow-y-auto"> <div id="bookshelf" class="w-full h-full p-8 overflow-y-auto">
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">
<template v-for="author in authors"> <template v-for="author in authorsSorted">
<cards-author-card :key="author.id" :author="author" :width="160" :height="200" class="p-3" @edit="editAuthor" /> <cards-author-card :key="author.id" :author="author" :width="160" :height="200" class="p-3" @edit="editAuthor" />
</template> </template>
</div> </div>
@ -44,6 +44,22 @@ export default {
}, },
selectedAuthor() { selectedAuthor() {
return this.$store.state.globals.selectedAuthor return this.$store.state.globals.selectedAuthor
},
authorSortBy() {
return this.$store.getters['user/getUserSetting']('authorSortBy') || 'name'
},
authorSortDesc() {
return !!this.$store.getters['user/getUserSetting']('authorSortDesc')
},
authorsSorted() {
const sortProp = this.authorSortBy
const bDesc = this.authorSortDesc ? -1 : 1
return this.authors.sort((a, b) => {
if (typeof a[sortProp] === 'number' && typeof b[sortProp] === 'number') {
return a[sortProp] > b[sortProp] ? bDesc : -bDesc
}
return a[sortProp].localeCompare(b[sortProp], undefined, { sensitivity: 'base' }) * bDesc
})
} }
}, },
methods: { methods: {

View File

@ -11,7 +11,9 @@ export const state = () => ({
useChapterTrack: false, useChapterTrack: false,
seriesSortBy: 'name', seriesSortBy: 'name',
seriesSortDesc: false, seriesSortDesc: false,
seriesFilterBy: 'all' seriesFilterBy: 'all',
authorSortBy: 'name',
authorSortDesc: false
} }
}) })

View File

@ -660,6 +660,7 @@ class LibraryController {
for (const author of authors) { for (const author of authors) {
const oldAuthor = author.getOldAuthor().toJSON() const oldAuthor = author.getOldAuthor().toJSON()
oldAuthor.numBooks = author.books.length oldAuthor.numBooks = author.books.length
oldAuthor.lastFirst = author.lastFirst
oldAuthors.push(oldAuthor) oldAuthors.push(oldAuthor)
} }