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.

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