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.

73 lines
1.7 KiB

  1. import { reactive } from '@nuxtjs/composition-api'
  2. export const useTeacherList = (service: any) => {
  3. const state = reactive({
  4. teacherList: []
  5. })
  6. const getTeacherList = async(
  7. projectId: string,
  8. exampleId: number
  9. ) => {
  10. state.teacherList = await service.list(projectId, exampleId)
  11. }
  12. const removeTeacher = async(
  13. projectId: string,
  14. exampleId: number,
  15. teacherId: number
  16. ) => {
  17. await service.delete(projectId, exampleId, teacherId)
  18. await getTeacherList(projectId, exampleId)
  19. }
  20. const annotateLabel = async(
  21. projectId: string,
  22. exampleId: number,
  23. labelId: number
  24. ) => {
  25. await service.create(projectId, exampleId, labelId)
  26. await getTeacherList(projectId, exampleId)
  27. }
  28. const clearTeacherList = async(
  29. projectId: string,
  30. exampleId: number
  31. ) => {
  32. await service.clear(projectId, exampleId)
  33. await getTeacherList(projectId, exampleId)
  34. }
  35. const autoLabel = async(
  36. projectId: string,
  37. exampleId: number
  38. ) => {
  39. await service.autoLabel(projectId, exampleId)
  40. await getTeacherList(projectId, exampleId)
  41. }
  42. const annotateOrRemoveLabel = async(
  43. projectId: string,
  44. exampleId: number,
  45. srcKey: string
  46. ) => {
  47. const labelId = parseInt(srcKey, 10)
  48. // @ts-ignore
  49. const annotation = state.teacherList.find(item => item.label === labelId)
  50. if (annotation) {
  51. // @ts-ignore
  52. await removeTeacher(projectId, exampleId, annotation.id)
  53. } else {
  54. await annotateLabel(projectId, exampleId, labelId)
  55. }
  56. }
  57. return {
  58. state,
  59. getTeacherList,
  60. annotateLabel,
  61. annotateOrRemoveLabel,
  62. removeTeacher,
  63. clearTeacherList,
  64. autoLabel,
  65. }
  66. }