flosight-api/public/js/controllers/index.js
2014-01-15 09:38:27 -03:00

30 lines
761 B
JavaScript
Executable File

'use strict';
var TRANSACTION_DISPLAYED = 5;
var BLOCKS_DISPLAYED = 5;
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', function($scope, Global, socket) {
$scope.global = Global;
socket.on('tx', function(data) {
var tx = data;
console.log('Transaction received! ' + JSON.stringify(tx));
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
$scope.txs.pop();
}
$scope.txs.unshift(tx);
});
socket.on('block', function(data) {
var block = data;
console.log('Block received! ' + JSON.stringify(block));
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
$scope.blocks.pop();
}
$scope.blocks.unshift(block);
});
$scope.txs = [];
$scope.blocks = [];
}]);