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.

154 lines
3.6 KiB

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