mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Add secondary sort by series sort title when sorting by author #274
This commit is contained in:
parent
d4525ad5ca
commit
1b79b3f42d
@ -176,12 +176,29 @@ class LibraryController {
|
||||
sortKey += 'IgnorePrefix'
|
||||
}
|
||||
|
||||
// Start sort
|
||||
var direction = payload.sortDesc ? 'desc' : 'asc'
|
||||
libraryItems = naturalSort(libraryItems)[direction]((li) => {
|
||||
var sortArray = [
|
||||
{
|
||||
[direction]: (li) => {
|
||||
// Supports dot notation strings i.e. "media.metadata.title"
|
||||
return sortKey.split('.').reduce((a, b) => a[b], li)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
// Supports dot notation strings i.e. "media.metadata.title"
|
||||
return sortKey.split('.').reduce((a, b) => a[b], li)
|
||||
})
|
||||
// Secondary sort when sorting by book author use series sort title
|
||||
if (payload.mediaType === 'book' && payload.sortBy.includes('author')) {
|
||||
sortArray.push({
|
||||
asc: (li) => {
|
||||
if (li.media.metadata.series && li.media.metadata.series.length) {
|
||||
return li.media.metadata.getSeriesSortTitle(li.media.metadata.series[0])
|
||||
}
|
||||
return null
|
||||
}
|
||||
})
|
||||
}
|
||||
libraryItems = naturalSort(libraryItems).by(sortArray)
|
||||
}
|
||||
|
||||
// TODO: Potentially implement collapse series again
|
||||
|
@ -162,6 +162,11 @@ class BookMetadata {
|
||||
if (!series) return null
|
||||
return series.sequence || ''
|
||||
}
|
||||
getSeriesSortTitle(series) {
|
||||
if (!series) return ''
|
||||
if (!series.sequence) return series.name
|
||||
return `${series.name} #${series.sequence}`
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var json = this.toJSON()
|
||||
|
Loading…
Reference in New Issue
Block a user