From 322b8e2ce5beb313306a2f9220cc426979e846d2 Mon Sep 17 00:00:00 2001 From: Michal Tuleja Date: Tue, 11 Dec 2018 16:21:04 +0100 Subject: [PATCH 1/5] Add URL-based pagination to transaction page --- .../transactions/transactions.component.js | 24 +++++++++++-------- .../transactions-list/transactions-list.html | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/transactions/transactions.component.js b/src/components/transactions/transactions.component.js index 0b90bcd7a..2cd6de4bb 100644 --- a/src/components/transactions/transactions.component.js +++ b/src/components/transactions/transactions.component.js @@ -16,15 +16,12 @@ import AppTransactions from './transactions.module'; import template from './transactions.html'; -const TransactionsConstructor = function ($rootScope, $stateParams, $location, $http, $interval) { +const TransactionsConstructor = function ($rootScope, $stateParams, $state, $http, $interval) { const vm = this; vm.getLastTransactions = (n) => { const limit = 20 + 1; let offset = 0; - - if (n) { - offset = (n - 1) * limit; - } + if (n) offset = (n - 1) * limit; $http.get(`/api/getTransactions?limit=${limit}&offset=${offset}`).then((resp) => { if (resp.data.success) { @@ -33,18 +30,25 @@ const TransactionsConstructor = function ($rootScope, $stateParams, $location, $ vm.txs = { results: resp.data.transactions }; vm.txs.hasPrev = !!offset; vm.txs.hasNext = !!removedTx; + vm.txs.page = $stateParams.page || 0; + vm.txs.loadPageOffset = vm.loadPageOffset; + vm.txs.loadPage = vm.loadPage; } else { vm.txs = {}; } }); }; + vm.loadPageOffset = (offset) => { + $state.go($state.current.component, { page: Number(vm.txs.page || 1) + offset }); + }; + + vm.loadPage = (pageNumber) => { + $state.go($state.current.component, { page: Number(vm.txs.page || 1) + pageNumber }); + }; + const update = () => { - if ($stateParams.page) { - vm.getLastTransactions($stateParams.page); - } else { - vm.getLastTransactions(); - } + vm.getLastTransactions($stateParams.page || 1); }; update(); diff --git a/src/shared/transactions-list/transactions-list.html b/src/shared/transactions-list/transactions-list.html index 1fa7a2aac..9dd070696 100644 --- a/src/shared/transactions-list/transactions-list.html +++ b/src/shared/transactions-list/transactions-list.html @@ -62,13 +62,13 @@

No transactions