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.

162 lines
3.6 KiB

  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 v-slot:top>
  23. <v-text-field
  24. v-model="search"
  25. prepend-inner-icon="search"
  26. :label="$t('generic.search')"
  27. single-line
  28. hide-details
  29. filled
  30. />
  31. </template>
  32. <template v-slot:[`item.url`]="{ item }">
  33. <v-img
  34. :src="item.url"
  35. aspect-ratio="1"
  36. height="150"
  37. max-height="150"
  38. width="150"
  39. class="grey lighten-2"
  40. />
  41. </template>
  42. <template v-slot:[`item.meta`]="{ item }">
  43. {{ JSON.stringify(item.meta, null, 4) }}
  44. </template>
  45. <template v-slot:[`item.commentCount`]="{ item }">
  46. <span> {{ item.commentCount }} </span>
  47. </template>
  48. <template v-slot:[`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 { DataOptions } from 'vuetify/types'
  62. import { ExampleDTO } from '~/services/application/example/exampleData'
  63. export default Vue.extend({
  64. props: {
  65. isLoading: {
  66. type: Boolean,
  67. default: false,
  68. required: true
  69. },
  70. items: {
  71. type: Array as PropType<ExampleDTO[]>,
  72. default: () => [],
  73. required: true
  74. },
  75. value: {
  76. type: Array as PropType<ExampleDTO[]>,
  77. default: () => [],
  78. required: true
  79. },
  80. total: {
  81. type: Number,
  82. default: 0,
  83. required: true
  84. }
  85. },
  86. data() {
  87. return {
  88. search: this.$route.query.q,
  89. options: {} as DataOptions,
  90. }
  91. },
  92. computed: {
  93. headers() {
  94. return [
  95. {
  96. text: 'Image',
  97. value: 'url',
  98. sortable: false
  99. },
  100. {
  101. text: 'Filename',
  102. value: 'filename',
  103. sortable: false
  104. },
  105. {
  106. text: this.$t('dataset.metadata'),
  107. value: 'meta',
  108. sortable: false
  109. },
  110. {
  111. text: this.$t('comments.comments'),
  112. value: 'commentCount',
  113. sortable: false
  114. },
  115. {
  116. text: this.$t('dataset.action'),
  117. value: 'action',
  118. sortable: false
  119. }
  120. ]
  121. }
  122. },
  123. watch: {
  124. options: {
  125. handler() {
  126. this.$emit('update:query', {
  127. query: {
  128. limit: this.options.itemsPerPage.toString(),
  129. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  130. q: this.search
  131. }
  132. })
  133. },
  134. deep: true
  135. },
  136. search() {
  137. this.$emit('update:query', {
  138. query: {
  139. limit: this.options.itemsPerPage.toString(),
  140. offset: '0',
  141. q: this.search
  142. }
  143. })
  144. this.options.page = 1
  145. }
  146. },
  147. methods: {
  148. toLabeling(item: ExampleDTO) {
  149. const index = this.items.indexOf(item)
  150. const offset = (this.options.page - 1) * this.options.itemsPerPage
  151. const page = (offset + index + 1).toString()
  152. this.$emit('click:labeling', { page, q: this.search })
  153. }
  154. }
  155. })
  156. </script>