refactoring is working

This commit is contained in:
Moriz Wahl 2021-09-14 17:28:40 +02:00
parent 7ede572f4b
commit 4f5ca22363
3 changed files with 50 additions and 78 deletions

View File

@ -1,8 +1,8 @@
<template> <template>
<div class="pagination-buttons"> <div class="pagination-buttons" v-if="totalRows > perPage">
<b-row class="m-4"> <b-row class="m-4">
<b-col class="text-right"> <b-col class="text-right">
<b-button class="previous-page" :disabled="!hasPrevious" @click="$emit('show-previous')"> <b-button class="previous-page" :disabled="!hasPrevious" @click="currentValue--">
<b-icon icon="chevron-left" variant="primary"></b-icon> <b-icon icon="chevron-left" variant="primary"></b-icon>
</b-button> </b-button>
</b-col> </b-col>
@ -10,7 +10,7 @@
<p class="text-center pt-2">{{ value }} / {{ totalPages }}</p> <p class="text-center pt-2">{{ value }} / {{ totalPages }}</p>
</b-col> </b-col>
<b-col> <b-col>
<b-button class="next-page" :disabled="!hasNext" @click="$emit('show-next')"> <b-button class="next-page" :disabled="!hasNext" @click="currentValue++">
<b-icon icon="chevron-right" variant="primary"></b-icon> <b-icon icon="chevron-right" variant="primary"></b-icon>
</b-button> </b-button>
</b-col> </b-col>
@ -18,35 +18,36 @@
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'PaginationButtons', name: 'PaginationButtons',
props: { props: {
totalRows: { type: Number, required: true }, totalRows: { type: Number, required: true },
pageSize: { type: Number, required: true }, perPage: { type: Number, required: true },
value: { type: Number, , required: true }, value: { type: Number, required: true },
},
data() {
return {
currentValue: { type: Number, default: 1 },
}
}, },
computed: { computed: {
hasNext() { hasNext() {
return this.value * this.pageSize < this.totalCount return this.value * this.perPage < this.totalRows
}, },
hasPrevious() { hasPrevious() {
return this.value > 1 return this.value > 1
}, },
totalPages() { totalPages() {
return Math.ceil(this.totalCount / this.pageSize) return Math.ceil(this.totalRows / this.perPage)
}, },
}, },
methods: { created() {
showNext() { this.currentValue = this.value
this.value++
this.updateGdt()
window.scrollTo(0, 0)
}, },
showPrevious() { watch: {
this.value-- currentValue() {
this.updateGdt() if (this.currentValue !== this.value) this.$emit('input', this.currentValue)
window.scrollTo(0, 0)
}, },
}, },
} }
</script> </script>

View File

@ -84,13 +84,9 @@
</div> </div>
</div> </div>
<pagination-buttons <pagination-buttons
v-if="showPagination && transactionCount > pageSize" v-model="currentPage"
:has-next="hasNext" :per-page="pageSize"
:has-previous="hasPrevious" :total-rows="transactionCount"
:total-pages="totalPages"
:current-page="currentPage"
@show-next="showNext"
@show-previous="showPrevious"
></pagination-buttons> ></pagination-buttons>
<div v-if="transactions.length === 0" class="mt-4 text-center"> <div v-if="transactions.length === 0" class="mt-4 text-center">
<span>{{ $t('transaction.nullTransactions') }}</span> <span>{{ $t('transaction.nullTransactions') }}</span>
@ -128,23 +124,6 @@ export default {
transactionCount: { type: Number, default: 0 }, transactionCount: { type: Number, default: 0 },
showPagination: { type: Boolean, default: false }, showPagination: { type: Boolean, default: false },
}, },
watch: {
timestamp: {
immediate: true,
handler: 'updateTransactions',
},
},
computed: {
hasNext() {
return this.currentPage * this.pageSize < this.transactionCount
},
hasPrevious() {
return this.currentPage > 1
},
totalPages() {
return Math.ceil(this.transactionCount / this.pageSize)
},
},
methods: { methods: {
updateTransactions() { updateTransactions() {
this.$emit('update-transactions', { this.$emit('update-transactions', {
@ -165,15 +144,14 @@ export default {
throwError(msg) { throwError(msg) {
throw new Error(msg) throw new Error(msg)
}, },
showNext() {
this.currentPage++
this.updateTransactions()
window.scrollTo(0, 0)
}, },
showPrevious() { watch: {
this.currentPage-- currentPage() {
this.updateTransactions() this.updateTransactions()
window.scrollTo(0, 0) },
timestamp: {
immediate: true,
handler: 'updateTransactions',
}, },
}, },
} }

View File

@ -28,12 +28,9 @@
</div> </div>
</div> </div>
<pagination-buttons <pagination-buttons
v-if="transactionGdtCount > pageSize"
v-model="currentPage" v-model="currentPage"
:per-page="pageSize" :per-page="pageSize"
:total-rows="transactionGdtCount" :total-rows="transactionGdtCount"
@show-next="showNext"
@show-previous="showPrevious"
></pagination-buttons> ></pagination-buttons>
</div> </div>
</template> </template>
@ -73,25 +70,21 @@ export default {
} = result } = result
this.transactionsGdt = listGDTEntries.gdtEntries this.transactionsGdt = listGDTEntries.gdtEntries
this.transactionGdtCount = listGDTEntries.count this.transactionGdtCount = listGDTEntries.count
window.scrollTo(0, 0)
}) })
.catch((error) => { .catch((error) => {
this.$toasted.error(error.message) this.$toasted.error(error.message)
}) })
}, },
showNext() {
this.currentPage++
this.updateGdt()
window.scrollTo(0, 0)
},
showPrevious() {
this.currentPage--
this.updateGdt()
window.scrollTo(0, 0)
},
}, },
mounted() { mounted() {
this.updateGdt() this.updateGdt()
}, },
watch: {
currentPage() {
this.updateGdt()
},
},
} }
</script> </script>
<style> <style>