You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { reactive } from '@nuxtjs/composition-api'
  2. import { Category } from '~/domain/models/tasks/category'
  3. export const useTeacherList = (repository: any) => {
  4. const state = reactive({
  5. teacherList: []
  6. })
  7. const getTeacherList = async (projectId: string, exampleId: number) => {
  8. state.teacherList = await repository.list(projectId, exampleId)
  9. }
  10. const removeTeacher = async (projectId: string, exampleId: number, teacherId: number) => {
  11. await repository.delete(projectId, exampleId, teacherId)
  12. await getTeacherList(projectId, exampleId)
  13. }
  14. const annotateLabel = async (projectId: string, exampleId: number, labelId: number) => {
  15. const category = Category.create(labelId)
  16. await repository.create(projectId, exampleId, category)
  17. await getTeacherList(projectId, exampleId)
  18. }
  19. const clearTeacherList = async (projectId: string, exampleId: number) => {
  20. await repository.clear(projectId, exampleId)
  21. await getTeacherList(projectId, exampleId)
  22. }
  23. const autoLabel = async (projectId: string, exampleId: number) => {
  24. await repository.autoLabel(projectId, exampleId)
  25. await getTeacherList(projectId, exampleId)
  26. }
  27. const annotateOrRemoveLabel = async (projectId: string, exampleId: number, srcKey: string) => {
  28. const labelId = parseInt(srcKey, 10)
  29. // @ts-ignore
  30. const annotation = state.teacherList.find((item) => item.label === labelId)
  31. if (annotation) {
  32. // @ts-ignore
  33. await removeTeacher(projectId, exampleId, annotation.id)
  34. } else {
  35. await annotateLabel(projectId, exampleId, labelId)
  36. }
  37. }
  38. return {
  39. state,
  40. getTeacherList,
  41. annotateLabel,
  42. annotateOrRemoveLabel,
  43. removeTeacher,
  44. clearTeacherList,
  45. autoLabel
  46. }
  47. }