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.

168 lines
4.1 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 class="me-1" small color="primary text-capitalize" @click="$emit('edit', item)"
  49. >Edit</v-btn
  50. >
  51. <v-btn small color="primary text-capitalize" @click="toLabeling(item)">
  52. {{ $t('dataset.annotate') }}
  53. </v-btn>
  54. </template>
  55. </v-data-table>
  56. </template>
  57. <script lang="ts">
  58. import { mdiMagnify } from '@mdi/js'
  59. import type { PropType } from 'vue'
  60. import Vue 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. mdiMagnify
  91. }
  92. },
  93. computed: {
  94. headers() {
  95. return [
  96. {
  97. text: 'ID',
  98. value: 'id',
  99. sortable: false
  100. },
  101. {
  102. text: 'Status',
  103. value: 'isConfirmed',
  104. sortable: false
  105. },
  106. {
  107. text: this.$t('dataset.text'),
  108. value: 'text',
  109. sortable: false
  110. },
  111. {
  112. text: this.$t('dataset.metadata'),
  113. value: 'meta',
  114. sortable: false
  115. },
  116. {
  117. text: this.$t('comments.comments'),
  118. value: 'commentCount',
  119. sortable: false
  120. },
  121. {
  122. text: this.$t('dataset.action'),
  123. value: 'action',
  124. sortable: false
  125. }
  126. ]
  127. }
  128. },
  129. watch: {
  130. options: {
  131. handler() {
  132. this.$emit('update:query', {
  133. query: {
  134. limit: this.options.itemsPerPage.toString(),
  135. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  136. q: this.search
  137. }
  138. })
  139. },
  140. deep: true
  141. },
  142. search() {
  143. this.$emit('update:query', {
  144. query: {
  145. limit: this.options.itemsPerPage.toString(),
  146. offset: '0',
  147. q: this.search
  148. }
  149. })
  150. this.options.page = 1
  151. }
  152. },
  153. methods: {
  154. toLabeling(item: ExampleDTO) {
  155. const index = this.items.indexOf(item)
  156. const offset = (this.options.page - 1) * this.options.itemsPerPage
  157. const page = (offset + index + 1).toString()
  158. this.$emit('click:labeling', { page, q: this.search })
  159. }
  160. }
  161. })
  162. </script>