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-23 08:00:27 -08:00
|
|
|
function($scope, $routeParams, $location, Global, Status, Sync, getSocket) {
|
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-23 08:00:27 -08:00
|
|
|
$scope.loaded = 1;
|
2014-01-20 06:45:01 -08:00
|
|
|
angular.extend($scope, d);
|
2014-01-21 08:28:01 -08:00
|
|
|
},
|
|
|
|
function(e) {
|
2014-01-23 10:10:52 -08:00
|
|
|
$scope.error = 'API ERROR: ' + e.data;
|
2014-01-16 05:54:21 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-23 09:39:09 -08:00
|
|
|
var _onSyncUpdate = function(sync) {
|
2014-01-21 08:28:01 -08:00
|
|
|
$scope.sync = sync;
|
|
|
|
};
|
|
|
|
|
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-23 09:39:09 -08:00
|
|
|
_onSyncUpdate(sync);
|
2014-01-21 08:28:01 -08:00
|
|
|
},
|
|
|
|
function(e) {
|
2014-01-23 08:00:27 -08:00
|
|
|
var err = 'Could not get sync information' + e.toString();
|
|
|
|
$scope.sync = { error: err };
|
2014-01-20 06:45:01 -08:00
|
|
|
});
|
|
|
|
};
|
2014-01-21 06:51:34 -08:00
|
|
|
|
2014-01-23 10:01:09 -08:00
|
|
|
var socket = getSocket($scope);
|
2014-01-21 06:51:34 -08:00
|
|
|
socket.emit('subscribe', 'sync');
|
2014-01-21 08:28:01 -08:00
|
|
|
socket.on('status', function(sync) {
|
2014-01-23 09:39:09 -08:00
|
|
|
_onSyncUpdate(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
|
|
|
|