Browse Source

Merge pull request #1664 from doccano/fix/#1648

Fix #1648
pull/1665/head
Hiroki Nakayama 2 years ago
committed by GitHub
parent
commit
61a2a7528e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 26 deletions
  1. 2
      frontend/domain/models/label/label.ts
  2. 24
      frontend/pages/projects/_id/labels/index.vue
  3. 10
      frontend/services/application/label/labelApplicationService.ts

2
frontend/domain/models/label/label.ts

@ -7,7 +7,7 @@ export class LabelItem {
@Expose({ name: 'prefix_key' }) @Expose({ name: 'prefix_key' })
prefixKey: string | null; prefixKey: string | null;
@Expose({ name: 'suffixKey' })
@Expose({ name: 'suffix_key' })
suffixKey: string | null; suffixKey: string | null;
@Expose({ name: 'background_color' }) @Expose({ name: 'background_color' })

24
frontend/pages/projects/_id/labels/index.vue

@ -112,15 +112,6 @@ export default Vue.extend({
} }
}, },
// async fetch() {
// this.items = []
// this.isLoading = true
// console.log('start fetch')
// this.items = await this.service.list(this.projectId)
// console.log('end fetch')
// this.isLoading = false
// },
computed: { computed: {
canDelete(): boolean { canDelete(): boolean {
return this.selected.length > 0 return this.selected.length > 0
@ -171,30 +162,21 @@ export default Vue.extend({
async created() { async created() {
this.project = await this.$services.project.findById(this.projectId) this.project = await this.$services.project.findById(this.projectId)
this.list()
await this.list()
}, },
methods: { methods: {
async list() { async list() {
this.items = []
this.isLoading = true this.isLoading = true
this.items = await this.service.list(this.projectId) this.items = await this.service.list(this.projectId)
this.isLoading = false this.isLoading = false
}, },
async create() {
await this.service.create(this.projectId, this.editedItem)
},
async update() {
await this.service.update(this.projectId, this.editedItem)
},
async save() { async save() {
if (this.editedIndex > -1) { if (this.editedIndex > -1) {
await this.update()
await this.service.update(this.projectId, this.editedItem)
} else { } else {
await this.create()
await this.service.create(this.projectId, this.editedItem)
} }
await this.list() await this.list()
this.close() this.close()

10
frontend/services/application/label/labelApplicationService.ts

@ -14,7 +14,7 @@ export class LabelApplicationService {
return items.map(item => new LabelDTO(item)) return items.map(item => new LabelDTO(item))
} }
public create(projectId: string, item: CreateLabelCommand): void {
public async create(projectId: string, item: CreateLabelCommand): Promise<LabelDTO> {
// Todo: use auto mapping. // Todo: use auto mapping.
const label = new LabelItem() const label = new LabelItem()
label.text = item.text label.text = item.text
@ -22,10 +22,11 @@ export class LabelApplicationService {
label.suffixKey = item.suffixKey label.suffixKey = item.suffixKey
label.backgroundColor = item.backgroundColor label.backgroundColor = item.backgroundColor
label.textColor = item.textColor label.textColor = item.textColor
this.repository.create(projectId, label)
const created = await this.repository.create(projectId, label)
return new LabelDTO(created)
} }
public update(projectId: string, item: LabelDTO): void {
public async update(projectId: string, item: LabelDTO): Promise<LabelDTO> {
// Todo: use auto mapping. // Todo: use auto mapping.
const label = new LabelItem() const label = new LabelItem()
label.id = item.id label.id = item.id
@ -34,7 +35,8 @@ export class LabelApplicationService {
label.suffixKey = item.suffixKey label.suffixKey = item.suffixKey
label.backgroundColor = item.backgroundColor label.backgroundColor = item.backgroundColor
label.textColor = item.textColor label.textColor = item.textColor
this.repository.update(projectId, label)
const updated = await this.repository.update(projectId, label)
return new LabelDTO(updated)
} }
public bulkDelete(projectId: string, items: LabelDTO[]): Promise<void> { public bulkDelete(projectId: string, items: LabelDTO[]): Promise<void> {

Loading…
Cancel
Save