diff --git a/frontend/components/label/FormCreate.vue b/frontend/components/label/FormCreate.vue index fb040c38..69f216d0 100644 --- a/frontend/components/label/FormCreate.vue +++ b/frontend/components/label/FormCreate.vue @@ -1,108 +1,204 @@ diff --git a/frontend/pages/projects/_id/labels/add.vue b/frontend/pages/projects/_id/labels/add.vue new file mode 100644 index 00000000..94545a7b --- /dev/null +++ b/frontend/pages/projects/_id/labels/add.vue @@ -0,0 +1,105 @@ + + + diff --git a/frontend/pages/projects/_id/labels/index.vue b/frontend/pages/projects/_id/labels/index.vue index 4d771308..3db16231 100644 --- a/frontend/pages/projects/_id/labels/index.vue +++ b/frontend/pages/projects/_id/labels/index.vue @@ -6,7 +6,7 @@ @@ -18,15 +18,6 @@ > {{ $t('generic.delete') }} - - - import Vue from 'vue' import ActionMenu from '@/components/label/ActionMenu.vue' -import FormCreate from '@/components/label/FormCreate.vue' import FormDelete from '@/components/label/FormDelete.vue' import FormUpload from '@/components/label/FormUpload.vue' import LabelList from '@/components/label/LabelList.vue' @@ -66,7 +56,6 @@ export default Vue.extend({ components: { ActionMenu, - FormCreate, FormDelete, FormUpload, LabelList @@ -85,24 +74,8 @@ export default Vue.extend({ data() { return { - dialogCreate: false, dialogDelete: false, dialogUpload: false, - editedIndex: -1, - editedItem: { - text: '', - prefixKey: null, - suffixKey: null, - backgroundColor: '#2196F3', - textColor: '#ffffff' - } as LabelDTO, - defaultItem: { - text: '', - prefixKey: null, - suffixKey: null, - backgroundColor: '#2196F3', - textColor: '#ffffff' - } as LabelDTO, items: [] as LabelDTO[], selected: [] as LabelDTO[], isLoading: false, @@ -116,18 +89,11 @@ export default Vue.extend({ canDelete(): boolean { return this.selected.length > 0 }, + projectId(): string { return this.$route.params.id }, - usedNames(): string[] { - const item = this.items[this.editedIndex] // to remove myself - return this.items.filter(_ => _ !== item).map(item => item.text) - }, - usedKeys(): string[] { - const item = this.items[this.editedIndex] // to remove myself - return this.items.filter(_ => _ !== item).map(item => item.suffixKey) - .filter(item => item !==null) as string[] - }, + hasMultiType(): boolean { if ('projectType' in this.project) { return this.project.projectType === 'IntentDetectionAndSlotFilling' @@ -136,6 +102,20 @@ export default Vue.extend({ } }, + labelType(): string { + if (this.hasMultiType) { + if (this.tab === 0) { + return 'category' + } else { + return 'span' + } + } else if (this.project.projectType.endsWith('Classification')) { + return 'category' + } else { + return 'span' + } + }, + service(): any { if (!('projectType' in this.project)) { return @@ -171,25 +151,7 @@ export default Vue.extend({ this.items = await this.service.list(this.projectId) this.isLoading = false }, - - async save() { - if (this.editedIndex > -1) { - await this.service.update(this.projectId, this.editedItem) - } else { - await this.service.create(this.projectId, this.editedItem) - } - await this.list() - this.close() - }, - - close() { - this.dialogCreate = false - this.$nextTick(() => { - this.editedItem = Object.assign({}, this.defaultItem) - this.editedIndex = -1 - }) - }, - + async remove() { await this.service.bulkDelete(this.projectId, this.selected) this.list() @@ -221,9 +183,7 @@ export default Vue.extend({ }, editItem(item: LabelDTO) { - this.editedIndex = this.items.indexOf(item) - this.editedItem = Object.assign({}, item) - this.dialogCreate = true + this.$router.push(`labels/${item.id}/edit?type=${this.labelType}`) } } }) diff --git a/frontend/repositories/label/apiLabelRepository.ts b/frontend/repositories/label/apiLabelRepository.ts index 47bd015d..ff35e982 100644 --- a/frontend/repositories/label/apiLabelRepository.ts +++ b/frontend/repositories/label/apiLabelRepository.ts @@ -24,6 +24,12 @@ export class APILabelRepository implements LabelRepository { return response.data.map((item: any) => plainToInstance(LabelItem, item)) } + async findById(projectId: string, labelId: number): Promise { + const url = `/projects/${projectId}/${this.baseUrl}s/${labelId}` + const response = await this.request.get(url) + return plainToInstance(LabelItem, response.data) + } + async create(projectId: string, item: LabelItem): Promise { const url = `/projects/${projectId}/${this.baseUrl}s` const response = await this.request.post(url, item.toObject()) diff --git a/frontend/services/application/label/labelApplicationService.ts b/frontend/services/application/label/labelApplicationService.ts index 31a1e263..15e0c498 100644 --- a/frontend/services/application/label/labelApplicationService.ts +++ b/frontend/services/application/label/labelApplicationService.ts @@ -14,6 +14,11 @@ export class LabelApplicationService { return items.map(item => new LabelDTO(item)) } + public async findById(projectId: string, labelId: number): Promise { + const item = await this.repository.findById(projectId, labelId) + return new LabelDTO(item) + } + public async create(projectId: string, item: CreateLabelCommand): Promise { // Todo: use auto mapping. const label = new LabelItem()