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.

152 lines
3.6 KiB

  1. <template>
  2. <v-data-table
  3. :value="selected"
  4. :headers="headers"
  5. :items="items"
  6. :options.sync="options"
  7. :server-items-length="total"
  8. :search="search"
  9. :loading="loading"
  10. :no-data-text="$t('vuetify.noDataAvailable')"
  11. :footer-props="{
  12. 'showFirstLastPage': true,
  13. 'items-per-page-options': [10, 50, 100],
  14. 'items-per-page-text': $t('vuetify.itemsPerPageText')
  15. }"
  16. item-key="id"
  17. :loading-text="$t('generic.loading')"
  18. show-select
  19. @input="updateSelected"
  20. >
  21. <template v-slot:top>
  22. <v-text-field
  23. v-model="search"
  24. prepend-inner-icon="search"
  25. :label="$t('generic.search')"
  26. single-line
  27. hide-details
  28. filled
  29. />
  30. </template>
  31. <template v-slot:item.text="{ item }">
  32. <v-edit-dialog>
  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 v-slot:input>
  36. <v-textarea
  37. :value="item.text"
  38. :label="$t('generic.edit')"
  39. autofocus
  40. @change="handleUpdateDocument({ id: item.id, text: $event })"
  41. />
  42. </template>
  43. </v-edit-dialog>
  44. </template>
  45. <template v-slot:item.action="{ item }">
  46. <v-btn
  47. small
  48. color="primary text-capitalize"
  49. @click="toLabeling(item)"
  50. >
  51. {{ $t('dataset.annotate') }}
  52. </v-btn>
  53. </template>
  54. </v-data-table>
  55. </template>
  56. <script>
  57. import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
  58. export default {
  59. async fetch() {
  60. await this.getDocumentList({
  61. projectId: this.$route.params.id,
  62. ...this.$route.query
  63. })
  64. },
  65. data() {
  66. return {
  67. search: this.$route.query.q,
  68. options: {},
  69. headers: [
  70. {
  71. text: this.$t('dataset.text'),
  72. align: 'left',
  73. value: 'text',
  74. sortable: false
  75. },
  76. {
  77. text: this.$t('dataset.metadata'),
  78. align: 'left',
  79. value: 'meta',
  80. sortable: false
  81. },
  82. {
  83. text: this.$t('dataset.action'),
  84. align: 'left',
  85. value: 'action',
  86. sortable: false
  87. }
  88. ]
  89. }
  90. },
  91. computed: {
  92. ...mapState('documents', ['items', 'selected', 'loading', 'total']),
  93. ...mapGetters('projects', ['getLink'])
  94. },
  95. watch: {
  96. '$route.query': '$fetch',
  97. options: {
  98. handler(newvalue, oldvalue) {
  99. this.$router.push({
  100. query: {
  101. limit: this.options.itemsPerPage,
  102. offset: (this.options.page - 1) * this.options.itemsPerPage,
  103. q: this.search
  104. }
  105. })
  106. },
  107. deep: true
  108. },
  109. search() {
  110. this.$router.push({
  111. query: {
  112. limit: this.options.itemsPerPage,
  113. offset: 0,
  114. q: this.search
  115. }
  116. })
  117. this.options.page = 1
  118. }
  119. },
  120. methods: {
  121. ...mapActions('documents', ['getDocumentList', 'updateDocument']),
  122. ...mapMutations('documents', ['updateSelected']),
  123. handleUpdateDocument(payload) {
  124. const data = {
  125. projectId: this.$route.params.id,
  126. ...payload
  127. }
  128. this.updateDocument(data)
  129. },
  130. toLabeling(doc) {
  131. const index = this.items.findIndex(item => item.id === doc.id)
  132. const offset = (this.options.page - 1) * this.options.itemsPerPage
  133. const page = offset + index + 1
  134. this.$router.push({
  135. path: this.localePath(`/projects/${this.$route.params.id}/${this.getLink}`),
  136. query: {
  137. page,
  138. q: this.search
  139. }
  140. })
  141. }
  142. }
  143. }
  144. </script>