insight-ui-zcash/public/js/controllers/index.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-01-06 12:34:25 -08:00
'use strict';
2014-01-14 14:42:38 -08:00
var TRANSACTION_DISPLAYED = 5;
var BLOCKS_DISPLAYED = 5;
angular.module('insight.system').controller('IndexController', ['$scope', '$rootScope', 'Global', 'socket', 'Blocks', 'Transactions', function($scope, $rootScope, Global, socket, Blocks, Transactions) {
2014-01-06 13:01:23 -08:00
$scope.global = Global;
2014-01-15 07:44:17 -08:00
//show errors
$scope.flashMessage = $rootScope.flashMessage || null;
2014-01-15 07:44:17 -08:00
socket.on('tx', function(tx) {
2014-01-15 04:38:27 -08:00
console.log('Transaction received! ' + JSON.stringify(tx));
2014-01-14 14:42:38 -08:00
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
$scope.txs.pop();
}
$scope.txs.unshift(tx);
});
2014-01-15 07:44:17 -08:00
socket.on('block', function(block) {
2014-01-15 04:38:27 -08:00
console.log('Block received! ' + JSON.stringify(block));
2014-01-14 14:42:38 -08:00
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
$scope.blocks.pop();
}
$scope.blocks.unshift(block);
2014-01-13 13:13:41 -08:00
});
$scope.human_since = function(time) {
var m = moment.unix(time);
return m.max().fromNow();
2014-01-15 11:05:26 -08:00
};
2014-01-15 07:44:17 -08:00
$scope.index = function() {
Blocks.get({
limit: BLOCKS_DISPLAYED
}, function(res) {
$scope.blocks = res.blocks;
});
Transactions.query({
limit: TRANSACTION_DISPLAYED
}, function(txs) {
$scope.txs = txs;
});
};
$scope.txs = [];
2014-01-14 14:42:38 -08:00
$scope.blocks = [];
}]);