diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 53c479e6..5f8b3c44 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -7,7 +7,8 @@ module.exports = { extends: [ '@nuxtjs', 'plugin:nuxt/recommended', - '@nuxtjs/eslint-config-typescript' + '@nuxtjs/eslint-config-typescript', + 'prettier/@typescript-eslint' ], rules: { 'no-console': 'off', diff --git a/frontend/components/containers/settings/ConfigList.vue b/frontend/components/containers/settings/ConfigList.vue index 17053271..8aecb362 100644 --- a/frontend/components/containers/settings/ConfigList.vue +++ b/frontend/components/containers/settings/ConfigList.vue @@ -3,38 +3,23 @@ v-model="selected" :headers="headers" :items="items.toArray()" - :loading="loading" + :loading="isLoading" :no-data-text="$t('vuetify.noDataAvailable')" item-key="id" :loading-text="$t('generic.loading')" show-select > - - @@ -42,29 +27,51 @@ diff --git a/frontend/models/config/config-item-list.ts b/frontend/models/config/config-item-list.ts new file mode 100644 index 00000000..1ad32d7a --- /dev/null +++ b/frontend/models/config/config-item-list.ts @@ -0,0 +1,47 @@ +export class ConfigItemList { + constructor(public configItems: ConfigItem[]) {} + + static valueOf(items: ConfigItem[]): ConfigItemList { + return new ConfigItemList(items) + } + + toArray(): Object[] { + return this.configItems.map(item => item.toObject()) + } +} + +export class ConfigItem { + constructor( + public id: number, + public modelName: string, + public modelAttrs: object, + public template: string, + public labelMapping: object + ) {} + + static valueOf( + { id, model_name, model_attrs, template, label_mapping }: + { id: number, model_name: string, model_attrs: object, template: string, label_mapping: object } + ): ConfigItem { + return new ConfigItem(id, model_name, model_attrs, template, label_mapping) + } + + toObject(): Object { + return { + id: this.id, + modelName: this.modelName, + modelAttrs: this.modelAttrs, + template: this.template, + labelMapping: this.labelMapping + } + } +} + +export const headers = [ + { + text: 'Model name', + align: 'left', + value: 'modelName', + sortable: false + } +] diff --git a/frontend/repositories/config/api.ts b/frontend/repositories/config/api.ts new file mode 100644 index 00000000..070975ad --- /dev/null +++ b/frontend/repositories/config/api.ts @@ -0,0 +1,56 @@ +import ApiService from '@/services/api.service' +import { ConfigItemListRepository } from '@/repositories/config/interface' +import { ConfigItemList, ConfigItem } from '@/models/config/config-item-list' + +interface ConfigItemResponse { + id: number, + model_name: string, + model_attrs: object, + template: string, + label_mapping: object +} + +export class FromApiConfigItemListRepository implements ConfigItemListRepository { + constructor( + private readonly request = ApiService + ) {} + + async list(projectId: string): Promise { + const url = `/projects/${projectId}/auto-labeling-configs` + const response = await this.request.get(url) + const responseItems: ConfigItemResponse[] = response.data + return ConfigItemList.valueOf( + responseItems.map(item => ConfigItem.valueOf(item)) + ) + } + + async create(projectId: string, item: ConfigItem): Promise { + const url = `/projects/${projectId}/auto-labeling-configs` + const response = await this.request.post(url, { + model_name: item.modelName, + model_attrs: item.modelAttrs, + template: item.template, + label_mapping: item.labelMapping + }) + const responseItem: ConfigItemResponse = response.data + return ConfigItem.valueOf(responseItem) + } + + async update(projectId: string, item: ConfigItem): Promise { + const url = `/projects/${projectId}/auto-labeling-configs/${item.id}` + const response = await this.request.put(url, { + id: item.id, + model_name: item.modelName, + model_attrs: item.modelAttrs, + template: item.template, + label_mapping: item.labelMapping + }) + const responseItem: ConfigItemResponse = response.data + return ConfigItem.valueOf(responseItem) + } + + async delete(projectId: string, itemId: number): Promise { + const url = `/projects/${projectId}/auto-labeling-configs/${itemId}` + await this.request.delete(url) + } +} diff --git a/frontend/repositories/config/interface.ts b/frontend/repositories/config/interface.ts new file mode 100644 index 00000000..1eb8923c --- /dev/null +++ b/frontend/repositories/config/interface.ts @@ -0,0 +1,11 @@ +import { ConfigItem, ConfigItemList } from '@/models/config/config-item-list' + +export interface ConfigItemListRepository { + list(projectId: string): Promise + + create(projectId: string, item: ConfigItem): Promise + + delete(projectId: string, itemId: number): Promise + + update(projectId: string, item: ConfigItem): Promise +} diff --git a/frontend/services/application/config.service.ts b/frontend/services/application/config.service.ts new file mode 100644 index 00000000..4fc86293 --- /dev/null +++ b/frontend/services/application/config.service.ts @@ -0,0 +1,16 @@ +import { ConfigItemList } from '@/models/config/config-item-list' +import { ConfigItemListRepository } from '@/repositories/config/interface' + +export class ConfigApplicationService { + constructor( + private readonly configRepository: ConfigItemListRepository + ) {} + + public list(id: string): Promise { + return this.configRepository.list(id) + } + + public delete(projectId: string, itemId: number) { + return this.configRepository.delete(projectId, itemId) + } +}