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.

148 lines
3.8 KiB

2 years ago
3 years ago
2 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 #[`item.createdAt`]="{ item }">
  23. <span>{{
  24. item.createdAt | dateParse('YYYY-MM-DDTHH:mm:ss') | dateFormat('DD/MM/YYYY HH:mm')
  25. }}</span>
  26. </template>
  27. <template #top>
  28. <v-text-field
  29. v-model="search"
  30. :prepend-inner-icon="mdiMagnify"
  31. :label="$t('generic.search')"
  32. single-line
  33. hide-details
  34. filled
  35. />
  36. </template>
  37. <!--
  38. Tempolary removing due to the performance
  39. <template #[`item.action`]="{ item }">
  40. <v-btn
  41. small
  42. color="primary text-capitalize"
  43. @click="toLabeling(item)"
  44. >
  45. {{ $t('dataset.annotate') }}
  46. </v-btn>
  47. </template> -->
  48. </v-data-table>
  49. </template>
  50. <script lang="ts">
  51. import { mdiMagnify } from '@mdi/js'
  52. import VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  53. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  54. import type { PropType } from 'vue'
  55. import Vue from 'vue'
  56. import { DataOptions } from 'vuetify/types'
  57. import { CommentItem } from '~/domain/models/comment/comment'
  58. Vue.use(VueFilterDateFormat)
  59. Vue.use(VueFilterDateParse)
  60. export default Vue.extend({
  61. props: {
  62. isLoading: {
  63. type: Boolean,
  64. default: false,
  65. required: true
  66. },
  67. items: {
  68. type: Array as PropType<CommentItem[]>,
  69. default: () => [],
  70. required: true
  71. },
  72. value: {
  73. type: Array as PropType<CommentItem[]>,
  74. default: () => [],
  75. required: true
  76. },
  77. total: {
  78. type: Number,
  79. default: 0,
  80. required: true
  81. }
  82. },
  83. data() {
  84. return {
  85. search: '',
  86. options: {} as DataOptions,
  87. headers: [
  88. { text: this.$t('dataset.text'), value: 'text', sortable: false },
  89. { text: this.$t('user.username'), value: 'username', sortable: false },
  90. { text: this.$t('comments.created_at'), value: 'createdAt', sortable: false },
  91. { text: this.$t('dataset.action'), value: 'action', sortable: false },
  92. { text: this.$t('comments.document'), value: 'example' }
  93. ],
  94. mdiMagnify
  95. }
  96. },
  97. watch: {
  98. options: {
  99. handler() {
  100. this.updateQuery({
  101. query: {
  102. limit: this.options.itemsPerPage.toString(),
  103. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  104. q: this.search
  105. }
  106. })
  107. },
  108. deep: true
  109. },
  110. search() {
  111. this.updateQuery({
  112. query: {
  113. limit: this.options.itemsPerPage.toString(),
  114. offset: '0',
  115. q: this.search
  116. }
  117. })
  118. this.options.page = 1
  119. }
  120. },
  121. methods: {
  122. updateQuery(payload: any) {
  123. const { sortBy, sortDesc } = this.options
  124. if (sortBy.length === 1 && sortDesc.length === 1) {
  125. payload.query.sortBy = sortBy[0]
  126. payload.query.sortDesc = sortDesc[0]
  127. } else {
  128. payload.query.sortBy = 'createdAt'
  129. payload.query.sortDesc = true
  130. }
  131. this.$emit('update:query', payload)
  132. }
  133. }
  134. // methods: {
  135. // toLabeling(item: CommentReadDTO) {
  136. // const index = this.examples.findIndex((example: ExampleDTO) => example.id === item.example)
  137. // const page = (index + 1).toString()
  138. // this.$emit('click:labeling', { page, q: this.search })
  139. // }
  140. // }
  141. })
  142. </script>