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.

125 lines
2.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <div class="v-data-footer">
  3. <v-edit-dialog
  4. @save="changePage"
  5. large
  6. persistent
  7. >
  8. <span>{{ page }} of {{ total }}</span>
  9. <template v-slot:input>
  10. <div class="mt-4 title">
  11. Move Page
  12. </div>
  13. </template>
  14. <template v-slot:input>
  15. <v-text-field
  16. v-model="newPage"
  17. :rules="rules"
  18. label="Edit"
  19. single-line
  20. counter
  21. autofocus
  22. />
  23. </template>
  24. </v-edit-dialog>
  25. <v-tooltip bottom>
  26. <template v-slot:activator="{ on }">
  27. <v-btn
  28. v-shortkey.once="['arrowleft']"
  29. :disabled="page===1"
  30. v-on="on"
  31. @shortkey="prevPage"
  32. @click="prevPage"
  33. text
  34. fab
  35. small
  36. >
  37. <v-icon>mdi-chevron-left</v-icon>
  38. </v-btn>
  39. </template>
  40. <span></span>
  41. </v-tooltip>
  42. <v-tooltip bottom>
  43. <template v-slot:activator="{ on }">
  44. <v-btn
  45. v-shortkey.once="['arrowright']"
  46. :disabled="page===total"
  47. v-on="on"
  48. @shortkey="nextPage(total)"
  49. @click="nextPage(total)"
  50. text
  51. fab
  52. small
  53. >
  54. <v-icon>mdi-chevron-right</v-icon>
  55. </v-btn>
  56. </template>
  57. <span></span>
  58. </v-tooltip>
  59. </div>
  60. </template>
  61. <script>
  62. import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
  63. export default {
  64. data() {
  65. return {
  66. editedPage: null,
  67. rules: [
  68. value => (value && parseInt(value, 10) > 0 && parseInt(value, 10) <= this.total) || 'Invalid page number!'
  69. ]
  70. }
  71. },
  72. computed: {
  73. ...mapState('documents', ['items', 'total']),
  74. ...mapGetters('pagination', ['current', 'limit', 'offset', 'page']),
  75. newPage: {
  76. get: function () {
  77. return this.page
  78. },
  79. set: function (newValue) {
  80. const value = parseInt(newValue, 10)
  81. this.editedPage = value
  82. }
  83. }
  84. },
  85. watch: {
  86. offset() {
  87. this.updateSearchOptions({
  88. limit: this.limit,
  89. offset: this.offset
  90. })
  91. this.getDocumentList({
  92. projectId: this.$route.params.id
  93. })
  94. },
  95. current() {
  96. this.setCurrent(this.current)
  97. }
  98. },
  99. created() {
  100. this.initPage({
  101. projectId: this.$route.params.id
  102. })
  103. this.getDocumentList({
  104. projectId: this.$route.params.id
  105. })
  106. },
  107. methods: {
  108. ...mapActions('documents', ['getDocumentList']),
  109. ...mapActions('pagination', ['prevPage', 'nextPage', 'initPage', 'movePage']),
  110. ...mapMutations('documents', ['setCurrent', 'updateSearchOptions']),
  111. changePage() {
  112. if (!this.editedPage || this.editedPage < 0 || this.editedPage > this.total) {
  113. return
  114. }
  115. this.movePage(this.editedPage)
  116. }
  117. }
  118. }
  119. </script>