diff --git a/frontend/components/containers/settings/ConfigCreationForm.vue b/frontend/components/containers/settings/ConfigCreationForm.vue index dcc1aa6e..0bf34f10 100644 --- a/frontend/components/containers/settings/ConfigCreationForm.vue +++ b/frontend/components/containers/settings/ConfigCreationForm.vue @@ -26,7 +26,7 @@ - +

Select a config template

@@ -62,6 +62,7 @@ :key="item.name" /> +

Set mapping template

You can set mapping template to convert API response to doccano format. @@ -71,10 +72,12 @@ outlined label="Mapping Template" /> +

Configure label mappings

Once you fetch the API response, you can convert the label into the defined one.

+
@@ -90,7 +93,7 @@ />
- + + Test + + Save @@ -125,11 +136,19 @@ \ No newline at end of file + diff --git a/frontend/components/containers/settings/ConfigList.vue b/frontend/components/containers/settings/ConfigList.vue index 167fe1e3..d21e74ea 100644 --- a/frontend/components/containers/settings/ConfigList.vue +++ b/frontend/components/containers/settings/ConfigList.vue @@ -21,7 +21,9 @@ @@ -41,7 +43,7 @@ title="Delete Config" message="Are you sure you want to delete these configs?" item-key="modelName" - @ok="remove();modal.close" + @ok="remove();modal.close()" @cancel="modal.close" /> @@ -98,10 +100,16 @@ export default Vue.extend({ await this.configService.delete(projectId, item.id) } this.items = await this.configService.list(projectId) + this.selected = [] this.isLoading = false }, isDeletable(): boolean { return this.selected.length > 0 + }, + async onCreate() { + this.isLoading = true + this.items = await this.configService.list(this.$route.params.id) + this.isLoading = false } } }) diff --git a/frontend/models/config/config-item-list.ts b/frontend/models/config/config-item-list.ts index 1ad32d7a..9e2cdaf9 100644 --- a/frontend/models/config/config-item-list.ts +++ b/frontend/models/config/config-item-list.ts @@ -26,7 +26,21 @@ export class ConfigItem { return new ConfigItem(id, model_name, model_attrs, template, label_mapping) } - toObject(): Object { + static parseFromUI( + { modelName, modelAttrs, template, labelMapping }: + { + modelName: string, + modelAttrs: {'name': string, 'value': string}[], + template: string, + labelMapping: {'from': string, 'to': string}[] + } + ): ConfigItem { + const mapping = labelMapping.reduce((a, x) => ({...a, [x.from]: x.to}), {}) + const attributes = modelAttrs.reduce((a, x) => ({...a, [x.name]: x.value}), {}) + return new ConfigItem(99999, modelName, attributes, template, mapping) + } + + toObject(): object { return { id: this.id, modelName: this.modelName, @@ -35,6 +49,16 @@ export class ConfigItem { labelMapping: this.labelMapping } } + + toAPI(): object { + return { + id: this.id, + model_name: this.modelName, + model_attrs: this.modelAttrs, + template: this.template, + label_mapping: this.labelMapping + } + } } export const headers = [ diff --git a/frontend/models/config/config-template.ts b/frontend/models/config/config-template.ts index 3b75d2d0..1f18fa5b 100644 --- a/frontend/models/config/config-template.ts +++ b/frontend/models/config/config-template.ts @@ -56,3 +56,23 @@ export class ConfigTemplateItem { } } } + +export const headers = [ + { + text: 'From', + align: 'left', + value: 'from', + sortable: false + }, + { + text: 'To', + align: 'left', + value: 'to', + sortable: false + }, + { + text: 'Actions', + value: 'actions', + sortable: false + } +] diff --git a/frontend/repositories/config/api.ts b/frontend/repositories/config/api.ts index 9196cee0..aec93e0e 100644 --- a/frontend/repositories/config/api.ts +++ b/frontend/repositories/config/api.ts @@ -1,5 +1,5 @@ import ApiService from '@/services/api.service' -import { ConfigItemListRepository } from '@/repositories/config/interface' +import { ConfigItemListRepository, ConfigTestResponse } from '@/repositories/config/interface' import { ConfigItemList, ConfigItem } from '@/models/config/config-item-list' export interface ConfigItemResponse { @@ -53,4 +53,11 @@ export class FromApiConfigItemListRepository implements ConfigItemListRepository const url = `/projects/${projectId}/auto-labeling-configs/${itemId}` await this.request.delete(url) } + + async testConfig(projectId: string, item: ConfigItem, text: string): Promise { + const url = `/projects/${projectId}/auto-labeling-config-testing` + const response = await this.request.post(url, {config: {...item.toAPI()}, input: text}) + const responseItem: ConfigTestResponse = response.data + return responseItem + } } diff --git a/frontend/repositories/config/interface.ts b/frontend/repositories/config/interface.ts index 1eb8923c..30ace1d4 100644 --- a/frontend/repositories/config/interface.ts +++ b/frontend/repositories/config/interface.ts @@ -1,5 +1,10 @@ import { ConfigItem, ConfigItemList } from '@/models/config/config-item-list' +export interface ConfigTestResponse { + valid: boolean, + labels?: object[] +} + export interface ConfigItemListRepository { list(projectId: string): Promise @@ -8,4 +13,6 @@ export interface ConfigItemListRepository { delete(projectId: string, itemId: number): Promise update(projectId: string, item: ConfigItem): Promise + + testConfig(projectId: string, item: ConfigItem, text: string): Promise } diff --git a/frontend/services/application/config.service.ts b/frontend/services/application/config.service.ts index 4fc86293..88b08492 100644 --- a/frontend/services/application/config.service.ts +++ b/frontend/services/application/config.service.ts @@ -1,5 +1,5 @@ -import { ConfigItemList } from '@/models/config/config-item-list' -import { ConfigItemListRepository } from '@/repositories/config/interface' +import { ConfigItemList, ConfigItem } from '@/models/config/config-item-list' +import { ConfigItemListRepository, ConfigTestResponse } from '@/repositories/config/interface' export class ConfigApplicationService { constructor( @@ -10,7 +10,15 @@ export class ConfigApplicationService { return this.configRepository.list(id) } + public save(projectId: string, item: ConfigItem): Promise { + return this.configRepository.create(projectId, item) + } + public delete(projectId: string, itemId: number) { return this.configRepository.delete(projectId, itemId) } + + public testConfig(projectId: string, item: ConfigItem, text: string): Promise { + return this.configRepository.testConfig(projectId, item, text) + } }