Add secondary sort by series sort title when sorting by author #274

This commit is contained in:
advplyr 2022-04-22 17:11:03 -05:00
parent d4525ad5ca
commit 1b79b3f42d
2 changed files with 26 additions and 4 deletions

View File

@ -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

View File

@ -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()