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.

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