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.

176 lines
4.3 KiB

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