Browse Source

Update useLabelList to pass LabelApplicationService

pull/1619/head
Hironsan 2 years ago
parent
commit
965f760da0
4 changed files with 13 additions and 12 deletions
  1. 15
      frontend/composables/useLabelList.ts
  2. 5
      frontend/pages/projects/_id/image-classification/index.vue
  3. 2
      frontend/pages/projects/_id/text-classification/index.vue
  4. 3
      frontend/services/application/label/labelApplicationService.ts

15
frontend/composables/useLabelList.ts

@ -1,27 +1,26 @@
import { computed, reactive, ref, useContext } from '@nuxtjs/composition-api'
import { computed, reactive, useContext } from '@nuxtjs/composition-api'
import { LabelDTO } from '@/services/application/label/labelData'
import { CreateLabelCommand , UpdateLabelCommand } from '@/services/application/label/labelCommand'
import { LabelApplicationService } from '@/services/application/label/labelApplicationService'
export const useLabelList = () => {
export const useLabelList = (service: LabelApplicationService) => {
const state = reactive({
labels: [] as LabelDTO[]
})
const { app } = useContext()
const $services = app.$services
const getLabelList = async(
projectId: string
) => {
state.labels = await $services.label.list(projectId)
state.labels = await service.list(projectId)
}
const createLabel = async(
projectId: string,
command: CreateLabelCommand
) => {
await $services.label.create(projectId, command)
await service.create(projectId, command)
await getLabelList(projectId)
}
@ -29,14 +28,14 @@ export const useLabelList = () => {
projectId: string,
command: UpdateLabelCommand
) => {
await $services.label.update(projectId, command)
await service.update(projectId, command)
}
const deleteLabelList = async(
projectId: string,
items: LabelDTO[]
) => {
await $services.label.bulkDelete(projectId, items)
await service.bulkDelete(projectId, items)
await getLabelList(projectId)
}

5
frontend/pages/projects/_id/image-classification/index.vue

@ -70,7 +70,7 @@
<script>
import _ from 'lodash'
import { mdiText, mdiFormatListBulleted } from '@mdi/js'
import { toRefs } from '@nuxtjs/composition-api'
import { toRefs, useContext } from '@nuxtjs/composition-api'
import LabelGroup from '@/components/tasks/textClassification/LabelGroup'
import LabelSelect from '@/components/tasks/textClassification/LabelSelect'
import LayoutText from '@/components/tasks/layout/LayoutText'
@ -96,7 +96,8 @@ export default {
},
setup() {
const { state, getLabelList, shortKeys } = useLabelList()
const { app } = useContext()
const { state, getLabelList, shortKeys } = useLabelList(app.$services.categoryType)
return {
...toRefs(state),

2
frontend/pages/projects/_id/text-classification/index.vue

@ -96,7 +96,7 @@ export default {
removeTeacher
} = useTeacherList(app.$services.textClassification)
const enableAutoLabeling = ref(false)
const { state: labelState, getLabelList, shortKeys } = useLabelList()
const { state: labelState, getLabelList, shortKeys } = useLabelList(app.$services.categoryType)
const labelComponent = ref('label-group')
getLabelList(projectId)

3
frontend/services/application/label/labelApplicationService.ts

@ -1,4 +1,5 @@
import { LabelDTO } from './labelData'
import { CreateLabelCommand } from './labelCommand';
import { LabelRepository } from '~/domain/models/label/labelRepository'
import { LabelItem } from '~/domain/models/label/label'
@ -13,7 +14,7 @@ export class LabelApplicationService {
return items.map(item => new LabelDTO(item))
}
public create(projectId: string, item: LabelDTO): void {
public create(projectId: string, item: CreateLabelCommand): void {
const label = new LabelItem(0, item.text, item.prefixKey, item.suffixKey, item.backgroundColor, item.textColor)
this.repository.create(projectId, label)
}

Loading…
Cancel
Save