Browse Source

Merge pull request #2140 from doccano/enhancement/frontend-role

Remove role application service
pull/2142/head
Hiroki Nakayama 1 year ago
committed by GitHub
parent
commit
aeb0f9aa3d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 46 deletions
  1. 22
      frontend/components/member/FormCreate.vue
  2. 5
      frontend/domain/models/role/roleRepository.ts
  3. 3
      frontend/plugins/services.ts
  4. 5
      frontend/repositories/role/apiRoleRepository.ts
  5. 4
      frontend/services/application/member/memberData.ts
  6. 11
      frontend/services/application/role/roleApplicationService.ts
  7. 11
      frontend/services/application/role/roleData.ts

22
frontend/components/member/FormCreate.vue

@ -25,7 +25,7 @@
<v-select
v-model="role"
:items="roles"
item-text="rolename"
item-text="name"
item-value="id"
:label="$t('members.role')"
:rules="[rules.roleRequired]"
@ -33,10 +33,10 @@
:prepend-icon="mdiCreditCardOutline"
>
<template #item="props">
{{ $translateRole(props.item.rolename, $t('members.roles')) }}
{{ $translateRole(props.item.name, $t('members.roles')) }}
</template>
<template #selection="props">
{{ $translateRole(props.item.rolename, $t('members.roles')) }}
{{ $translateRole(props.item.name, $t('members.roles')) }}
</template>
</v-select>
<v-alert v-show="errorMessage" prominent type="error">
@ -56,9 +56,9 @@ import { mdiAccount, mdiCreditCardOutline } from '@mdi/js'
import type { PropType } from 'vue'
import Vue from 'vue'
import BaseCard from '@/components/utils/BaseCard.vue'
import { RoleItem } from '~/domain/models/role/role'
import { UserItem } from '~/domain/models/user/user'
import { MemberDTO } from '~/services/application/member/memberData'
import { RoleDTO } from '~/services/application/role/roleData'
export default Vue.extend({
components: {
@ -81,11 +81,11 @@ export default Vue.extend({
isLoading: false,
valid: false,
users: [] as UserItem[],
roles: [] as RoleDTO[],
roles: [] as RoleItem[],
username: '',
rules: {
userRequired: (v: UserItem) => (!!v && !!v.username) || 'Required',
roleRequired: (v: RoleDTO) => (!!v && !!v.rolename) || 'Required'
roleRequired: (v: RoleItem) => (!!v && !!v.name) || 'Required'
},
mdiAccount,
mdiCreditCardOutline
@ -115,14 +115,14 @@ export default Vue.extend({
}
},
role: {
get(): RoleDTO {
get(): RoleItem {
return {
id: this.value.role,
rolename: this.value.rolename
name: this.value.rolename
}
},
set(val: MemberDTO) {
const role = { role: val.id, rolename: val.rolename }
set(val: RoleItem) {
const role = { role: val.id, rolename: val.name }
this.$emit('input', { ...this.value, ...role })
}
}
@ -141,7 +141,7 @@ export default Vue.extend({
},
async created() {
this.roles = await this.$services.role.list()
this.roles = await this.$repositories.role.list()
}
})
</script>

5
frontend/domain/models/role/roleRepository.ts

@ -1,5 +0,0 @@
import { RoleItem } from '~/domain/models/role/role'
export interface RoleRepository {
list(): Promise<RoleItem[]>
}

3
frontend/plugins/services.ts

@ -12,7 +12,6 @@ import { MemberApplicationService } from '@/services/application/member/memberAp
import { MetricsApplicationService } from '@/services/application/metrics/metricsApplicationService'
import { OptionApplicationService } from '@/services/application/option/optionApplicationService'
import { ProjectApplicationService } from '@/services/application/project/projectApplicationService'
import { RoleApplicationService } from '@/services/application/role/roleApplicationService'
import { TagApplicationService } from '@/services/application/tag/tagApplicationService'
import { BoundingBoxApplicationService } from '@/services/application/tasks/boundingBox/boundingBoxApplicationService'
import { SegmentationApplicationService } from '@/services/application/tasks/segmentation/segmentationApplicationService'
@ -27,7 +26,6 @@ export interface Services {
spanType: LabelApplicationService
relationType: LabelApplicationService
member: MemberApplicationService
role: RoleApplicationService
project: ProjectApplicationService
comment: CommentApplicationService
metrics: MetricsApplicationService
@ -60,7 +58,6 @@ const plugin: Plugin = (_, inject) => {
spanType: new LabelApplicationService(repositories.spanType),
relationType: new LabelApplicationService(repositories.relationType),
member: new MemberApplicationService(repositories.member),
role: new RoleApplicationService(repositories.role),
project: new ProjectApplicationService(repositories.project),
comment: new CommentApplicationService(repositories.comment),
metrics: new MetricsApplicationService(repositories.metrics),

5
frontend/repositories/role/apiRoleRepository.ts

@ -1,12 +1,11 @@
import ApiService from '@/services/api.service'
import { RoleRepository } from '@/domain/models/role/roleRepository'
import { RoleItem } from '@/domain/models/role/role'
import ApiService from '@/services/api.service'
function toModel(item: { [key: string]: any }): RoleItem {
return new RoleItem(item.id, item.name)
}
export class APIRoleRepository implements RoleRepository {
export class APIRoleRepository {
constructor(private readonly request = ApiService) {}
async list(): Promise<RoleItem[]> {

4
frontend/services/application/member/memberData.ts

@ -1,11 +1,11 @@
import { MemberItem } from '~/domain/models/member/member'
import { RoleName } from '~/domain/models/role/role'
export class MemberDTO {
id: number
user: number
role: number
username: string
rolename: string
rolename: RoleName
constructor(item: MemberItem) {
this.id = item.id

11
frontend/services/application/role/roleApplicationService.ts

@ -1,11 +0,0 @@
import { RoleDTO } from './roleData'
import { RoleRepository } from '~/domain/models/role/roleRepository'
export class RoleApplicationService {
constructor(private readonly repository: RoleRepository) {}
public async list(): Promise<RoleDTO[]> {
const items = await this.repository.list()
return items.map((item) => new RoleDTO(item))
}
}

11
frontend/services/application/role/roleData.ts

@ -1,11 +0,0 @@
import { RoleItem } from '~/domain/models/role/role'
export class RoleDTO {
id: number
rolename: string
constructor(item: RoleItem) {
this.id = item.id
this.rolename = item.name
}
}
Loading…
Cancel
Save