mirror of https://github.com/doccano/doccano.git
Hironsan
3 years ago
6 changed files with 173 additions and 35 deletions
Split View
Diff Options
-
3frontend/.eslintrc.js
-
75frontend/components/containers/settings/ConfigList.vue
-
47frontend/models/config/config-item-list.ts
-
56frontend/repositories/config/api.ts
-
11frontend/repositories/config/interface.ts
-
16frontend/services/application/config.service.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 |
|||
} |
|||
] |
@ -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<ConfigItemList> { |
|||
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<ConfigItem> { |
|||
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<ConfigItem> { |
|||
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<void> { |
|||
const url = `/projects/${projectId}/auto-labeling-configs/${itemId}` |
|||
await this.request.delete(url) |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
import { ConfigItem, ConfigItemList } from '@/models/config/config-item-list' |
|||
|
|||
export interface ConfigItemListRepository { |
|||
list(projectId: string): Promise<ConfigItemList> |
|||
|
|||
create(projectId: string, item: ConfigItem): Promise<ConfigItem> |
|||
|
|||
delete(projectId: string, itemId: number): Promise<void> |
|||
|
|||
update(projectId: string, item: ConfigItem): Promise<ConfigItem> |
|||
} |
@ -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<ConfigItemList> { |
|||
return this.configRepository.list(id) |
|||
} |
|||
|
|||
public delete(projectId: string, itemId: number) { |
|||
return this.configRepository.delete(projectId, itemId) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save