mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Merge pull request #2580 from KeyboardHammer/authorSort
Add sorting to author page
This commit is contained in:
commit
153f149d58
@ -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)
|
||||||
},
|
},
|
||||||
|
@ -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: {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user