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.

146 lines
3.5 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. @input="updateSelected"
  14. item-key="id"
  15. loading-text="Loading... Please wait"
  16. show-select
  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. @change="handleUpdateDocument({ id: item.id, text: $event })"
  36. label="Edit"
  37. autofocus
  38. />
  39. </template>
  40. </v-edit-dialog>
  41. </template>
  42. <template v-slot:item.action="{ item }">
  43. <v-btn
  44. @click="goToAnnotationPage(item)"
  45. small
  46. color="primary text-capitalize"
  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. data() {
  57. return {
  58. search: '',
  59. options: {},
  60. headers: [
  61. {
  62. text: 'Text',
  63. align: 'left',
  64. value: 'text',
  65. sortable: false
  66. },
  67. {
  68. text: 'Metadata',
  69. align: 'left',
  70. value: 'meta',
  71. sortable: false
  72. },
  73. {
  74. text: 'Action',
  75. align: 'left',
  76. value: 'action',
  77. sortable: false
  78. }
  79. ]
  80. }
  81. },
  82. computed: {
  83. ...mapState('documents', ['items', 'selected', 'loading', 'total']),
  84. ...mapGetters('projects', ['getLink'])
  85. },
  86. watch: {
  87. options: {
  88. handler() {
  89. this.updateSearchOptions({
  90. limit: this.options.itemsPerPage,
  91. offset: (this.options.page - 1) * this.options.itemsPerPage
  92. })
  93. this.getDocumentList({
  94. projectId: this.$route.params.id
  95. })
  96. },
  97. deep: true
  98. },
  99. search() {
  100. this.updateSearchOptions({
  101. q: this.search
  102. })
  103. this.getDocumentList({
  104. projectId: this.$route.params.id
  105. })
  106. }
  107. },
  108. created() {
  109. this.initSearchOptions()
  110. this.getDocumentList({
  111. projectId: this.$route.params.id
  112. })
  113. },
  114. methods: {
  115. ...mapActions('documents', ['getDocumentList', 'updateDocument']),
  116. ...mapMutations('documents', ['updateSelected', 'updateSearchOptions', 'setCurrent', 'initSearchOptions']),
  117. handleUpdateDocument(payload) {
  118. const data = {
  119. projectId: this.$route.params.id,
  120. ...payload
  121. }
  122. this.updateDocument(data)
  123. },
  124. goToAnnotationPage(doc) {
  125. const index = this.items.findIndex(item => item.id === doc.id)
  126. const limit = this.options.itemsPerPage
  127. const offset = (this.options.page - 1) * limit
  128. const q = this.search
  129. this.updateSearchOptions({ limit, offset, q })
  130. this.$router.push('/projects/' + this.$route.params.id + '/' + this.getLink)
  131. this.setCurrent(index)
  132. const checkpoint = {}
  133. checkpoint[this.$route.params.id] = index + 1
  134. localStorage.setItem('checkpoint', JSON.stringify(checkpoint))
  135. }
  136. }
  137. }
  138. </script>