mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Add:Library filter for publishers & link to publisher filter on book page #1813
This commit is contained in:
parent
9439acf300
commit
b108f2241b
@ -24,7 +24,7 @@
|
|||||||
<span class="text-white text-opacity-60 uppercase text-sm">{{ $strings.LabelPublisher }}</span>
|
<span class="text-white text-opacity-60 uppercase text-sm">{{ $strings.LabelPublisher }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{ publisher }}
|
<nuxt-link :to="`/library/${libraryId}/bookshelf?filter=publishers.${$encode(publisher)}`" class="hover:underline">{{ publisher }}</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="musicAlbum" class="flex py-0.5">
|
<div v-if="musicAlbum" class="flex py-0.5">
|
||||||
|
@ -124,6 +124,11 @@ export default {
|
|||||||
value: 'narrators',
|
value: 'narrators',
|
||||||
sublist: true
|
sublist: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: this.$strings.LabelPublisher,
|
||||||
|
value: 'publishers',
|
||||||
|
sublist: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: this.$strings.LabelLanguage,
|
text: this.$strings.LabelLanguage,
|
||||||
value: 'languages',
|
value: 'languages',
|
||||||
@ -167,6 +172,11 @@ export default {
|
|||||||
value: 'narrators',
|
value: 'narrators',
|
||||||
sublist: true
|
sublist: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: this.$strings.LabelPublisher,
|
||||||
|
value: 'publishers',
|
||||||
|
sublist: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: this.$strings.LabelLanguage,
|
text: this.$strings.LabelLanguage,
|
||||||
value: 'languages',
|
value: 'languages',
|
||||||
@ -313,6 +323,9 @@ export default {
|
|||||||
languages() {
|
languages() {
|
||||||
return this.filterData.languages || []
|
return this.filterData.languages || []
|
||||||
},
|
},
|
||||||
|
publishers() {
|
||||||
|
return this.filterData.publishers || []
|
||||||
|
},
|
||||||
progress() {
|
progress() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -238,21 +238,23 @@ export const mutations = {
|
|||||||
if (!libraryItem || !state.filterData) return
|
if (!libraryItem || !state.filterData) return
|
||||||
if (state.currentLibraryId !== libraryItem.libraryId) return
|
if (state.currentLibraryId !== libraryItem.libraryId) return
|
||||||
/*
|
/*
|
||||||
var data = {
|
structure of filterData:
|
||||||
|
{
|
||||||
authors: [],
|
authors: [],
|
||||||
genres: [],
|
genres: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
series: [],
|
series: [],
|
||||||
narrators: [],
|
narrators: [],
|
||||||
languages: []
|
languages: [],
|
||||||
|
publishers: []
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
var mediaMetadata = libraryItem.media.metadata
|
const mediaMetadata = libraryItem.media.metadata
|
||||||
|
|
||||||
// Add/update book authors
|
// Add/update book authors
|
||||||
if (mediaMetadata.authors && mediaMetadata.authors.length) {
|
if (mediaMetadata.authors?.length) {
|
||||||
mediaMetadata.authors.forEach((author) => {
|
mediaMetadata.authors.forEach((author) => {
|
||||||
var indexOf = state.filterData.authors.findIndex(au => au.id === author.id)
|
const indexOf = state.filterData.authors.findIndex(au => au.id === author.id)
|
||||||
if (indexOf >= 0) {
|
if (indexOf >= 0) {
|
||||||
state.filterData.authors.splice(indexOf, 1, author)
|
state.filterData.authors.splice(indexOf, 1, author)
|
||||||
} else {
|
} else {
|
||||||
@ -263,9 +265,9 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add/update series
|
// Add/update series
|
||||||
if (mediaMetadata.series && mediaMetadata.series.length) {
|
if (mediaMetadata.series?.length) {
|
||||||
mediaMetadata.series.forEach((series) => {
|
mediaMetadata.series.forEach((series) => {
|
||||||
var indexOf = state.filterData.series.findIndex(se => se.id === series.id)
|
const indexOf = state.filterData.series.findIndex(se => se.id === series.id)
|
||||||
if (indexOf >= 0) {
|
if (indexOf >= 0) {
|
||||||
state.filterData.series.splice(indexOf, 1, { id: series.id, name: series.name })
|
state.filterData.series.splice(indexOf, 1, { id: series.id, name: series.name })
|
||||||
} else {
|
} else {
|
||||||
@ -276,7 +278,7 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add genres
|
// Add genres
|
||||||
if (mediaMetadata.genres && mediaMetadata.genres.length) {
|
if (mediaMetadata.genres?.length) {
|
||||||
mediaMetadata.genres.forEach((genre) => {
|
mediaMetadata.genres.forEach((genre) => {
|
||||||
if (!state.filterData.genres.includes(genre)) {
|
if (!state.filterData.genres.includes(genre)) {
|
||||||
state.filterData.genres.push(genre)
|
state.filterData.genres.push(genre)
|
||||||
@ -286,7 +288,7 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add tags
|
// Add tags
|
||||||
if (libraryItem.media.tags && libraryItem.media.tags.length) {
|
if (libraryItem.media.tags?.length) {
|
||||||
libraryItem.media.tags.forEach((tag) => {
|
libraryItem.media.tags.forEach((tag) => {
|
||||||
if (!state.filterData.tags.includes(tag)) {
|
if (!state.filterData.tags.includes(tag)) {
|
||||||
state.filterData.tags.push(tag)
|
state.filterData.tags.push(tag)
|
||||||
@ -296,7 +298,7 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add narrators
|
// Add narrators
|
||||||
if (mediaMetadata.narrators && mediaMetadata.narrators.length) {
|
if (mediaMetadata.narrators?.length) {
|
||||||
mediaMetadata.narrators.forEach((narrator) => {
|
mediaMetadata.narrators.forEach((narrator) => {
|
||||||
if (!state.filterData.narrators.includes(narrator)) {
|
if (!state.filterData.narrators.includes(narrator)) {
|
||||||
state.filterData.narrators.push(narrator)
|
state.filterData.narrators.push(narrator)
|
||||||
@ -305,12 +307,16 @@ export const mutations = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add publishers
|
||||||
|
if (mediaMetadata.publisher && !state.filterData.publishers.includes(mediaMetadata.publisher)) {
|
||||||
|
state.filterData.publishers.push(mediaMetadata.publisher)
|
||||||
|
state.filterData.publishers.sort((a, b) => a.localeCompare(b))
|
||||||
|
}
|
||||||
|
|
||||||
// Add language
|
// Add language
|
||||||
if (mediaMetadata.language) {
|
if (mediaMetadata.language && !state.filterData.languages.includes(mediaMetadata.language)) {
|
||||||
if (!state.filterData.languages.includes(mediaMetadata.language)) {
|
state.filterData.languages.push(mediaMetadata.language)
|
||||||
state.filterData.languages.push(mediaMetadata.language)
|
state.filterData.languages.sort((a, b) => a.localeCompare(b))
|
||||||
state.filterData.languages.sort((a, b) => a.localeCompare(b))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setCollections(state, collections) {
|
setCollections(state, collections) {
|
||||||
|
@ -80,7 +80,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', 'languages', 'progress', 'issues', 'ebooks', 'abridged']
|
const invalidFilters = ['series', 'authors', 'narrators', 'publishers', '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'
|
||||||
|
@ -14,7 +14,7 @@ module.exports = {
|
|||||||
getFilteredLibraryItems(libraryItems, filterBy, user, feedsArray) {
|
getFilteredLibraryItems(libraryItems, filterBy, user, feedsArray) {
|
||||||
let filtered = libraryItems
|
let filtered = libraryItems
|
||||||
|
|
||||||
const searchGroups = ['genres', 'tags', 'series', 'authors', 'progress', 'narrators', 'missing', 'languages', 'tracks', 'ebooks']
|
const searchGroups = ['genres', 'tags', 'series', 'authors', 'progress', 'narrators', 'publishers', 'missing', 'languages', 'tracks', 'ebooks']
|
||||||
const group = searchGroups.find(_group => filterBy.startsWith(_group + '.'))
|
const group = searchGroups.find(_group => filterBy.startsWith(_group + '.'))
|
||||||
if (group) {
|
if (group) {
|
||||||
const filterVal = filterBy.replace(`${group}.`, '')
|
const filterVal = filterBy.replace(`${group}.`, '')
|
||||||
@ -29,6 +29,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
else if (group === 'authors') filtered = filtered.filter(li => li.isBook && li.media.metadata.hasAuthor(filter))
|
else if (group === 'authors') filtered = filtered.filter(li => li.isBook && li.media.metadata.hasAuthor(filter))
|
||||||
else if (group === 'narrators') filtered = filtered.filter(li => li.isBook && li.media.metadata.hasNarrator(filter))
|
else if (group === 'narrators') filtered = filtered.filter(li => li.isBook && li.media.metadata.hasNarrator(filter))
|
||||||
|
else if (group === 'publishers') filtered = filtered.filter(li => li.isBook && li.media.metadata.publisher === filter)
|
||||||
else if (group === 'progress') {
|
else if (group === 'progress') {
|
||||||
filtered = filtered.filter(li => {
|
filtered = filtered.filter(li => {
|
||||||
const itemProgress = user.getMediaProgress(li.id)
|
const itemProgress = user.getMediaProgress(li.id)
|
||||||
@ -82,16 +83,17 @@ module.exports = {
|
|||||||
|
|
||||||
// Returns false if should be filtered out
|
// Returns false if should be filtered out
|
||||||
checkFilterForSeriesLibraryItem(libraryItem, filterBy) {
|
checkFilterForSeriesLibraryItem(libraryItem, filterBy) {
|
||||||
var searchGroups = ['genres', 'tags', 'authors', 'progress', 'narrators', 'languages']
|
const searchGroups = ['genres', 'tags', 'authors', 'progress', 'narrators', 'publishers', 'languages']
|
||||||
var group = searchGroups.find(_group => filterBy.startsWith(_group + '.'))
|
const group = searchGroups.find(_group => filterBy.startsWith(_group + '.'))
|
||||||
if (group) {
|
if (group) {
|
||||||
var filterVal = filterBy.replace(`${group}.`, '')
|
const filterVal = filterBy.replace(`${group}.`, '')
|
||||||
var filter = this.decode(filterVal)
|
const filter = this.decode(filterVal)
|
||||||
|
|
||||||
if (group === 'genres') return libraryItem.media.metadata.genres.includes(filter)
|
if (group === 'genres') return libraryItem.media.metadata.genres.includes(filter)
|
||||||
else if (group === 'tags') return libraryItem.media.tags.includes(filter)
|
else if (group === 'tags') return libraryItem.media.tags.includes(filter)
|
||||||
else if (group === 'authors') return libraryItem.isBook && libraryItem.media.metadata.hasAuthor(filter)
|
else if (group === 'authors') return libraryItem.isBook && libraryItem.media.metadata.hasAuthor(filter)
|
||||||
else if (group === 'narrators') return libraryItem.isBook && libraryItem.media.metadata.hasNarrator(filter)
|
else if (group === 'narrators') return libraryItem.isBook && libraryItem.media.metadata.hasNarrator(filter)
|
||||||
|
else if (group === 'publishers') return libraryItem.isBook && libraryItem.media.metadata.publisher === filter
|
||||||
else if (group === 'languages') {
|
else if (group === 'languages') {
|
||||||
return libraryItem.media.metadata.language === filter
|
return libraryItem.media.metadata.language === filter
|
||||||
}
|
}
|
||||||
@ -123,27 +125,28 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDistinctFilterDataNew(libraryItems) {
|
getDistinctFilterDataNew(libraryItems) {
|
||||||
var data = {
|
const data = {
|
||||||
authors: [],
|
authors: [],
|
||||||
genres: [],
|
genres: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
series: [],
|
series: [],
|
||||||
narrators: [],
|
narrators: [],
|
||||||
languages: []
|
languages: [],
|
||||||
|
publishers: []
|
||||||
}
|
}
|
||||||
libraryItems.forEach((li) => {
|
libraryItems.forEach((li) => {
|
||||||
var mediaMetadata = li.media.metadata
|
const mediaMetadata = li.media.metadata
|
||||||
if (mediaMetadata.authors && mediaMetadata.authors.length) {
|
if (mediaMetadata.authors?.length) {
|
||||||
mediaMetadata.authors.forEach((author) => {
|
mediaMetadata.authors.forEach((author) => {
|
||||||
if (author && !data.authors.find(au => au.id === author.id)) data.authors.push({ id: author.id, name: author.name })
|
if (author && !data.authors.some(au => au.id === author.id)) data.authors.push({ id: author.id, name: author.name })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (mediaMetadata.series && mediaMetadata.series.length) {
|
if (mediaMetadata.series?.length) {
|
||||||
mediaMetadata.series.forEach((series) => {
|
mediaMetadata.series.forEach((series) => {
|
||||||
if (series && !data.series.find(se => se.id === series.id)) data.series.push({ id: series.id, name: series.name })
|
if (series && !data.series.some(se => se.id === series.id)) data.series.push({ id: series.id, name: series.name })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (mediaMetadata.genres && mediaMetadata.genres.length) {
|
if (mediaMetadata.genres?.length) {
|
||||||
mediaMetadata.genres.forEach((genre) => {
|
mediaMetadata.genres.forEach((genre) => {
|
||||||
if (genre && !data.genres.includes(genre)) data.genres.push(genre)
|
if (genre && !data.genres.includes(genre)) data.genres.push(genre)
|
||||||
})
|
})
|
||||||
@ -153,18 +156,24 @@ module.exports = {
|
|||||||
if (tag && !data.tags.includes(tag)) data.tags.push(tag)
|
if (tag && !data.tags.includes(tag)) data.tags.push(tag)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (mediaMetadata.narrators && mediaMetadata.narrators.length) {
|
if (mediaMetadata.narrators?.length) {
|
||||||
mediaMetadata.narrators.forEach((narrator) => {
|
mediaMetadata.narrators.forEach((narrator) => {
|
||||||
if (narrator && !data.narrators.includes(narrator)) data.narrators.push(narrator)
|
if (narrator && !data.narrators.includes(narrator)) data.narrators.push(narrator)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (mediaMetadata.language && !data.languages.includes(mediaMetadata.language)) data.languages.push(mediaMetadata.language)
|
if (mediaMetadata.publisher && !data.publishers.includes(mediaMetadata.publisher)) {
|
||||||
|
data.publishers.push(mediaMetadata.publisher)
|
||||||
|
}
|
||||||
|
if (mediaMetadata.language && !data.languages.includes(mediaMetadata.language)) {
|
||||||
|
data.languages.push(mediaMetadata.language)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
data.authors = naturalSort(data.authors).asc(au => au.name)
|
data.authors = naturalSort(data.authors).asc(au => au.name)
|
||||||
data.genres = naturalSort(data.genres).asc()
|
data.genres = naturalSort(data.genres).asc()
|
||||||
data.tags = naturalSort(data.tags).asc()
|
data.tags = naturalSort(data.tags).asc()
|
||||||
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.languages = naturalSort(data.languages).asc()
|
data.languages = naturalSort(data.languages).asc()
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user