refactor(webui): simplify authorRoles

This commit is contained in:
Gauthier Roebroeck 2021-02-26 10:36:22 +08:00
parent 0381a40fcb
commit 70318fb617
5 changed files with 21 additions and 21 deletions

View file

@ -176,8 +176,8 @@
:key="i"
>
<v-col cols="12">
<span class="text-body-2">{{ $_.capitalize(role.plural) }}</span>
<v-combobox v-model="form.authors[role.role]"
<span class="text-body-2">{{ $_.capitalize(role.name) }}</span>
<v-combobox v-model="form.authors[role.value]"
:items="authorSearchResultsFull"
:search-input.sync="authorSearch[i]"
@keydown.esc="authorSearch[i] = null"
@ -364,11 +364,11 @@ export default Vue.extend({
this.tagsAvailable = await this.$komgaReferential.getTags()
},
computed: {
authorRoles(): object[] {
return authorRoles.map((x: any) => {
x.plural = this.$t(`author_roles.${x.role}`)
return x
})
authorRoles(): NameValue[] {
return authorRoles.map((x: string) => ({
name: this.$t(`author_roles.${x}`).toString(),
value: x,
}))
},
single(): boolean {
return !Array.isArray(this.books)

View file

@ -9,15 +9,15 @@ export function groupAuthorsByRole (authors: AuthorDto[]): any {
authors => authors.map((author: AuthorDto) => author.name))
}
// return an object where keys are roles (plural form), and values are string[]
export function groupAuthorsByRolePlural (authors: AuthorDto[]): any {
// return an object where keys are roles (i18n translated), and values are string[]
export function groupAuthorsByRoleI18n (authors: AuthorDto[]): any {
const r = mapKeys(groupAuthorsByRole(authors),
(v, k) => i18n.t(`author_roles.${k}`),
)
// sort object keys according to the order of keys in authorRoles
// push unknown keys to the end of the array
const roles = authorRoles.map(x => i18n.t(`author_roles.${x.role}`))
const roles = authorRoles.map(x => i18n.t(`author_roles.${x}`))
const o = {} as any
Object.keys(r)
.sort((a, b) => {

View file

@ -1,9 +1,9 @@
export const authorRoles = [
{ role: 'writer'},
{ role: 'penciller'},
{ role: 'inker'},
{ role: 'colorist'},
{ role: 'letterer'},
{ role: 'cover'},
{ role: 'editor'},
'writer',
'penciller',
'inker',
'colorist',
'letterer',
'cover',
'editor',
]

View file

@ -216,7 +216,7 @@
import BookActionsMenu from '@/components/menus/BookActionsMenu.vue'
import ItemCard from '@/components/ItemCard.vue'
import ToolbarSticky from '@/components/bars/ToolbarSticky.vue'
import {groupAuthorsByRolePlural} from '@/functions/authors'
import {groupAuthorsByRoleI18n} from '@/functions/authors'
import {getBookFormatFromMediaType} from '@/functions/book-format'
import {getReadProgress, getReadProgressPercentage} from '@/functions/book-progress'
import {getBookTitleCompact} from '@/functions/book-title'
@ -287,7 +287,7 @@ export default Vue.extend({
return getBookFormatFromMediaType(this.book.media.mediaType)
},
authorsByRole (): any {
return groupAuthorsByRolePlural(this.book.metadata.authors)
return groupAuthorsByRoleI18n(this.book.metadata.authors)
},
isRead (): boolean {
return getReadProgress(this.book) === ReadStatus.READ

View file

@ -291,7 +291,7 @@ import SortList from '@/components/SortList.vue'
import {mergeFilterParams, sortOrFilterActive, toNameValue} from '@/functions/filter'
import FilterPanels from '@/components/FilterPanels.vue'
import {SeriesDto} from "@/types/komga-series";
import {groupAuthorsByRolePlural} from "@/functions/authors";
import {groupAuthorsByRoleI18n} from "@/functions/authors";
import ReadMore from "@/components/ReadMore.vue";
const tags = require('language-tags')
@ -398,7 +398,7 @@ export default Vue.extend({
return sortOrFilterActive(this.sortActive, this.sortDefault, this.filters)
},
authorsByRole(): any {
return groupAuthorsByRolePlural(this.series.booksMetadata.authors)
return groupAuthorsByRoleI18n(this.series.booksMetadata.authors)
},
},
props: {