From 01eef838a20ee01b179bf3ad5dcd03b94f0e7a8b Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 28 Aug 2020 10:19:19 +0800 Subject: [PATCH] feat(webui): filter series by age rating --- .../src/services/komga-referential.service.ts | 18 ++++++++++++++++++ .../src/services/komga-series.service.ts | 5 ++++- komga-webui/src/views/BrowseLibraries.vue | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/komga-webui/src/services/komga-referential.service.ts b/komga-webui/src/services/komga-referential.service.ts index d7711fc94..fc4cc88b4 100644 --- a/komga-webui/src/services/komga-referential.service.ts +++ b/komga-webui/src/services/komga-referential.service.ts @@ -84,6 +84,24 @@ export default class KomgaReferentialService { } } + async getAgeRatings (libraryId?: string): Promise { + try { + const params = {} as any + if (libraryId) params.library_id = libraryId + + return (await this.http.get('/api/v1/age-ratings', { + params: params, + paramsSerializer: params => qs.stringify(params, { indices: false }), + })).data + } catch (e) { + let msg = 'An error occurred while trying to retrieve age ratings' + if (e.response.data.message) { + msg += `: ${e.response.data.message}` + } + throw new Error(msg) + } + } + async getLanguages (libraryId?: string): Promise { try { const params = {} as any diff --git a/komga-webui/src/services/komga-series.service.ts b/komga-webui/src/services/komga-series.service.ts index b649f270b..eb72a724d 100644 --- a/komga-webui/src/services/komga-series.service.ts +++ b/komga-webui/src/services/komga-series.service.ts @@ -11,7 +11,9 @@ export default class KomgaSeriesService { this.http = http } - async getSeries (libraryId?: string, pageRequest?: PageRequest, search?: string, status?: string[], readStatus?: string[], genre?: string[], tag?: string[], language?: string[], publisher?: string[]): Promise> { + async getSeries (libraryId?: string, pageRequest?: PageRequest, search?: string, status?: string[], + readStatus?: string[], genre?: string[], tag?: string[], language?: string[], + publisher?: string[], ageRating?: string[]): Promise> { try { const params = { ...pageRequest } as any if (libraryId) params.library_id = libraryId @@ -22,6 +24,7 @@ export default class KomgaSeriesService { if (tag) params.tag = tag if (language) params.language = language if (publisher) params.publisher = publisher + if (ageRating) params.age_rating = ageRating return (await this.http.get(API_SERIES, { params: params, diff --git a/komga-webui/src/views/BrowseLibraries.vue b/komga-webui/src/views/BrowseLibraries.vue index 079d890fc..5c879c58e 100644 --- a/komga-webui/src/views/BrowseLibraries.vue +++ b/komga-webui/src/views/BrowseLibraries.vue @@ -148,6 +148,7 @@ export default Vue.extend({ tag: { name: 'TAG', values: [] }, publisher: { name: 'PUBLISHER', values: [] }, language: { name: 'LANGUAGE', values: [] }, + ageRating: { name: 'AGE RATING', values: [] }, } as FiltersOptions, filters: {} as FiltersActive, sortUnwatch: null as any, @@ -211,6 +212,7 @@ export default Vue.extend({ this.filterOptionsPanel.tag.values = [] this.filterOptionsPanel.publisher.values = [] this.filterOptionsPanel.language.values = [] + this.filterOptionsPanel.ageRating.values = [] this.loadLibrary(to.params.libraryId) @@ -322,6 +324,7 @@ export default Vue.extend({ 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))) + this.filterOptionsPanel.ageRating.values.push(...toNameValue(await this.$komgaReferential.getAgeRatings(requestLibraryId))) await this.loadPage(libraryId, this.page, this.sortActive) }, @@ -350,7 +353,7 @@ export default Vue.extend({ } const requestLibraryId = libraryId !== LIBRARIES_ALL ? libraryId : undefined - const seriesPage = await this.$komgaSeries.getSeries(requestLibraryId, pageRequest, undefined, this.filters.status, this.filters.readStatus, this.filters.genre, this.filters.tag, this.filters.language, this.filters.publisher) + const seriesPage = await this.$komgaSeries.getSeries(requestLibraryId, pageRequest, undefined, this.filters.status, this.filters.readStatus, this.filters.genre, this.filters.tag, this.filters.language, this.filters.publisher, this.filters.ageRating) this.totalPages = seriesPage.totalPages this.totalElements = seriesPage.totalElements