mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-30 04:25:03 +02:00
Handle sorting when collapsing by series and filtering by series on library page
This commit is contained in:
parent
826963bf00
commit
9e13c64408
2 changed files with 50 additions and 11 deletions
|
@ -130,20 +130,53 @@ module.exports = {
|
|||
payload.total = libraryItems.length
|
||||
}
|
||||
|
||||
const sortArray = [
|
||||
{
|
||||
asc: (li) => li.media.metadata.getSeries(seriesId).sequence
|
||||
},
|
||||
{ // If no series sequence then fallback to sorting by title (or collapsed series name for sub-series)
|
||||
asc: (li) => {
|
||||
if (Database.serverSettings.sortingIgnorePrefix) {
|
||||
return li.collapsedSeries?.nameIgnorePrefix || li.media.metadata.titleIgnorePrefix
|
||||
} else {
|
||||
return li.collapsedSeries?.name || li.media.metadata.title
|
||||
const sortingIgnorePrefix = Database.serverSettings.sortingIgnorePrefix
|
||||
|
||||
let sortArray = []
|
||||
const direction = payload.sortDesc ? 'desc' : 'asc'
|
||||
if (!payload.sortBy || payload.sortBy === 'sequence') {
|
||||
sortArray = [
|
||||
{
|
||||
[direction]: (li) => li.media.metadata.getSeries(seriesId).sequence
|
||||
},
|
||||
{ // If no series sequence then fallback to sorting by title (or collapsed series name for sub-series)
|
||||
[direction]: (li) => {
|
||||
if (sortingIgnorePrefix) {
|
||||
return li.collapsedSeries?.nameIgnorePrefix || li.media.metadata.titleIgnorePrefix
|
||||
} else {
|
||||
return li.collapsedSeries?.name || li.media.metadata.title
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
} else {
|
||||
// If series are collapsed and not sorting by title or sequence,
|
||||
// sort all collapsed series to the end in alphabetical order
|
||||
if (payload.sortBy !== 'media.metadata.title') {
|
||||
sortArray.push({
|
||||
asc: (li) => {
|
||||
if (li.collapsedSeries) {
|
||||
return sortingIgnorePrefix ? li.collapsedSeries.nameIgnorePrefix : li.collapsedSeries.name
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
]
|
||||
sortArray.push({
|
||||
[direction]: (li) => {
|
||||
if (payload.sortBy === 'media.metadata.title') {
|
||||
if (sortingIgnorePrefix) {
|
||||
return li.collapsedSeries?.nameIgnorePrefix || li.media.metadata.titleIgnorePrefix
|
||||
} else {
|
||||
return li.collapsedSeries?.name || li.media.metadata.title
|
||||
}
|
||||
} else {
|
||||
return payload.sortBy.split('.').reduce((a, b) => a[b], li)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
libraryItems = naturalSort(libraryItems).by(sortArray)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue