mirror of https://github.com/doccano/doccano.git
8 changed files with 173 additions and 100 deletions
Unified View
Diff Options
-
29frontend/composables/labelType/useFormCreate.ts
-
24frontend/composables/labelType/useFormEdit.ts
-
51frontend/composables/labelType/useLabelType.ts
-
46frontend/pages/projects/_id/labels/_label_id/edit.vue
-
76frontend/pages/projects/_id/labels/add.vue
-
14frontend/pages/projects/_id/labels/import.vue
-
11frontend/pages/projects/_id/labels/index.vue
-
22frontend/plugins/labelType/validators.ts
@ -0,0 +1,29 @@ |
|||||
|
import { ref, useRouter } from '@nuxtjs/composition-api' |
||||
|
import { LabelRepository } from '@/domain/models/label/labelRepository' |
||||
|
import { LabelItem } from '@/domain/models/label/label' |
||||
|
import { useLabelType } from './useLabelType' |
||||
|
|
||||
|
export const useFormCreate = (repository: LabelRepository) => { |
||||
|
const { labelTypes, createLabelType, fetchLabelTypes } = useLabelType(repository) |
||||
|
const editedItem = ref<LabelItem>(LabelItem.create()) |
||||
|
const router = useRouter() |
||||
|
|
||||
|
const save = async (projectId: string) => { |
||||
|
await createLabelType(projectId, editedItem.value) |
||||
|
router.push(`/projects/${projectId}/labels`) |
||||
|
} |
||||
|
|
||||
|
const saveAndAnother = async (projectId: string) => { |
||||
|
await createLabelType(projectId, editedItem.value) |
||||
|
editedItem.value = LabelItem.create() |
||||
|
await fetchLabelTypes(projectId) |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
fetchLabelTypes, |
||||
|
save, |
||||
|
saveAndAnother, |
||||
|
labelTypes, |
||||
|
editedItem |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
import { ref, useRouter } from '@nuxtjs/composition-api' |
||||
|
import { LabelRepository } from '@/domain/models/label/labelRepository' |
||||
|
import { LabelItem } from '@/domain/models/label/label' |
||||
|
import { useLabelType } from './useLabelType' |
||||
|
|
||||
|
export const useFormEdit = (repository: LabelRepository) => { |
||||
|
const { labelTypes, updateLabelType, fetchLabelTypes, findLabelTypeById } = |
||||
|
useLabelType(repository) |
||||
|
const editedItem = ref<LabelItem>(LabelItem.create()) |
||||
|
const router = useRouter() |
||||
|
|
||||
|
const save = async (projectId: string): Promise<void> => { |
||||
|
await updateLabelType(projectId, editedItem.value) |
||||
|
router.push(`/projects/${projectId}/labels`) |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
fetchLabelTypes, |
||||
|
findLabelTypeById, |
||||
|
save, |
||||
|
labelTypes, |
||||
|
editedItem |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
import { computed, ref } from '@nuxtjs/composition-api' |
||||
|
import { LabelRepository } from '@/domain/models/label/labelRepository' |
||||
|
import { LabelItem } from '@/domain/models/label/label' |
||||
|
|
||||
|
export const useLabelType = (repository: LabelRepository) => { |
||||
|
const labelTypes = ref<LabelItem[]>([]) |
||||
|
const isLoading = ref(false) |
||||
|
|
||||
|
const fetchLabelTypes = async (projectId: string) => { |
||||
|
isLoading.value = true |
||||
|
labelTypes.value = await repository.list(projectId) |
||||
|
isLoading.value = false |
||||
|
} |
||||
|
|
||||
|
const createLabelType = async (projectId: string, labelType: LabelItem) => { |
||||
|
await repository.create(projectId, labelType) |
||||
|
await fetchLabelTypes(projectId) |
||||
|
} |
||||
|
|
||||
|
const updateLabelType = async (projectId: string, labelType: LabelItem) => { |
||||
|
await repository.update(projectId, labelType) |
||||
|
await fetchLabelTypes(projectId) |
||||
|
} |
||||
|
|
||||
|
const deleteLabelTypes = async (projectId: string, items: LabelItem[]) => { |
||||
|
await repository.bulkDelete( |
||||
|
projectId, |
||||
|
items.map((item) => item.id) |
||||
|
) |
||||
|
await fetchLabelTypes(projectId) |
||||
|
} |
||||
|
|
||||
|
const findLabelTypeById = async (projectId: string, labelTypeId: number) => { |
||||
|
return await repository.findById(projectId, labelTypeId) |
||||
|
} |
||||
|
|
||||
|
const usedShortKeys = computed(() => { |
||||
|
return Object.fromEntries(labelTypes.value.map((item) => [item.id, [item.suffixKey]])) |
||||
|
}) |
||||
|
|
||||
|
return { |
||||
|
labelTypes, |
||||
|
isLoading, |
||||
|
createLabelType, |
||||
|
fetchLabelTypes, |
||||
|
updateLabelType, |
||||
|
deleteLabelTypes, |
||||
|
findLabelTypeById, |
||||
|
usedShortKeys |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
const validateItemPage = async ({ params, query, app }: { params: any; query: any; app: any }) => { |
||||
|
if (!/^\d+$/.test(params.id)) { |
||||
|
return false |
||||
|
} |
||||
|
if (!['category', 'span', 'relation'].includes(query.type as string)) { |
||||
|
return false |
||||
|
} |
||||
|
const project = await app.$services.project.findById(params.id) |
||||
|
return project.canDefineLabel |
||||
|
} |
||||
|
|
||||
|
const validateEditPage = ({ params, query, app }: { params: any; query: any; app: any }) => { |
||||
|
if (!validateItemPage({ params, query, app })) { |
||||
|
return false |
||||
|
} |
||||
|
if (!/^\d+$/.test(params.label_id)) { |
||||
|
return false |
||||
|
} |
||||
|
return true |
||||
|
} |
||||
|
|
||||
|
export { validateItemPage, validateEditPage } |
Write
Preview
Loading…
Cancel
Save