From 3a9d1359817ca35151513008d962cd299a4612d7 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 20 May 2021 14:35:35 +0900 Subject: [PATCH] Add composition api for label list --- frontend/composables/useLabelList.ts | 60 +++++++++++++++++++ .../_id/image-classification/index.vue | 24 +++++--- .../projects/_id/sequence-labeling/index.vue | 20 +++++-- .../_id/text-classification/index.vue | 24 +++++--- 4 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 frontend/composables/useLabelList.ts diff --git a/frontend/composables/useLabelList.ts b/frontend/composables/useLabelList.ts new file mode 100644 index 00000000..b6c770c9 --- /dev/null +++ b/frontend/composables/useLabelList.ts @@ -0,0 +1,60 @@ +import { computed, reactive, ref, useContext } from '@nuxtjs/composition-api' +import { LabelDTO } from '@/services/application/label/labelData' +import { CreateLabelCommand , UpdateLabelCommand } from '@/services/application/label/labelCommand' + + +export const useLabelList = () => { + 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) + } + + const createLabel = async( + projectId: string, + command: CreateLabelCommand + ) => { + await $services.label.create(projectId, command) + await getLabelList(projectId) + } + + const updateLabel = async( + projectId: string, + command: UpdateLabelCommand + ) => { + await $services.label.update(projectId, command) + } + + const deleteLabelList = async( + projectId: string, + items: LabelDTO[] + ) => { + await $services.label.bulkDelete(projectId, items) + await getLabelList(projectId) + } + + const findLabelById = (labelId: number) => { + return state.labels.find(item => item.id === labelId) + } + + const shortKeys = computed(() => { + return Object.fromEntries(state.labels.map(item => [item.id, [item.suffixKey]])) + }) + + return { + state, + getLabelList, + findLabelById, + createLabel, + updateLabel, + deleteLabelList, + shortKeys, + } +} diff --git a/frontend/pages/projects/_id/image-classification/index.vue b/frontend/pages/projects/_id/image-classification/index.vue index c34047c5..400e5f43 100644 --- a/frontend/pages/projects/_id/image-classification/index.vue +++ b/frontend/pages/projects/_id/image-classification/index.vue @@ -70,12 +70,14 @@