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.

151 lines
3.6 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 class="mb-5">
  22. <v-card-text class="title" v-text="doc.text" />
  23. </v-card>
  24. <seq2seq-box
  25. :text="doc.text"
  26. :annotations="annotations"
  27. @delete:annotation="remove"
  28. @update:annotation="update"
  29. @create:annotation="add"
  30. />
  31. </template>
  32. <template v-slot:sidebar>
  33. <list-metadata :metadata="JSON.parse(doc.meta)" />
  34. </template>
  35. </layout-text>
  36. </template>
  37. <script>
  38. import _ from 'lodash'
  39. import LayoutText from '@/components/tasks/layout/LayoutText'
  40. import ListMetadata from '@/components/tasks/metadata/ListMetadata'
  41. import ToolbarLaptop from '@/components/tasks/toolbar/ToolbarLaptop'
  42. import ToolbarMobile from '@/components/tasks/toolbar/ToolbarMobile'
  43. import Seq2seqBox from '~/components/tasks/seq2seq/Seq2seqBox'
  44. export default {
  45. layout: 'workspace',
  46. components: {
  47. LayoutText,
  48. ListMetadata,
  49. Seq2seqBox,
  50. ToolbarLaptop,
  51. ToolbarMobile
  52. },
  53. async fetch() {
  54. this.docs = await this.$services.document.fetchOne(
  55. this.projectId,
  56. this.$route.query.page,
  57. this.$route.query.q,
  58. this.$route.query.isChecked,
  59. this.project.filterOption
  60. )
  61. const doc = this.docs.items[0]
  62. if (this.enableAutoLabeling) {
  63. await this.autoLabel(doc.id)
  64. }
  65. await this.list(doc.id)
  66. },
  67. data() {
  68. return {
  69. annotations: [],
  70. docs: [],
  71. project: {},
  72. enableAutoLabeling: false
  73. }
  74. },
  75. computed: {
  76. projectId() {
  77. return this.$route.params.id
  78. },
  79. doc() {
  80. if (_.isEmpty(this.docs) || this.docs.items.length === 0) {
  81. return {}
  82. } else {
  83. return this.docs.items[0]
  84. }
  85. }
  86. },
  87. watch: {
  88. '$route.query': '$fetch',
  89. enableAutoLabeling(val) {
  90. if (val) {
  91. this.list(this.doc.id)
  92. }
  93. }
  94. },
  95. async created() {
  96. this.project = await this.$services.project.findById(this.projectId)
  97. },
  98. methods: {
  99. async list(docId) {
  100. this.annotations = await this.$services.seq2seq.list(this.projectId, docId)
  101. },
  102. async remove(id) {
  103. await this.$services.seq2seq.delete(this.projectId, this.doc.id, id)
  104. await this.list(this.doc.id)
  105. },
  106. async add(text) {
  107. await this.$services.seq2seq.create(this.projectId, this.doc.id, text)
  108. await this.list(this.doc.id)
  109. },
  110. async update(annotationId, text) {
  111. await this.$services.seq2seq.changeText(this.projectId, this.doc.id, annotationId, text)
  112. await this.list(this.doc.id)
  113. },
  114. async clear() {
  115. await this.$services.seq2seq.clear(this.projectId, this.doc.id)
  116. await this.list(this.doc.id)
  117. },
  118. async autoLabel(docId) {
  119. try {
  120. await this.$services.seq2seq.autoLabel(this.projectId, docId)
  121. } catch (e) {
  122. console.log(e.response.data.detail)
  123. }
  124. },
  125. async approve() {
  126. const approved = !this.doc.isApproved
  127. await this.$services.document.approve(this.projectId, this.doc.id, approved)
  128. await this.$fetch()
  129. }
  130. },
  131. validate({ params, query }) {
  132. return /^\d+$/.test(params.id) && /^\d+$/.test(query.page)
  133. }
  134. }
  135. </script>