Browse Source

Replace field type from object to TagItem

pull/2093/head
Hironsan 2 years ago
parent
commit
1cb34dd214
5 changed files with 14 additions and 6 deletions
  1. 2
      frontend/components/project/FormUpdate.vue
  2. 6
      frontend/domain/models/project/project.ts
  3. 6
      frontend/domain/models/tag/tag.ts
  4. 3
      frontend/repositories/project/apiProjectRepository.ts
  5. 3
      frontend/services/application/project/projectApplicationService.ts

2
frontend/components/project/FormUpdate.vue

@ -71,7 +71,7 @@ export default Vue.extend({
async fetch() {
const projectId = this.$route.params.id
this.project = await this.$services.project.findById(projectId)
this.tags = this.project.tags.map((item: any) => item.text)
this.tags = this.project.tags.map((item) => item.text)
this.isEditing = false
},

6
frontend/domain/models/project/project.ts

@ -1,3 +1,5 @@
import { TagItem } from '~/domain/models/tag/tag'
export const DocumentClassification = 'DocumentClassification'
export const SequenceLabeling = 'SequenceLabeling'
export const Seq2seq = 'Seq2seq'
@ -47,7 +49,7 @@ export class Project {
readonly allowOverlappingSpans: boolean,
readonly enableGraphemeMode: boolean,
readonly useRelation: boolean,
readonly tags: Object[],
readonly tags: TagItem[],
readonly users: number[] = [],
readonly createdAt: string = '',
readonly updatedAt: string = '',
@ -83,7 +85,7 @@ export class Project {
allowOverlappingSpans: boolean,
enableGraphemeMode: boolean,
useRelation: boolean,
tags: Object[]
tags: TagItem[]
) {
return new Project(
id,

6
frontend/domain/models/tag/tag.ts

@ -1,3 +1,7 @@
export class TagItem {
constructor(readonly id: number, readonly text: string, readonly project: string) {}
constructor(readonly id: number, readonly text: string, readonly project: string | number) {}
static create(text: string): TagItem {
return new TagItem(0, text, 0)
}
}

3
frontend/repositories/project/apiProjectRepository.ts

@ -1,6 +1,7 @@
import { Page } from '@/domain/models/page'
import { Project } from '@/domain/models/project/project'
import ApiService from '@/services/api.service'
import { TagItem } from '~/domain/models/tag/tag'
const sortableFieldList = ['name', 'projectType', 'createdAt', 'author'] as const
type SortableFields = typeof sortableFieldList[number]
@ -36,7 +37,7 @@ function toModel(item: { [key: string]: any }): Project {
item.allow_overlapping,
item.grapheme_mode,
item.use_relation,
item.tags,
item.tags.map((tag: { [key: string]: any }) => new TagItem(tag.id, tag.text, tag.project)),
item.users,
item.created_at,
item.updated_at,

3
frontend/services/application/project/projectApplicationService.ts

@ -1,5 +1,6 @@
import { Page } from '~/domain/models/page'
import { Project } from '~/domain/models/project/project'
import { TagItem } from '~/domain/models/tag/tag'
import { APIProjectRepository, SearchQuery } from '~/repositories/project/apiProjectRepository'
type Options = {
@ -65,7 +66,7 @@ export class ProjectApplicationService {
allowOverlappingSpans,
enableGraphemeMode,
useRelation,
tags.map((tag) => ({ text: tag }))
tags.map((tag) => TagItem.create(tag))
)
try {
return await this.repository.create(project)

Loading…
Cancel
Save