diff --git a/app/controllers/transactions.js b/app/controllers/transactions.js
index 5676790..1012815 100644
--- a/app/controllers/transactions.js
+++ b/app/controllers/transactions.js
@@ -52,8 +52,12 @@ var getTransaction = function(txid, cb) {
*/
exports.list = function(req, res, next) {
var bId = req.query.block;
- var aId = req.query.address;
- var limit = req.query.limit || 1000;
+ var addrStr = req.query.address;
+ var page = req.query.pageNum;
+ var pageLength = 20;
+ var pagesTotal = 1;
+ var txLength;
+ var txs;
if (bId) {
Block.fromHashWithInfo(bId, function(err, block) {
@@ -63,14 +67,28 @@ exports.list = function(req, res, next) {
return next();
}
- async.mapSeries(block.info.tx, getTransaction,
+ txLength = block.info.tx.length;
+
+ if (page) {
+ var spliceInit = page * pageLength;
+ txs = block.info.tx.splice(spliceInit, pageLength);
+ pagesTotal = Math.ceil(txLength / pageLength);
+ }
+ else {
+ txs = block.info.tx;
+ }
+
+ async.mapSeries(txs, getTransaction,
function(err, results) {
- res.jsonp(results);
+ res.jsonp({
+ pagesTotal: pagesTotal,
+ txs: results
+ });
});
});
}
- else if (aId) {
- var a = Address.new(aId);
+ else if (addrStr) {
+ var a = Address.new(addrStr);
a.update(function(err) {
if (err && !a.totalReceivedSat) {
@@ -79,23 +97,25 @@ exports.list = function(req, res, next) {
return next();
}
- async.mapSeries(a.transactions, getTransaction,
+ txLength = a.transactions.length;
+
+ if (page) {
+ var spliceInit = page * pageLength;
+ txs = a.transactions.splice(spliceInit, pageLength);
+ pagesTotal = Math.ceil(txLength / pageLength);
+ }
+ else {
+ txs = a.transactions;
+ }
+
+ async.mapSeries(txs, getTransaction,
function(err, results) {
- res.jsonp(results);
+ res.jsonp({
+ pagesTotal: pagesTotal,
+ txs: results
+ });
});
});
}
- else {
- Transaction
- .find()
- .limit(limit)
- .sort('-time')
- .exec(function(err, txs) {
- if (err) {
- res.status(500).send(err);
- } else {
- res.jsonp(txs);
- }
- });
- }
+
};
diff --git a/public/css/common.css b/public/css/common.css
index 685758a..f51137d 100644
--- a/public/css/common.css
+++ b/public/css/common.css
@@ -38,6 +38,7 @@ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
.m20h {margin: 0 20px;}
.m5v {margin: 5px 0;}
.m20v {margin: 20px 0;}
+.m10v {margin: 10px 0;}
.m50v {margin: 50px 0;}
.m10b {margin-bottom: 10px;}
@@ -119,6 +120,7 @@ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
}
.col-gray {
+ width: 267px;
background-color: #F4F4F4;
padding: 15px;
margin-top: 21px;
diff --git a/public/js/controllers/transactions.js b/public/js/controllers/transactions.js
index 28efee2..f657dea 100644
--- a/public/js/controllers/transactions.js
+++ b/public/js/controllers/transactions.js
@@ -3,12 +3,16 @@
angular.module('insight.transactions').controller('transactionsController',
function ($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress, get_socket) {
$scope.global = Global;
+ $scope.loading = false;
+ $scope.loadedBy = null;
+
+ var pageNum = 0;
+ var pagesTotal = 1;
$scope.findThis = function() {
$scope.findTx($routeParams.txId);
};
-
$scope.aggregateItems = function(items) {
var l = items.length;
@@ -16,12 +20,12 @@ angular.module('insight.transactions').controller('transactionsController',
var tmp = {};
var u=0;
// TODO multiple output address
- //
+ //
for(var i=0; i < l; i++) {
var notAddr = false;
- // non standard input
+ // non standard input
if (items[i].scriptSig && !items[i].addr) {
items[i].addr = 'Unparsed address [' + u++ + ']';
items[i].notAddr = true;
@@ -57,7 +61,6 @@ angular.module('insight.transactions').controller('transactionsController',
return (ret);
};
-
$scope.processTX = function(tx) {
tx.vinSimple = $scope.aggregateItems(tx.vin);
tx.voutSimple = $scope.aggregateItems(tx.vout);
@@ -84,27 +87,54 @@ angular.module('insight.transactions').controller('transactionsController',
});
};
- $scope.byBlock = function(bId) {
- TransactionsByBlock.query({
- block: bId
- }, function(txs) {
- angular.forEach(txs, function(tx) {
- $scope.processTX(tx);
- });
- $scope.txs = txs;
+ $scope.byBlock = function() {
+ TransactionsByBlock.get({
+ block: $routeParams.blockHash,
+ pageNum: pageNum
+ }, function(data) {
+ $scope.paginate(data);
});
};
- $scope.byAddress = function(aId) {
- TransactionsByAddress.query({
- address: aId
- }, function(txs) {
- angular.forEach(txs, function(tx) {
- $scope.processTX(tx);
- });
- $scope.txs = txs;
+ $scope.byAddress = function () {
+ TransactionsByAddress.get({
+ address: $routeParams.addrStr,
+ pageNum: pageNum
+ }, function(data) {
+ $scope.paginate(data);
});
};
+
+ $scope.paginate = function (data) {
+ $scope.loading = false;
+
+ pagesTotal = data.pagesTotal;
+ pageNum += 1;
+
+ data.txs.forEach(function(tx) {
+ $scope.processTX(tx);
+ $scope.txs.push(tx);
+ });
+ };
+
+ $scope.load = function(from) {
+ $scope.loadedBy = from;
+ $scope.loadMore();
+ };
+
+ $scope.loadMore = function() {
+ if (pageNum < pagesTotal && !$scope.loading) {
+ $scope.loading = true;
+
+ if ($scope.loadedBy === 'address') {
+ $scope.byAddress();
+ }
+ else {
+ $scope.byBlock();
+ }
+ }
+ };
+
var socket = get_socket($scope);
socket.on('atx', function(tx) {
console.log('atx '+tx.txid);
diff --git a/public/js/directives.js b/public/js/directives.js
index a726efc..d0fe487 100755
--- a/public/js/directives.js
+++ b/public/js/directives.js
@@ -1 +1,25 @@
-'use strict';
\ No newline at end of file
+'use strict';
+
+angular.module('insight.address').directive('whenScrolled', ['$window', function($window) {
+ return {
+ link: function(scope, elm, attr) {
+ var pageHeight, clientHeight, scrollPos;
+ $window = angular.element($window);
+
+ var handler = function() {
+ pageHeight = window.document.documentElement.scrollHeight;
+ clientHeight = window.document.documentElement.clientHeight;
+ scrollPos = window.pageYOffset;
+
+ if (pageHeight - (scrollPos + clientHeight) === 0) {
+ scope.$apply(attr.whenScrolled);
+ }
+ };
+
+ $window.on('scroll', handler);
+ scope.$on('$destroy', function() {
+ return $window.off('scroll', handler);
+ });
+ }
+ };
+}]);
diff --git a/public/views/address.html b/public/views/address.html
index 1e21aec..2736b03 100644
--- a/public/views/address.html
+++ b/public/views/address.html
@@ -1,45 +1,44 @@
-
-
-
-
-
- | Address |
- {{address.addrStr}} |
-
-
- | Total Received |
- {{address.totalReceived}} BTC |
-
-
- | Total Sent |
- {{address.totalSent}} BTC |
-
-
- | Final Balance |
- {{address.balance}} BTC |
-
-
- | No. Transactions |
- {{address.txApperances}} |
-
+
+
-
-
-
-
-
-
+
+
Summary
+
+
+
+ | Total Received |
+ {{address.totalReceived}} BTC |
+
+
+ | Total Sent |
+ {{address.totalSent}} BTC |
+
+
+ | Final Balance |
+ {{address.balance}} BTC |
+
+
+ | No. Transactions |
+ {{address.txApperances}} |
+
+
+
+
+
+
-
-
Transactions Transactions contained within this block
-
-
+
+
+
Transactions Transactions contained within this block
+
+
+
+
diff --git a/public/views/block.html b/public/views/block.html
index d3db901..88cc231 100644
--- a/public/views/block.html
+++ b/public/views/block.html
@@ -8,33 +8,32 @@
Block #{{ block.height }}
-
+
-
+
Summary
@@ -85,9 +84,9 @@
-
+
Transactions Transactions contained within this block
-
+
diff --git a/public/views/footer.html b/public/views/footer.html
index 0540455..24a739e 100644
--- a/public/views/footer.html
+++ b/public/views/footer.html
@@ -1,6 +1,3 @@
-
-
+
-
diff --git a/public/views/transaction/list.html b/public/views/transaction/list.html
index bd9b755..c1262f2 100644
--- a/public/views/transaction/list.html
+++ b/public/views/transaction/list.html
@@ -1,9 +1,9 @@
-
There are not transactions
+