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.

93 lines
2.1 KiB

  1. <template>
  2. <v-data-table
  3. :value="selected"
  4. :headers="headers"
  5. :items="items"
  6. item-key="id"
  7. :options.sync="options"
  8. :server-items-length="total"
  9. :search="search"
  10. :loading="loading"
  11. :footer-props="{
  12. 'items-per-page-options': [10, 50, 100]
  13. }"
  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. </v-data-table>
  43. </template>
  44. <script>
  45. import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
  46. export default {
  47. data() {
  48. return {
  49. search: '',
  50. options: {}
  51. }
  52. },
  53. computed: {
  54. ...mapState('documents', ['items', 'selected', 'loading', 'total']),
  55. ...mapGetters('documents', ['headers'])
  56. },
  57. watch: {
  58. options: {
  59. handler() {
  60. this.getDocumentList({
  61. projectId: this.$route.params.id,
  62. limit: this.options.itemsPerPage,
  63. offset: (this.options.page - 1) * this.options.itemsPerPage
  64. })
  65. },
  66. deep: true
  67. }
  68. },
  69. created() {
  70. this.getDocumentList({
  71. projectId: this.$route.params.id
  72. })
  73. },
  74. methods: {
  75. ...mapActions('documents', ['getDocumentList', 'updateDocument']),
  76. ...mapMutations('documents', ['updateSelected']),
  77. handleUpdateDocument(payload) {
  78. const data = {
  79. projectId: this.$route.params.id,
  80. ...payload
  81. }
  82. this.updateDocument(data)
  83. }
  84. }
  85. }
  86. </script>