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.

158 lines
4.0 KiB

  1. <template>
  2. <layout-text v-if="doc.id">
  3. <template v-slot:header>
  4. <toolbar-laptop
  5. :doc-id="doc.id"
  6. :enable-auto-labeling.sync="enableAutoLabeling"
  7. :guideline-text="project.guideline"
  8. :is-reviewd="doc.isApproved"
  9. :show-approve-button="project.permitApprove"
  10. :total="docs.count"
  11. class="d-none d-sm-block"
  12. @click:clear-label="clear"
  13. @click:review="approve"
  14. />
  15. <toolbar-mobile
  16. :total="docs.count"
  17. class="d-flex d-sm-none"
  18. />
  19. </template>
  20. <template v-slot:content>
  21. <v-card>
  22. <v-card-text class="title">
  23. <entity-item-box
  24. :labels="labels"
  25. :text="doc.text"
  26. :entities="annotations"
  27. :delete-annotation="remove"
  28. :update-entity="update"
  29. :add-entity="add"
  30. />
  31. </v-card-text>
  32. </v-card>
  33. </template>
  34. <template v-slot:sidebar>
  35. <list-metadata :metadata="JSON.parse(doc.meta)" />
  36. </template>
  37. </layout-text>
  38. </template>
  39. <script>
  40. import _ from 'lodash'
  41. import LayoutText from '@/components/tasks/layout/LayoutText'
  42. import ListMetadata from '@/components/tasks/metadata/ListMetadata'
  43. import ToolbarLaptop from '@/components/tasks/toolbar/ToolbarLaptop'
  44. import ToolbarMobile from '@/components/tasks/toolbar/ToolbarMobile'
  45. import EntityItemBox from '~/components/tasks/sequenceLabeling/EntityItemBox'
  46. export default {
  47. layout: 'workspace',
  48. components: {
  49. EntityItemBox,
  50. LayoutText,
  51. ListMetadata,
  52. ToolbarLaptop,
  53. ToolbarMobile
  54. },
  55. async fetch() {
  56. this.docs = await this.$services.document.fetchOne(
  57. this.projectId,
  58. this.$route.query.page,
  59. this.$route.query.q,
  60. this.$route.query.isChecked,
  61. this.project.filterOption
  62. )
  63. const doc = this.docs.items[0]
  64. if (this.enableAutoLabeling) {
  65. await this.autoLabel(doc.id)
  66. }
  67. await this.list(doc.id)
  68. },
  69. data() {
  70. return {
  71. annotations: [],
  72. docs: [],
  73. labels: [],
  74. project: {},
  75. enableAutoLabeling: false
  76. }
  77. },
  78. computed: {
  79. shortKeys() {
  80. return Object.fromEntries(this.labels.map(item => [item.id, [item.suffixKey]]))
  81. },
  82. projectId() {
  83. return this.$route.params.id
  84. },
  85. doc() {
  86. if (_.isEmpty(this.docs) || this.docs.items.length === 0) {
  87. return {}
  88. } else {
  89. return this.docs.items[0]
  90. }
  91. }
  92. },
  93. watch: {
  94. '$route.query': '$fetch',
  95. enableAutoLabeling(val) {
  96. if (val) {
  97. this.list(this.doc.id)
  98. }
  99. }
  100. },
  101. async created() {
  102. this.labels = await this.$services.label.list(this.projectId)
  103. this.project = await this.$services.project.findById(this.projectId)
  104. },
  105. methods: {
  106. async list(docId) {
  107. this.annotations = await this.$services.sequenceLabeling.list(this.projectId, docId)
  108. },
  109. async remove(id) {
  110. await this.$services.sequenceLabeling.delete(this.projectId, this.doc.id, id)
  111. await this.list(this.doc.id)
  112. },
  113. async add(startOffset, endOffset, labelId) {
  114. await this.$services.sequenceLabeling.create(this.projectId, this.doc.id, labelId, startOffset, endOffset)
  115. await this.list(this.doc.id)
  116. },
  117. async update(labelId, annotationId) {
  118. await this.$services.sequenceLabeling.changeLabel(this.projectId, this.doc.id, annotationId, labelId)
  119. await this.list(this.doc.id)
  120. },
  121. async clear() {
  122. await this.$services.sequenceLabeling.clear(this.projectId, this.doc.id)
  123. await this.list(this.doc.id)
  124. },
  125. async autoLabel(docId) {
  126. try {
  127. await this.$services.sequenceLabeling.autoLabel(this.projectId, docId)
  128. } catch (e) {
  129. console.log(e.response.data.detail)
  130. }
  131. },
  132. async approve() {
  133. const approved = !this.doc.isApproved
  134. await this.$services.document.approve(this.projectId, this.doc.id, approved)
  135. await this.$fetch()
  136. }
  137. },
  138. validate({ params, query }) {
  139. return /^\d+$/.test(params.id) && /^\d+$/.test(query.page)
  140. }
  141. }
  142. </script>