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:
Greg Lorenzen 2024-10-08 15:20:42 -07:00 committed by GitHub
parent e42db121ea
commit f38b6636e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 4 deletions

View File

@ -189,6 +189,12 @@ export default {
value: 'publishers', value: 'publishers',
sublist: true sublist: true
}, },
{
text: this.$strings.LabelPublishedDecade,
textPlural: this.$strings.LabelPublishedDecades,
value: 'publishedDecades',
sublist: true
},
{ {
text: this.$strings.LabelLanguage, text: this.$strings.LabelLanguage,
textPlural: this.$strings.LabelLanguages, textPlural: this.$strings.LabelLanguages,
@ -338,6 +344,9 @@ export default {
publishers() { publishers() {
return this.filterData.publishers || [] return this.filterData.publishers || []
}, },
publishedDecades() {
return this.filterData.publishedDecades || []
},
progress() { progress() {
return [ return [
{ {

View File

@ -240,7 +240,8 @@ export const mutations = {
series: [], series: [],
narrators: [], narrators: [],
languages: [], languages: [],
publishers: [] publishers: [],
publishedDecades: []
} }
*/ */
const mediaMetadata = libraryItem.media.metadata const mediaMetadata = libraryItem.media.metadata
@ -307,6 +308,16 @@ export const mutations = {
state.filterData.publishers.sort((a, b) => a.localeCompare(b)) state.filterData.publishers.sort((a, b) => a.localeCompare(b))
} }
// Add publishedDecades
if (mediaMetadata.publishedYear) {
const publishedYear = parseInt(mediaMetadata.publishedYear, 10)
const decade = Math.floor(publishedYear / 10) * 10
if (!state.filterData.publishedDecades.includes(decade)) {
state.filterData.publishedDecades.push(decade)
state.filterData.publishedDecades.sort((a, b) => a - b)
}
}
// Add language // Add language
if (mediaMetadata.language && !state.filterData.languages.includes(mediaMetadata.language)) { if (mediaMetadata.language && !state.filterData.languages.includes(mediaMetadata.language)) {
state.filterData.languages.push(mediaMetadata.language) state.filterData.languages.push(mediaMetadata.language)

View File

@ -90,7 +90,7 @@ export const actions = {
if (state.settings.orderBy == 'media.metadata.publishedYear') { if (state.settings.orderBy == 'media.metadata.publishedYear') {
settingsUpdate.orderBy = 'media.metadata.title' settingsUpdate.orderBy = 'media.metadata.title'
} }
const invalidFilters = ['series', 'authors', 'narrators', 'publishers', 'languages', 'progress', 'issues', 'ebooks', 'abridged'] const invalidFilters = ['series', 'authors', 'narrators', 'publishers', 'publishedDecades', 'languages', 'progress', 'issues', 'ebooks', 'abridged']
const filterByFirstPart = (state.settings.filterBy || '').split('.').shift() const filterByFirstPart = (state.settings.filterBy || '').split('.').shift()
if (invalidFilters.includes(filterByFirstPart)) { if (invalidFilters.includes(filterByFirstPart)) {
settingsUpdate.filterBy = 'all' settingsUpdate.filterBy = 'all'

View File

@ -465,6 +465,8 @@
"LabelPubDate": "Pub Date", "LabelPubDate": "Pub Date",
"LabelPublishYear": "Publish Year", "LabelPublishYear": "Publish Year",
"LabelPublishedDate": "Published {0}", "LabelPublishedDate": "Published {0}",
"LabelPublishedDecade": "Published Decade",
"LabelPublishedDecades": "Published Decades",
"LabelPublisher": "Publisher", "LabelPublisher": "Publisher",
"LabelPublishers": "Publishers", "LabelPublishers": "Publishers",
"LabelRSSFeedCustomOwnerEmail": "Custom owner Email", "LabelRSSFeedCustomOwnerEmail": "Custom owner Email",

View File

@ -607,6 +607,11 @@ class Database {
this.libraryFilterData[libraryId].publishers.push(publisher) this.libraryFilterData[libraryId].publishers.push(publisher)
} }
addPublishedDecadeToFilterData(libraryId, decade) {
if (!this.libraryFilterData[libraryId] || !decade || this.libraryFilterData[libraryId].publishedDecades.includes(decade)) return
this.libraryFilterData[libraryId].publishedDecades.push(decade)
}
addLanguageToFilterData(libraryId, language) { addLanguageToFilterData(libraryId, language) {
if (!this.libraryFilterData[libraryId] || !language || this.libraryFilterData[libraryId].languages.includes(language)) return if (!this.libraryFilterData[libraryId] || !language || this.libraryFilterData[libraryId].languages.includes(language)) return
this.libraryFilterData[libraryId].languages.push(language) this.libraryFilterData[libraryId].languages.push(language)

View File

@ -590,6 +590,10 @@ class BookScanner {
Database.addPublisherToFilterData(libraryItemData.libraryId, libraryItem.book.publisher) Database.addPublisherToFilterData(libraryItemData.libraryId, libraryItem.book.publisher)
Database.addLanguageToFilterData(libraryItemData.libraryId, libraryItem.book.language) Database.addLanguageToFilterData(libraryItemData.libraryId, libraryItem.book.language)
const publishedYear = libraryItem.book.publishedYear
const decade = publishedYear ? `${Math.floor(publishedYear / 10) * 10}` : null
Database.addPublishedDecadeToFilterData(libraryItemData.libraryId, decade)
// Load for emitting to client // Load for emitting to client
libraryItem.media = await libraryItem.getMedia({ libraryItem.media = await libraryItem.getMedia({
include: [ include: [

View File

@ -26,7 +26,7 @@ module.exports = {
let filterValue = null let filterValue = null
let filterGroup = null let filterGroup = null
if (filterBy) { 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 + '.')) const group = searchGroups.find((_group) => filterBy.startsWith(_group + '.'))
filterGroup = group || filterBy filterGroup = group || filterBy
filterValue = group ? this.decode(filterBy.replace(`${group}.`, '')) : null filterValue = group ? this.decode(filterBy.replace(`${group}.`, '')) : null
@ -458,6 +458,7 @@ module.exports = {
narrators: new Set(), narrators: new Set(),
languages: new Set(), languages: new Set(),
publishers: new Set(), publishers: new Set(),
publishedDecades: new Set(),
numIssues: 0 numIssues: 0
} }
@ -492,7 +493,7 @@ module.exports = {
libraryId: libraryId libraryId: libraryId
} }
}, },
attributes: ['tags', 'genres', 'publisher', 'narrators', 'language'] attributes: ['tags', 'genres', 'publisher', 'publishedYear', 'narrators', 'language']
}) })
for (const book of books) { for (const book of books) {
if (book.libraryItem.isMissing || book.libraryItem.isInvalid) data.numIssues++ if (book.libraryItem.isMissing || book.libraryItem.isInvalid) data.numIssues++
@ -506,6 +507,11 @@ module.exports = {
book.narrators.forEach((narrator) => data.narrators.add(narrator)) book.narrators.forEach((narrator) => data.narrators.add(narrator))
} }
if (book.publisher) data.publishers.add(book.publisher) 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) if (book.language) data.languages.add(book.language)
} }
@ -532,6 +538,7 @@ module.exports = {
data.series = naturalSort(data.series).asc((se) => se.name) data.series = naturalSort(data.series).asc((se) => se.name)
data.narrators = naturalSort([...data.narrators]).asc() data.narrators = naturalSort([...data.narrators]).asc()
data.publishers = naturalSort([...data.publishers]).asc() data.publishers = naturalSort([...data.publishers]).asc()
data.publishedDecades = naturalSort([...data.publishedDecades]).asc()
data.languages = naturalSort([...data.languages]).asc() data.languages = naturalSort([...data.languages]).asc()
data.loadedAt = Date.now() data.loadedAt = Date.now()
Database.libraryFilterData[libraryId] = data Database.libraryFilterData[libraryId] = data

View File

@ -228,6 +228,11 @@ module.exports = {
} else if (value === 'series') { } else if (value === 'series') {
mediaWhere['$series.id$'] = null 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 } return { mediaWhere, replacements }