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.

172 lines
4.0 KiB

2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
  1. <template>
  2. <v-data-table
  3. :value="value"
  4. :headers="headers"
  5. :items="items"
  6. :options.sync="options"
  7. :server-items-length="total"
  8. :search="search"
  9. :loading="isLoading"
  10. :loading-text="$t('generic.loading')"
  11. :no-data-text="$t('vuetify.noDataAvailable')"
  12. :footer-props="{
  13. showFirstLastPage: true,
  14. 'items-per-page-options': [10, 50, 100],
  15. 'items-per-page-text': $t('vuetify.itemsPerPageText'),
  16. 'page-text': $t('dataset.pageText')
  17. }"
  18. item-key="id"
  19. show-select
  20. @input="$emit('input', $event)"
  21. >
  22. <template #top>
  23. <v-text-field
  24. v-model="search"
  25. :prepend-inner-icon="mdiMagnify"
  26. :label="$t('generic.search')"
  27. single-line
  28. hide-details
  29. filled
  30. />
  31. </template>
  32. <template #[`item.isConfirmed`]="{ item }">
  33. <v-chip :color="item.isConfirmed ? 'success' : 'warning'" text small>
  34. {{ item.isConfirmed ? 'Finished' : 'In progress' }}
  35. </v-chip>
  36. </template>
  37. <template #[`item.url`]="{ item }">
  38. <audio controls :src="item.url" class="mt-2">
  39. Your browser does not support the
  40. <code>audio</code> element.
  41. </audio>
  42. </template>
  43. <template #[`item.meta`]="{ item }">
  44. {{ JSON.stringify(item.meta, null, 4) }}
  45. </template>
  46. <template #[`item.commentCount`]="{ item }">
  47. <span> {{ item.commentCount }} </span>
  48. </template>
  49. <template #[`item.action`]="{ item }">
  50. <v-btn small color="primary text-capitalize" @click="toLabeling(item)">
  51. {{ $t('dataset.annotate') }}
  52. </v-btn>
  53. </template>
  54. </v-data-table>
  55. </template>
  56. <script lang="ts">
  57. import { mdiMagnify } from '@mdi/js'
  58. import type { PropType } from 'vue'
  59. import Vue from 'vue'
  60. import { DataOptions } from 'vuetify/types'
  61. import { ExampleDTO } from '~/services/application/example/exampleData'
  62. export default Vue.extend({
  63. props: {
  64. isLoading: {
  65. type: Boolean,
  66. default: false,
  67. required: true
  68. },
  69. items: {
  70. type: Array as PropType<ExampleDTO[]>,
  71. default: () => [],
  72. required: true
  73. },
  74. value: {
  75. type: Array as PropType<ExampleDTO[]>,
  76. default: () => [],
  77. required: true
  78. },
  79. total: {
  80. type: Number,
  81. default: 0,
  82. required: true
  83. }
  84. },
  85. data() {
  86. return {
  87. search: this.$route.query.q,
  88. options: {} as DataOptions,
  89. mdiMagnify
  90. }
  91. },
  92. computed: {
  93. headers() {
  94. return [
  95. {
  96. text: 'ID',
  97. value: 'id',
  98. sortable: false
  99. },
  100. {
  101. text: 'Status',
  102. value: 'isConfirmed',
  103. sortable: false
  104. },
  105. {
  106. text: 'Audio',
  107. value: 'url',
  108. sortable: false
  109. },
  110. {
  111. text: 'Filename',
  112. value: 'filename',
  113. sortable: false
  114. },
  115. {
  116. text: this.$t('dataset.metadata'),
  117. value: 'meta',
  118. sortable: false
  119. },
  120. {
  121. text: this.$t('comments.comments'),
  122. value: 'commentCount',
  123. sortable: false
  124. },
  125. {
  126. text: this.$t('dataset.action'),
  127. value: 'action',
  128. sortable: false
  129. }
  130. ]
  131. }
  132. },
  133. watch: {
  134. options: {
  135. handler() {
  136. this.$emit('update:query', {
  137. query: {
  138. limit: this.options.itemsPerPage.toString(),
  139. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  140. q: this.search
  141. }
  142. })
  143. },
  144. deep: true
  145. },
  146. search() {
  147. this.$emit('update:query', {
  148. query: {
  149. limit: this.options.itemsPerPage.toString(),
  150. offset: '0',
  151. q: this.search
  152. }
  153. })
  154. this.options.page = 1
  155. }
  156. },
  157. methods: {
  158. toLabeling(item: ExampleDTO) {
  159. const index = this.items.indexOf(item)
  160. const offset = (this.options.page - 1) * this.options.itemsPerPage
  161. const page = (offset + index + 1).toString()
  162. this.$emit('click:labeling', { page, q: this.search })
  163. }
  164. }
  165. })
  166. </script>