added pagination
This commit is contained in:
parent
af6777d359
commit
04a0bff706
3 changed files with 71 additions and 10 deletions
|
|
@ -11,8 +11,9 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.lastShowed = false;
|
$scope.lastShowed = false;
|
||||||
|
|
||||||
$scope.txpCurrentPage = 1;
|
$scope.currentPage = 1;
|
||||||
$scope.txpItemsPerPage = 4;
|
$scope.itemsPerPage = 10;
|
||||||
|
$scope.nbPages = 0;
|
||||||
$scope.blockchain_txs = [];
|
$scope.blockchain_txs = [];
|
||||||
$scope.alternativeCurrency = [];
|
$scope.alternativeCurrency = [];
|
||||||
|
|
||||||
|
|
@ -24,19 +25,38 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$scope.update();
|
$scope.update();
|
||||||
}, 10);
|
}, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.nextPage = function() {
|
||||||
|
$scope.currentPage++;
|
||||||
|
$scope.update();
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.previousPage = function() {
|
||||||
|
$scope.currentPage--;
|
||||||
|
$scope.update();
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.hasNextPage = function() {
|
||||||
|
return $scope.currentPage < $scope.nbPages;
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.hasPreviousPage = function() {
|
||||||
|
return $scope.currentPage > 1;
|
||||||
|
};
|
||||||
|
|
||||||
$scope.getTransactions = function() {
|
$scope.getTransactions = function() {
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
|
|
||||||
$scope.blockchain_txs = w.cached_txs || [];
|
$scope.blockchain_txs = w.cached_txs || [];
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
w.getTransactionHistory(function(err, res) {
|
w.getTransactionHistory({
|
||||||
|
currentPage: $scope.currentPage,
|
||||||
|
itemsPerPage: $scope.itemsPerPage,
|
||||||
|
}, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
|
@ -45,10 +65,15 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each(res, function(r) {
|
var items = res.items;
|
||||||
|
|
||||||
|
_.each(items, function(r) {
|
||||||
r.ts = r.minedTs || r.sentTs;
|
r.ts = r.minedTs || r.sentTs;
|
||||||
});
|
});
|
||||||
$scope.blockchain_txs = w.cached_txs = res;
|
$scope.blockchain_txs = w.cached_txs = items;
|
||||||
|
$scope.nbPages = res.nbPages;
|
||||||
|
|
||||||
|
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
|
|
|
||||||
|
|
@ -1289,7 +1289,7 @@ Wallet.prototype._getActionList = function(actions) {
|
||||||
var peers = Object.keys(actions).map(function(i) {
|
var peers = Object.keys(actions).map(function(i) {
|
||||||
return {
|
return {
|
||||||
cId: i,
|
cId: i,
|
||||||
actions: actions[i]
|
actions: actions[i]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2836,9 +2836,22 @@ Wallet.request = function(options, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.getTransactionHistory = function(cb) {
|
/**
|
||||||
|
* @desc Return a list of past transactions
|
||||||
|
*
|
||||||
|
* @param {number} opts.currentPage - the desired page in the dataset
|
||||||
|
* @param {number} opts.itemsPerPage - number of items per page
|
||||||
|
* @return {Object} the list of transactions
|
||||||
|
*/
|
||||||
|
Wallet.prototype.getTransactionHistory = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (_.isFunction(opts)) {
|
||||||
|
cb = opts;
|
||||||
|
opts = {};
|
||||||
|
}
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
var addresses = self.getAddressesInfo();
|
var addresses = self.getAddressesInfo();
|
||||||
var proposals = self.getTxProposals();
|
var proposals = self.getTxProposals();
|
||||||
var satToUnit = 1 / self.settings.unitToSatoshi;
|
var satToUnit = 1 / self.settings.unitToSatoshi;
|
||||||
|
|
@ -2948,6 +2961,23 @@ Wallet.prototype.getTransactionHistory = function(cb) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function paginate(list, currentPage, itemsPerPage) {
|
||||||
|
if (list.length == 0) return list;
|
||||||
|
|
||||||
|
var res = {
|
||||||
|
itemsPerPage: itemsPerPage || list.length,
|
||||||
|
currentPage: currentPage || 1,
|
||||||
|
nbItems: list.length,
|
||||||
|
};
|
||||||
|
res.nbPages = res.itemsPerPage != 0 ? Math.ceil(res.nbItems / res.itemsPerPage) : 1;
|
||||||
|
|
||||||
|
var from = (res.currentPage - 1) * res.itemsPerPage;
|
||||||
|
var to = Math.min(from + res.itemsPerPage, res.nbItems);
|
||||||
|
res.items = list.slice(from, to);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
if (addresses.length > 0) {
|
if (addresses.length > 0) {
|
||||||
var addressesStr = _.pluck(addresses, 'addressStr');
|
var addressesStr = _.pluck(addresses, 'addressStr');
|
||||||
self.blockchain.getTransactions(addressesStr, function(err, txs) {
|
self.blockchain.getTransactions(addressesStr, function(err, txs) {
|
||||||
|
|
@ -2957,7 +2987,11 @@ Wallet.prototype.getTransactionHistory = function(cb) {
|
||||||
decorateTx(tx);
|
decorateTx(tx);
|
||||||
return tx;
|
return tx;
|
||||||
});
|
});
|
||||||
return cb(null, history);
|
history.sort(function(a, b) {
|
||||||
|
return (b.sentTs || b.minedTs) - (a.sentTs || a.minedTs);
|
||||||
|
});
|
||||||
|
|
||||||
|
return cb(null, paginate(history, opts.currentPage, opts.itemsPerPage));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button ng-click="previousPage()" ng-disabled="!hasPreviousPage()">prev</button>
|
||||||
|
<button ng-click="nextPage()" ng-disabled="!hasNextPage()">next</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue