mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-11 15:59:28 +01:00
add sorting to author page
This commit is contained in:
parent
432e25565e
commit
e2bb0cfb7c
@ -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.LabelLastUpdated,
|
||||||
|
value: 'lastUpdated'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
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)
|
||||||
},
|
},
|
||||||
|
@ -48,9 +48,12 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async init() {
|
async init() {
|
||||||
|
this.settings = { ...this.$store.state.user.settings }
|
||||||
this.authors = await this.$axios
|
this.authors = await this.$axios
|
||||||
.$get(`/api/libraries/${this.currentLibraryId}/authors`)
|
.$get(`/api/libraries/${this.currentLibraryId}/authors`)
|
||||||
.then((response) => response.authors)
|
.then((response) => {
|
||||||
|
return this.sortAuthors(response.authors)
|
||||||
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Failed to load authors', error)
|
console.error('Failed to load authors', error)
|
||||||
return []
|
return []
|
||||||
@ -78,15 +81,33 @@ export default {
|
|||||||
},
|
},
|
||||||
editAuthor(author) {
|
editAuthor(author) {
|
||||||
this.$store.commit('globals/showEditAuthorModal', 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() {
|
mounted() {
|
||||||
this.init()
|
this.init()
|
||||||
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
||||||
this.$root.socket.on('author_added', this.authorAdded)
|
this.$root.socket.on('author_added', this.authorAdded)
|
||||||
this.$root.socket.on('author_updated', this.authorUpdated)
|
this.$root.socket.on('author_updated', this.authorUpdated)
|
||||||
this.$root.socket.on('author_removed', this.authorRemoved)
|
this.$root.socket.on('author_removed', this.authorRemoved)
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
||||||
this.$root.socket.off('author_added', this.authorAdded)
|
this.$root.socket.off('author_added', this.authorAdded)
|
||||||
this.$root.socket.off('author_updated', this.authorUpdated)
|
this.$root.socket.off('author_updated', this.authorUpdated)
|
||||||
this.$root.socket.off('author_removed', this.authorRemoved)
|
this.$root.socket.off('author_removed', this.authorRemoved)
|
||||||
|
@ -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,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -636,6 +636,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user