feat(webui): only shows filter values for pinned libraries

This commit is contained in:
Gauthier Roebroeck 2025-02-19 15:48:23 +08:00
parent 9bab9f620f
commit ef01550367
2 changed files with 29 additions and 25 deletions

View file

@ -1,5 +1,6 @@
import {AxiosInstance} from 'axios'
import {AuthorDto} from '@/types/komga-books'
import {NameValue} from '@/types/filter'
const qs = require('qs')
const tags = require('language-tags')
@ -11,12 +12,12 @@ export default class KomgaReferentialService {
this.http = http
}
async getAuthors(search?: string, role?: string, libraryId?: string, collectionId?: string, seriesId?: string, readListId?: string): Promise<Page<AuthorDto>> {
async getAuthors(search?: string, role?: string, libraryIds?: string[], collectionId?: string, seriesId?: string, readListId?: string): Promise<Page<AuthorDto>> {
try {
const params = {} as any
if (search) params.search = search
if (role) params.role = role
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
if (seriesId) params.series_id = seriesId
if (readListId) params.readlist_id = readListId
@ -53,10 +54,10 @@ export default class KomgaReferentialService {
}
}
async getGenres(libraryId?: string, collectionId?: string): Promise<string[]> {
async getGenres(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/genres', {
@ -84,10 +85,10 @@ export default class KomgaReferentialService {
}
}
async getSharingLabels(libraryId?: string, collectionId?: string): Promise<string[]> {
async getSharingLabels(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/sharing-labels', {
@ -103,10 +104,10 @@ export default class KomgaReferentialService {
}
}
async getSeriesAndBookTags(libraryId?: string, collectionId?: string): Promise<string[]> {
async getSeriesAndBookTags(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/tags', {
@ -141,10 +142,10 @@ export default class KomgaReferentialService {
}
}
async getPublishers(libraryId?: string, collectionId?: string): Promise<string[]> {
async getPublishers(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/publishers', {
@ -160,10 +161,10 @@ export default class KomgaReferentialService {
}
}
async getAgeRatings(libraryId?: string, collectionId?: string): Promise<string[]> {
async getAgeRatings(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/age-ratings', {
@ -179,10 +180,10 @@ export default class KomgaReferentialService {
}
}
async getSeriesReleaseDates(libraryId?: string, collectionId?: string): Promise<string[]> {
async getSeriesReleaseDates(libraryIds?: string[], collectionId?: string): Promise<string[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
return (await this.http.get('/api/v1/series/release-dates', {
@ -198,10 +199,10 @@ export default class KomgaReferentialService {
}
}
async getLanguages(libraryId?: string, collectionId?: string): Promise<NameValue[]> {
async getLanguages(libraryIds?: string[], collectionId?: string): Promise<NameValue[]> {
try {
const params = {} as any
if (libraryId) params.library_id = libraryId
if (libraryIds) params.library_id = libraryIds
if (collectionId) params.collection_id = collectionId
const data = (await this.http.get('/api/v1/languages', {

View file

@ -342,6 +342,9 @@ export default Vue.extend({
library(): LibraryDto | undefined {
return this.getLibraryLazy(this.libraryId)
},
requestLibraryIds(): string[] {
return this.libraryId !== LIBRARIES_ALL ? [this.libraryId] : this.$store.getters.getLibrariesPinned.map((it: LibraryDto) => it.id)
},
toolbarTitle(): string {
if (this.library) return this.library.name
else if (this.$store.getters.getLibrariesPinned.length > 0) return this.$t('common.pinned_libraries').toString()
@ -441,7 +444,7 @@ export default Vue.extend({
r[role] = {
name: this.$t(`author_roles.${role}`).toString(),
search: async search => {
return (await this.$komgaReferential.getAuthors(search, role, this.libraryId !== LIBRARIES_ALL ? this.libraryId : undefined))
return (await this.$komgaReferential.getAuthors(search, role, this.requestLibraryIds))
.content
.map(x => x.name)
},
@ -501,17 +504,17 @@ export default Vue.extend({
this.$store.getters.getLibrarySort(route.params.libraryId) ||
this.$_.clone(this.sortDefault)
const requestLibraryId = libraryId !== LIBRARIES_ALL ? libraryId : undefined
const requestLibraryIds = libraryId !== LIBRARIES_ALL ? [libraryId] : this.$store.getters.getLibrariesPinned.map((it: LibraryDto) => it.id)
// load dynamic filters
const [genres, tags, publishers, languages, ageRatings, releaseDates, sharingLabels] = await Promise.all([
this.$komgaReferential.getGenres(requestLibraryId),
this.$komgaReferential.getSeriesAndBookTags(requestLibraryId),
this.$komgaReferential.getPublishers(requestLibraryId),
this.$komgaReferential.getLanguages(requestLibraryId),
this.$komgaReferential.getAgeRatings(requestLibraryId),
this.$komgaReferential.getSeriesReleaseDates(requestLibraryId),
this.$komgaReferential.getSharingLabels(requestLibraryId),
this.$komgaReferential.getGenres(requestLibraryIds),
this.$komgaReferential.getSeriesAndBookTags(requestLibraryIds),
this.$komgaReferential.getPublishers(requestLibraryIds),
this.$komgaReferential.getLanguages(requestLibraryIds),
this.$komgaReferential.getAgeRatings(requestLibraryIds),
this.$komgaReferential.getSeriesReleaseDates(requestLibraryIds),
this.$komgaReferential.getSharingLabels(requestLibraryIds),
])
this.$set(this.filterOptions, 'genre', toNameValueCondition(genres, x => new SearchConditionGenre(new SearchOperatorIs(x)), x => new SearchConditionGenre(new SearchOperatorIsNot(x))))
this.$set(this.filterOptions, 'tag', toNameValueCondition(tags, x => new SearchConditionTag(new SearchOperatorIs(x)), x => new SearchConditionTag(new SearchOperatorIsNot(x))))