flosight-api/public/js/controllers/status.js
Manuel Araoz 21f03749c8 Merge branch 'master' of github.com:bitpay/insight into feature/realtime-sync-info
Conflicts:
	public/js/controllers/footer.js
	public/views/header.html
2014-01-21 11:57:53 -03:00

51 lines
1.2 KiB
JavaScript

'use strict';
angular.module('insight.status').controller('StatusController',
function ($scope, $routeParams, $location, $rootScope, Global, Status, Sync, get_socket) {
$scope.global = Global;
$scope.getStatus = function(q) {
Status.get({
q: 'get' + q
}, function(d) {
$rootScope.infoError = null;
angular.extend($scope, d);
}, function(e) {
if (e.status === 503) {
$rootScope.infoError = 'Backend Error. ' + e.data;
}
else {
$rootScope.infoError = 'Unknown error:' + e.data;
}
});
};
$scope.getSync = function() {
Sync.get({}, function(sync) {
$rootScope.syncError = null;
if (sync.blocksToSync > sync.syncedBlocks ) {
sync.message = 'Blocks to sync: ' + (sync.blocksToSync - sync.syncedBlocks);
sync.tooltip = 'Skipped blocks:' + sync.skipped_blocks;
}
else {
sync.message = 'On sync';
sync.tooltip = '';
}
$scope.sync = sync;
}, function(e) {
$rootScope.syncError = 'Could not get sync information' + e;
});
};
var socket = get_socket($scope);
socket.emit('subscribe', 'sync');
socket.on('status', function(info) {
console.log('info '+JSON.stringify(info));
});
});