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
3.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 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.url`]="{ item }">
  33. <audio
  34. controls
  35. :src="item.url"
  36. class="mt-2"
  37. >
  38. Your browser does not support the
  39. <code>audio</code> element.
  40. </audio>
  41. </template>
  42. <template #[`item.meta`]="{ item }">
  43. {{ JSON.stringify(item.meta, null, 4) }}
  44. </template>
  45. <template #[`item.commentCount`]="{ item }">
  46. <span> {{ item.commentCount }} </span>
  47. </template>
  48. <template #[`item.action`]="{ item }">
  49. <v-btn
  50. small
  51. color="primary text-capitalize"
  52. @click="toLabeling(item)"
  53. >
  54. {{ $t('dataset.annotate') }}
  55. </v-btn>
  56. </template>
  57. </v-data-table>
  58. </template>
  59. <script lang="ts">
  60. import Vue, { PropType } from 'vue'
  61. import { mdiMagnify } from '@mdi/js'
  62. import { DataOptions } from 'vuetify/types'
  63. import { ExampleDTO } from '~/services/application/example/exampleData'
  64. export default Vue.extend({
  65. props: {
  66. isLoading: {
  67. type: Boolean,
  68. default: false,
  69. required: true
  70. },
  71. items: {
  72. type: Array as PropType<ExampleDTO[]>,
  73. default: () => [],
  74. required: true
  75. },
  76. value: {
  77. type: Array as PropType<ExampleDTO[]>,
  78. default: () => [],
  79. required: true
  80. },
  81. total: {
  82. type: Number,
  83. default: 0,
  84. required: true
  85. }
  86. },
  87. data() {
  88. return {
  89. search: this.$route.query.q,
  90. options: {} as DataOptions,
  91. mdiMagnify
  92. }
  93. },
  94. computed: {
  95. headers() {
  96. return [
  97. {
  98. text: 'Audio',
  99. value: 'url',
  100. sortable: false
  101. },
  102. {
  103. text: 'Filename',
  104. value: 'filename',
  105. sortable: false
  106. },
  107. {
  108. text: this.$t('dataset.metadata'),
  109. value: 'meta',
  110. sortable: false
  111. },
  112. {
  113. text: this.$t('comments.comments'),
  114. value: 'commentCount',
  115. sortable: false
  116. },
  117. {
  118. text: this.$t('dataset.action'),
  119. value: 'action',
  120. sortable: false
  121. }
  122. ]
  123. }
  124. },
  125. watch: {
  126. options: {
  127. handler() {
  128. this.$emit('update:query', {
  129. query: {
  130. limit: this.options.itemsPerPage.toString(),
  131. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  132. q: this.search
  133. }
  134. })
  135. },
  136. deep: true
  137. },
  138. search() {
  139. this.$emit('update:query', {
  140. query: {
  141. limit: this.options.itemsPerPage.toString(),
  142. offset: '0',
  143. q: this.search
  144. }
  145. })
  146. this.options.page = 1
  147. }
  148. },
  149. methods: {
  150. toLabeling(item: ExampleDTO) {
  151. const index = this.items.indexOf(item)
  152. const offset = (this.options.page - 1) * this.options.itemsPerPage
  153. const page = (offset + index + 1).toString()
  154. this.$emit('click:labeling', { page, q: this.search })
  155. }
  156. }
  157. })
  158. </script>