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.

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