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.9 KiB

2 years ago
3 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.text`]="{ item }">
  38. <span class="d-flex d-sm-none">{{ item.text | truncate(50) }}</span>
  39. <span class="d-none d-sm-flex">{{ item.text | truncate(200) }}</span>
  40. </template>
  41. <template #[`item.meta`]="{ item }">
  42. {{ JSON.stringify(item.meta, null, 4) }}
  43. </template>
  44. <template #[`item.commentCount`]="{ item }">
  45. <span> {{ item.commentCount }} </span>
  46. </template>
  47. <template #[`item.action`]="{ item }">
  48. <v-btn small color="primary text-capitalize" @click="toLabeling(item)">
  49. {{ $t('dataset.annotate') }}
  50. </v-btn>
  51. </template>
  52. </v-data-table>
  53. </template>
  54. <script lang="ts">
  55. import Vue, { PropType } from 'vue'
  56. import { mdiMagnify } from '@mdi/js'
  57. import { DataOptions } from 'vuetify/types'
  58. import { ExampleDTO } from '~/services/application/example/exampleData'
  59. export default Vue.extend({
  60. props: {
  61. isLoading: {
  62. type: Boolean,
  63. default: false,
  64. required: true
  65. },
  66. items: {
  67. type: Array as PropType<ExampleDTO[]>,
  68. default: () => [],
  69. required: true
  70. },
  71. value: {
  72. type: Array as PropType<ExampleDTO[]>,
  73. default: () => [],
  74. required: true
  75. },
  76. total: {
  77. type: Number,
  78. default: 0,
  79. required: true
  80. }
  81. },
  82. data() {
  83. return {
  84. search: this.$route.query.q,
  85. options: {} as DataOptions,
  86. mdiMagnify
  87. }
  88. },
  89. computed: {
  90. headers() {
  91. return [
  92. {
  93. text: 'ID',
  94. value: 'id',
  95. sortable: false
  96. },
  97. {
  98. text: 'Status',
  99. value: 'isConfirmed',
  100. sortable: false
  101. },
  102. {
  103. text: this.$t('dataset.text'),
  104. value: 'text',
  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>