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.

164 lines
4.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <layout-text v-if="doc.id">
  3. <template #header>
  4. <toolbar-laptop
  5. :doc-id="doc.id"
  6. :enable-auto-labeling.sync="enableAutoLabeling"
  7. :guideline-text="project.guideline"
  8. :is-reviewd="doc.isConfirmed"
  9. :total="docs.count"
  10. class="d-none d-sm-block"
  11. @click:clear-label="clear"
  12. @click:review="confirm"
  13. />
  14. <toolbar-mobile
  15. :total="docs.count"
  16. class="d-flex d-sm-none"
  17. />
  18. </template>
  19. <template #content>
  20. <v-card class="mb-5">
  21. <v-card-text class="title text-pre-wrap" v-text="doc.text" />
  22. </v-card>
  23. <seq2seq-box
  24. :text="doc.text"
  25. :annotations="annotations"
  26. @delete:annotation="remove"
  27. @update:annotation="update"
  28. @create:annotation="add"
  29. />
  30. </template>
  31. <template #sidebar>
  32. <annotation-progress :progress="progress" />
  33. <list-metadata :metadata="doc.meta" class="mt-4" />
  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 AnnotationProgress from '@/components/tasks/sidebar/AnnotationProgress.vue'
  44. import Seq2seqBox from '~/components/tasks/seq2seq/Seq2seqBox'
  45. export default {
  46. components: {
  47. AnnotationProgress,
  48. LayoutText,
  49. ListMetadata,
  50. Seq2seqBox,
  51. ToolbarLaptop,
  52. ToolbarMobile
  53. },
  54. layout: 'workspace',
  55. validate({ params, query }) {
  56. return /^\d+$/.test(params.id) && /^\d+$/.test(query.page)
  57. },
  58. data() {
  59. return {
  60. annotations: [],
  61. docs: [],
  62. project: {},
  63. enableAutoLabeling: false,
  64. progress: {}
  65. }
  66. },
  67. async fetch() {
  68. this.docs = await this.$services.example.fetchOne(
  69. this.projectId,
  70. this.$route.query.page,
  71. this.$route.query.q,
  72. this.$route.query.isChecked
  73. )
  74. const doc = this.docs.items[0]
  75. if (this.enableAutoLabeling) {
  76. await this.autoLabel(doc.id)
  77. }
  78. await this.list(doc.id)
  79. },
  80. computed: {
  81. projectId() {
  82. return this.$route.params.id
  83. },
  84. doc() {
  85. if (_.isEmpty(this.docs) || this.docs.items.length === 0) {
  86. return {}
  87. } else {
  88. return this.docs.items[0]
  89. }
  90. }
  91. },
  92. watch: {
  93. '$route.query': '$fetch',
  94. enableAutoLabeling(val) {
  95. if (val) {
  96. this.list(this.doc.id)
  97. }
  98. }
  99. },
  100. async created() {
  101. this.project = await this.$services.project.findById(this.projectId)
  102. this.progress = await this.$services.metrics.fetchMyProgress(this.projectId)
  103. },
  104. methods: {
  105. async list(docId) {
  106. this.annotations = await this.$services.seq2seq.list(this.projectId, docId)
  107. },
  108. async remove(id) {
  109. await this.$services.seq2seq.delete(this.projectId, this.doc.id, id)
  110. await this.list(this.doc.id)
  111. },
  112. async add(text) {
  113. await this.$services.seq2seq.create(this.projectId, this.doc.id, text)
  114. await this.list(this.doc.id)
  115. },
  116. async update(annotationId, text) {
  117. await this.$services.seq2seq.changeText(this.projectId, this.doc.id, annotationId, text)
  118. await this.list(this.doc.id)
  119. },
  120. async clear() {
  121. await this.$services.seq2seq.clear(this.projectId, this.doc.id)
  122. await this.list(this.doc.id)
  123. },
  124. async autoLabel(docId) {
  125. try {
  126. await this.$services.seq2seq.autoLabel(this.projectId, docId)
  127. } catch (e) {
  128. console.log(e.response.data.detail)
  129. }
  130. },
  131. async updateProgress() {
  132. this.progress = await this.$services.metrics.fetchMyProgress(this.projectId)
  133. },
  134. async confirm() {
  135. await this.$services.example.confirm(this.projectId, this.doc.id)
  136. await this.$fetch()
  137. this.updateProgress()
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. .text-pre-wrap {
  144. white-space: pre-wrap !important;
  145. }
  146. </style>