mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 10:14:36 +02:00
Add published decade filter option (#3489)
* Add strings for PublishedDecade and PublishedDecades * Add publishedDecades filter options to LibraryFilterSelect * Add publishedDecades to libraries store * Add publishedDecades to getFilterData * Add database method to add published decades to filter data * Add published decade in BookScanner * Add 'publishedDecades' to invalidFilters in user.js * Add publishedDecades filter group to MediaGroupQuery * Update client/strings/en-us.json * Auto formatting --------- Co-authored-by: advplyr <dev@advplyr.com> Co-authored-by: advplyr <advplyr@protonmail.com>
This commit is contained in:
parent
e42db121ea
commit
f38b6636e3
8 changed files with 47 additions and 4 deletions
|
@ -26,7 +26,7 @@ module.exports = {
|
|||
let filterValue = null
|
||||
let filterGroup = null
|
||||
if (filterBy) {
|
||||
const searchGroups = ['genres', 'tags', 'series', 'authors', 'progress', 'narrators', 'publishers', 'missing', 'languages', 'tracks', 'ebooks']
|
||||
const searchGroups = ['genres', 'tags', 'series', 'authors', 'progress', 'narrators', 'publishers', 'publishedDecades', 'missing', 'languages', 'tracks', 'ebooks']
|
||||
const group = searchGroups.find((_group) => filterBy.startsWith(_group + '.'))
|
||||
filterGroup = group || filterBy
|
||||
filterValue = group ? this.decode(filterBy.replace(`${group}.`, '')) : null
|
||||
|
@ -458,6 +458,7 @@ module.exports = {
|
|||
narrators: new Set(),
|
||||
languages: new Set(),
|
||||
publishers: new Set(),
|
||||
publishedDecades: new Set(),
|
||||
numIssues: 0
|
||||
}
|
||||
|
||||
|
@ -492,7 +493,7 @@ module.exports = {
|
|||
libraryId: libraryId
|
||||
}
|
||||
},
|
||||
attributes: ['tags', 'genres', 'publisher', 'narrators', 'language']
|
||||
attributes: ['tags', 'genres', 'publisher', 'publishedYear', 'narrators', 'language']
|
||||
})
|
||||
for (const book of books) {
|
||||
if (book.libraryItem.isMissing || book.libraryItem.isInvalid) data.numIssues++
|
||||
|
@ -506,6 +507,11 @@ module.exports = {
|
|||
book.narrators.forEach((narrator) => data.narrators.add(narrator))
|
||||
}
|
||||
if (book.publisher) data.publishers.add(book.publisher)
|
||||
// Check if published year exists and is valid
|
||||
if (book.publishedYear && !isNaN(book.publishedYear) && book.publishedYear > 0 && book.publishedYear < 3000 && book.publishedYear.toString().length === 4) {
|
||||
const decade = Math.floor(book.publishedYear / 10) * 10
|
||||
data.publishedDecades.add(decade.toString())
|
||||
}
|
||||
if (book.language) data.languages.add(book.language)
|
||||
}
|
||||
|
||||
|
@ -532,6 +538,7 @@ module.exports = {
|
|||
data.series = naturalSort(data.series).asc((se) => se.name)
|
||||
data.narrators = naturalSort([...data.narrators]).asc()
|
||||
data.publishers = naturalSort([...data.publishers]).asc()
|
||||
data.publishedDecades = naturalSort([...data.publishedDecades]).asc()
|
||||
data.languages = naturalSort([...data.languages]).asc()
|
||||
data.loadedAt = Date.now()
|
||||
Database.libraryFilterData[libraryId] = data
|
||||
|
|
|
@ -228,6 +228,11 @@ module.exports = {
|
|||
} else if (value === 'series') {
|
||||
mediaWhere['$series.id$'] = null
|
||||
}
|
||||
} else if (group === 'publishedDecades') {
|
||||
const year = parseInt(value, 10)
|
||||
mediaWhere['publishedYear'] = {
|
||||
[Sequelize.Op.between]: year >= 1000 ? [year, year + 9] : [year * 10, (year + 1) * 10 - 1]
|
||||
}
|
||||
}
|
||||
|
||||
return { mediaWhere, replacements }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue