From f5158197ded703d57c3c0fb7eb6c31dae1629d03 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Thu, 27 Aug 2020 17:35:33 +0800 Subject: [PATCH] fix(webui): contextual filters closes #290 --- .../src/services/komga-referential.service.ts | 41 +++++++++++++++---- komga-webui/src/views/BrowseLibraries.vue | 15 ++++--- komga-webui/src/views/BrowseSeries.vue | 6 ++- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/komga-webui/src/services/komga-referential.service.ts b/komga-webui/src/services/komga-referential.service.ts index 2cf6479852..d7711fc948 100644 --- a/komga-webui/src/services/komga-referential.service.ts +++ b/komga-webui/src/services/komga-referential.service.ts @@ -29,9 +29,15 @@ export default class KomgaReferentialService { } } - async getGenres (): Promise { + async getGenres (libraryId?: string): Promise { try { - return (await this.http.get('/api/v1/genres')).data + const params = {} as any + if (libraryId) params.library_id = libraryId + + return (await this.http.get('/api/v1/genres', { + params: params, + paramsSerializer: params => qs.stringify(params, { indices: false }), + })).data } catch (e) { let msg = 'An error occurred while trying to retrieve genres' if (e.response.data.message) { @@ -41,9 +47,16 @@ export default class KomgaReferentialService { } } - async getTags (): Promise { + async getTags (libraryId?: string, seriesId?: string): Promise { try { - return (await this.http.get('/api/v1/tags')).data + const params = {} as any + if (libraryId) params.library_id = libraryId + if (seriesId) params.series_id = seriesId + + return (await this.http.get('/api/v1/tags', { + params: params, + paramsSerializer: params => qs.stringify(params, { indices: false }), + })).data } catch (e) { let msg = 'An error occurred while trying to retrieve tags' if (e.response.data.message) { @@ -53,9 +66,15 @@ export default class KomgaReferentialService { } } - async getPublishers (): Promise { + async getPublishers (libraryId?: string): Promise { try { - return (await this.http.get('/api/v1/publishers')).data + const params = {} as any + if (libraryId) params.library_id = libraryId + + return (await this.http.get('/api/v1/publishers', { + params: params, + paramsSerializer: params => qs.stringify(params, { indices: false }), + })).data } catch (e) { let msg = 'An error occurred while trying to retrieve publishers' if (e.response.data.message) { @@ -65,9 +84,15 @@ export default class KomgaReferentialService { } } - async getLanguages (): Promise { + async getLanguages (libraryId?: string): Promise { try { - const data = (await this.http.get('/api/v1/languages')).data + const params = {} as any + if (libraryId) params.library_id = libraryId + + const data = (await this.http.get('/api/v1/languages', { + params: params, + paramsSerializer: params => qs.stringify(params, { indices: false }), + })).data const ret = [] as NameValue[] for (const code of data) { const tag = tags(code) diff --git a/komga-webui/src/views/BrowseLibraries.vue b/komga-webui/src/views/BrowseLibraries.vue index 5b8b49da79..079d890fca 100644 --- a/komga-webui/src/views/BrowseLibraries.vue +++ b/komga-webui/src/views/BrowseLibraries.vue @@ -188,11 +188,6 @@ export default Vue.extend({ this.pageSize = Number(this.$cookies.get(cookiePageSize)) } - this.filterOptionsPanel.genre.values.push(...toNameValue(await this.$komgaReferential.getGenres())) - this.filterOptionsPanel.tag.values.push(...toNameValue(await this.$komgaReferential.getTags())) - this.filterOptionsPanel.publisher.values.push(...toNameValue(await this.$komgaReferential.getPublishers())) - this.filterOptionsPanel.language.values.push(...(await this.$komgaReferential.getLanguages())) - // restore from query param this.resetParams(this.$route) if (this.$route.query.page) this.page = Number(this.$route.query.page) @@ -212,6 +207,10 @@ export default Vue.extend({ this.totalPages = 1 this.totalElements = null this.series = [] + this.filterOptionsPanel.genre.values = [] + this.filterOptionsPanel.tag.values = [] + this.filterOptionsPanel.publisher.values = [] + this.filterOptionsPanel.language.values = [] this.loadLibrary(to.params.libraryId) @@ -318,6 +317,12 @@ export default Vue.extend({ async loadLibrary (libraryId: string) { this.library = this.getLibraryLazy(libraryId) + const requestLibraryId = libraryId !== LIBRARIES_ALL ? libraryId : undefined + this.filterOptionsPanel.genre.values.push(...toNameValue(await this.$komgaReferential.getGenres(requestLibraryId))) + this.filterOptionsPanel.tag.values.push(...toNameValue(await this.$komgaReferential.getTags(requestLibraryId))) + this.filterOptionsPanel.publisher.values.push(...toNameValue(await this.$komgaReferential.getPublishers(requestLibraryId))) + this.filterOptionsPanel.language.values.push(...(await this.$komgaReferential.getLanguages(requestLibraryId))) + await this.loadPage(libraryId, this.page, this.sortActive) }, updateRoute () { diff --git a/komga-webui/src/views/BrowseSeries.vue b/komga-webui/src/views/BrowseSeries.vue index 04909c0afb..27c3e8fc50 100644 --- a/komga-webui/src/views/BrowseSeries.vue +++ b/komga-webui/src/views/BrowseSeries.vue @@ -333,8 +333,6 @@ export default Vue.extend({ this.pageSize = Number(this.$cookies.get(cookiePageSize)) } - this.filterOptionsPanel.tag.values.push(...toNameValue(await this.$komgaReferential.getTags())) - // restore from query param this.sortActive = this.parseQuerySortOrDefault(this.$route.query.sort) @@ -360,6 +358,7 @@ export default Vue.extend({ this.totalElements = null this.books = [] this.collections = [] + this.filterOptionsPanel.tag.values = [] this.loadSeries(to.params.seriesId) @@ -413,6 +412,9 @@ export default Vue.extend({ async loadSeries (seriesId: string) { this.series = await this.$komgaSeries.getOneSeries(seriesId) this.collections = await this.$komgaSeries.getCollections(seriesId) + + this.filterOptionsPanel.tag.values.push(...toNameValue(await this.$komgaReferential.getTags(undefined, this.seriesId))) + await this.loadPage(seriesId, this.page, this.sortActive) }, parseQuerySortOrDefault (querySort: any): SortActive {