2014-01-16 05:54:21 -08:00
|
|
|
'use strict';
|
|
|
|
|
2014-01-20 13:09:18 -08:00
|
|
|
angular.module('insight.status').controller('StatusController',
|
2014-01-21 08:28:01 -08:00
|
|
|
function($scope, $routeParams, $location, $rootScope, Global, Status, Sync, get_socket) {
|
2014-01-16 05:54:21 -08:00
|
|
|
$scope.global = Global;
|
2014-01-17 06:46:12 -08:00
|
|
|
|
2014-01-20 06:45:01 -08:00
|
|
|
$scope.getStatus = function(q) {
|
2014-01-16 05:54:21 -08:00
|
|
|
Status.get({
|
2014-01-21 08:28:01 -08:00
|
|
|
q: 'get' + q
|
|
|
|
},
|
|
|
|
function(d) {
|
2014-01-20 11:40:20 -08:00
|
|
|
$rootScope.infoError = null;
|
2014-01-20 06:45:01 -08:00
|
|
|
angular.extend($scope, d);
|
2014-01-21 08:28:01 -08:00
|
|
|
},
|
|
|
|
function(e) {
|
2014-01-20 11:40:20 -08:00
|
|
|
if (e.status === 503) {
|
|
|
|
$rootScope.infoError = 'Backend Error. ' + e.data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootScope.infoError = 'Unknown error:' + e.data;
|
|
|
|
}
|
2014-01-16 05:54:21 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-21 08:28:01 -08:00
|
|
|
var on_sync_update = function(sync) {
|
2014-01-21 11:43:05 -08:00
|
|
|
|
|
|
|
if (sync.error) {
|
2014-01-21 12:46:42 -08:00
|
|
|
$scope.syncError = sync.error;
|
2014-01-21 11:43:05 -08:00
|
|
|
}
|
2014-01-21 12:46:42 -08:00
|
|
|
else {
|
|
|
|
if (sync.blocksToSync > sync.syncedBlocks) {
|
|
|
|
var p = parseInt(100*(sync.syncedBlocks) / sync.blocksToSync);
|
|
|
|
var delta = sync.blocksToSync - sync.syncedBlocks;
|
|
|
|
sync.message = 'Sync ' + p + '% ['+delta+' blocks remaining]';
|
|
|
|
sync.style = 'warn';
|
|
|
|
} else {
|
|
|
|
sync.message = 'On sync';
|
|
|
|
sync.style = 'success';
|
|
|
|
}
|
|
|
|
sync.tooltip = 'Synced blocks: '+sync.syncedBlocks;
|
2014-01-21 08:28:01 -08:00
|
|
|
}
|
|
|
|
$scope.sync = sync;
|
2014-01-21 12:46:42 -08:00
|
|
|
$scope.hola = 'hola';
|
|
|
|
console.log('[status.js.43:hola:]'); //TODO
|
2014-01-21 08:28:01 -08:00
|
|
|
};
|
|
|
|
|
2014-01-20 06:45:01 -08:00
|
|
|
$scope.getSync = function() {
|
2014-01-21 08:28:01 -08:00
|
|
|
Sync.get({},
|
|
|
|
function(sync) {
|
2014-01-21 12:46:42 -08:00
|
|
|
$scope.syncError = null;
|
2014-01-21 08:28:01 -08:00
|
|
|
on_sync_update(sync);
|
|
|
|
},
|
|
|
|
function(e) {
|
2014-01-21 12:46:42 -08:00
|
|
|
$scope.syncError = 'Could not get sync information' + e;
|
2014-01-20 06:45:01 -08:00
|
|
|
});
|
|
|
|
};
|
2014-01-21 06:51:34 -08:00
|
|
|
|
|
|
|
var socket = get_socket($scope);
|
|
|
|
socket.emit('subscribe', 'sync');
|
2014-01-21 08:28:01 -08:00
|
|
|
socket.on('status', function(sync) {
|
|
|
|
on_sync_update(sync);
|
2014-01-21 06:51:34 -08:00
|
|
|
});
|
|
|
|
|
2014-01-20 13:09:18 -08:00
|
|
|
});
|
2014-01-16 05:54:21 -08:00
|
|
|
|