mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-24 04:39:40 +00:00
SortBy Options: Started Date & Finished Date implemented. English-only strings
This commit is contained in:
parent
28d98b4dbc
commit
c023f029d7
4 changed files with 46 additions and 5 deletions
|
|
@ -290,6 +290,18 @@ module.exports = {
|
|||
return [[Sequelize.literal(`CAST(\`series.bookSeries.sequence\` AS FLOAT) ${nullDir}`)]]
|
||||
} else if (sortBy === 'progress') {
|
||||
return [[Sequelize.literal('mediaProgresses.updatedAt'), dir]]
|
||||
} else if (sortBy === 'startedDate') {
|
||||
// Sort started books first (not null), then unstarted (nulls last), then by createdAt desc
|
||||
return [
|
||||
[Sequelize.literal('(CASE WHEN mediaProgresses.createdAt IS NULL THEN 1 ELSE 0 END)'), 'ASC'],
|
||||
['mediaProgresses', 'createdAt', dir]
|
||||
]
|
||||
} else if (sortBy === 'finishedDate') {
|
||||
// Sort finished books first (not null), then unfinished (nulls last), then by finishedAt desc
|
||||
return [
|
||||
[Sequelize.literal('(CASE WHEN mediaProgresses.finishedAt IS NULL THEN 1 ELSE 0 END)'), 'ASC'],
|
||||
['mediaProgresses', 'finishedAt', dir]
|
||||
]
|
||||
} else if (sortBy === 'random') {
|
||||
return [Database.sequelize.random()]
|
||||
}
|
||||
|
|
@ -519,7 +531,7 @@ module.exports = {
|
|||
}
|
||||
bookIncludes.push({
|
||||
model: Database.mediaProgressModel,
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt', 'createdAt', 'finishedAt'],
|
||||
where: mediaProgressWhere,
|
||||
required: false
|
||||
})
|
||||
|
|
@ -530,10 +542,10 @@ module.exports = {
|
|||
}
|
||||
|
||||
// When sorting by progress but not filtering by progress, include media progresses
|
||||
if (filterGroup !== 'progress' && sortBy === 'progress') {
|
||||
if (filterGroup !== 'progress' && ['startedDate', 'finishedDate', 'progress'].includes(sortBy)) {
|
||||
bookIncludes.push({
|
||||
model: Database.mediaProgressModel,
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt', 'createdAt', 'finishedAt'],
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue