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.

139 lines
4.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <layout-text v-if="example.id">
  3. <template #header>
  4. <toolbar-laptop
  5. :doc-id="example.id"
  6. :enable-auto-labeling.sync="enableAutoLabeling"
  7. :guideline-text="project.guideline"
  8. :is-reviewd="example.isConfirmed"
  9. :total="totalExample"
  10. class="d-none d-sm-block"
  11. @click:clear-label="clearTeacherList(project.id, example.id)"
  12. @click:review="confirm(project.id)"
  13. >
  14. <button-label-switch
  15. class="ms-2"
  16. @change="labelComponent=$event"
  17. />
  18. </toolbar-laptop>
  19. <toolbar-mobile
  20. :total="totalExample"
  21. class="d-flex d-sm-none"
  22. />
  23. </template>
  24. <template #content>
  25. <v-card
  26. v-shortkey="shortKeys"
  27. @shortkey="annotateOrRemoveLabel(project.id, example.id, $event.srcKey)"
  28. >
  29. <v-card-title>
  30. <component
  31. :is="labelComponent"
  32. :labels="labels"
  33. :annotations="teacherList"
  34. :single-label="project.singleClassClassification"
  35. @add="annotateLabel(project.id, example.id, $event)"
  36. @remove="removeTeacher(project.id, example.id, $event)"
  37. />
  38. </v-card-title>
  39. <v-divider />
  40. <v-card-text
  41. class="title highlight"
  42. style="white-space: pre-wrap;"
  43. v-text="example.text"
  44. />
  45. </v-card>
  46. </template>
  47. <template #sidebar>
  48. <list-metadata :metadata="example.meta" />
  49. </template>
  50. </layout-text>
  51. </template>
  52. <script>
  53. import { toRefs, useContext, useFetch, ref, watch } from '@nuxtjs/composition-api'
  54. import LabelGroup from '@/components/tasks/textClassification/LabelGroup'
  55. import LabelSelect from '@/components/tasks/textClassification/LabelSelect'
  56. import LayoutText from '@/components/tasks/layout/LayoutText'
  57. import ListMetadata from '@/components/tasks/metadata/ListMetadata'
  58. import ToolbarLaptop from '@/components/tasks/toolbar/ToolbarLaptop'
  59. import ToolbarMobile from '@/components/tasks/toolbar/ToolbarMobile'
  60. import ButtonLabelSwitch from '@/components/tasks/toolbar/buttons/ButtonLabelSwitch'
  61. import { useExampleItem } from '@/composables/useExampleItem'
  62. import { useLabelList } from '@/composables/useLabelList'
  63. import { useProjectItem } from '@/composables/useProjectItem'
  64. import { useTeacherList } from '@/composables/useTeacherList'
  65. export default {
  66. components: {
  67. ButtonLabelSwitch,
  68. LabelGroup,
  69. LabelSelect,
  70. LayoutText,
  71. ListMetadata,
  72. ToolbarLaptop,
  73. ToolbarMobile
  74. },
  75. layout: 'workspace',
  76. validate({ params, query }) {
  77. return /^\d+$/.test(params.id) && /^\d+$/.test(query.page)
  78. },
  79. setup() {
  80. const { app, params, query } = useContext()
  81. const projectId = params.value.id
  82. const { state: projectState, getProjectById } = useProjectItem()
  83. const { state: exampleState, confirm, getExample } = useExampleItem()
  84. const {
  85. state: teacherState,
  86. annotateLabel,
  87. annotateOrRemoveLabel,
  88. autoLabel,
  89. clearTeacherList,
  90. getTeacherList,
  91. removeTeacher
  92. } = useTeacherList(app.$services.textClassification)
  93. const enableAutoLabeling = ref(false)
  94. const { state: labelState, getLabelList, shortKeys } = useLabelList(app.$services.categoryType)
  95. const labelComponent = ref('label-group')
  96. getLabelList(projectId)
  97. getProjectById(projectId)
  98. const { fetch } = useFetch(async() => {
  99. await getExample(
  100. projectId,
  101. query.value
  102. )
  103. if (enableAutoLabeling.value) {
  104. try {
  105. await autoLabel(projectId, exampleState.example.id)
  106. } catch(e) {
  107. enableAutoLabeling.value = false
  108. alert(e.response.data.detail)
  109. }
  110. } else {
  111. await getTeacherList(projectId, exampleState.example.id)
  112. }
  113. })
  114. watch(query, fetch)
  115. return {
  116. ...toRefs(labelState),
  117. ...toRefs(projectState),
  118. ...toRefs(teacherState),
  119. ...toRefs(exampleState),
  120. confirm,
  121. annotateLabel,
  122. annotateOrRemoveLabel,
  123. clearTeacherList,
  124. enableAutoLabeling,
  125. labelComponent,
  126. removeTeacher,
  127. shortKeys,
  128. }
  129. }
  130. }
  131. </script>