Skip to content

Commit

Permalink
fix(webui): contextual filters
Browse files Browse the repository at this point in the history
closes gotson#290
  • Loading branch information
gotson committed Aug 27, 2020
1 parent 57cc6c4 commit f515819
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
41 changes: 33 additions & 8 deletions komga-webui/src/services/komga-referential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ export default class KomgaReferentialService {
}
}

async getGenres (): Promise<string[]> {
async getGenres (libraryId?: string): Promise<string[]> {
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) {
Expand All @@ -41,9 +47,16 @@ export default class KomgaReferentialService {
}
}

async getTags (): Promise<string[]> {
async getTags (libraryId?: string, seriesId?: string): Promise<string[]> {
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) {
Expand All @@ -53,9 +66,15 @@ export default class KomgaReferentialService {
}
}

async getPublishers (): Promise<string[]> {
async getPublishers (libraryId?: string): Promise<string[]> {
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) {
Expand All @@ -65,9 +84,15 @@ export default class KomgaReferentialService {
}
}

async getLanguages (): Promise<NameValue[]> {
async getLanguages (libraryId?: string): Promise<NameValue[]> {
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)
Expand Down
15 changes: 10 additions & 5 deletions komga-webui/src/views/BrowseLibraries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 () {
Expand Down
6 changes: 4 additions & 2 deletions komga-webui/src/views/BrowseSeries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -360,6 +358,7 @@ export default Vue.extend({
this.totalElements = null
this.books = []
this.collections = []
this.filterOptionsPanel.tag.values = []
this.loadSeries(to.params.seriesId)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f515819

Please sign in to comment.