- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
function EngineListCtrl($scope, $timeout, $http)
{
$scope.engines = {};
$scope.workers = [];
$scope.checkEngines = function(){
$http.get(engineUrl + '&type=json&jcmd=getClients').success(function(req){
var engines = {};
var workers = {};
$scope.workers = []; // Это в отрисовке не используется.
// Сначала распихиваю всех по местам
angular.forEach(req, function(ob, i){
if( ob.info.type == 'engine' )
engines[ob.info.engine] = ob;
if( ob.info.type == 'worker' ){
if( workers[ob.info.engine] == undefined )
workers[ob.info.engine] = {};
workers[ob.info.engine][ob.info.worker] = ob;
if( ob.task && ob.task.state )
ob.info.state = ob.task.state;
$scope.workers.push(ob);
}
});
// Перебераю уже имеющиеся объекты
angular.forEach($scope.engines, function(engineOb, engineName){
var needRemove = true;
angular.forEach(engines, function(val, key){
if( engineName == key ){
angular.extend($scope.engines[engineName], val);
needRemove = false;
}
});
if( needRemove == false && $scope.engines[engineName] ){
$scope.checkEngineEvents($scope.engines[engineName]);
if( workers[engineName] != undefined ){
if( $scope.engines[engineName].workers == undefined )
$scope.engines[engineName].workers = {};
angular.extend($scope.engines[engineName].workers, workers[engineName]);
}else
$scope.engines[engineName].workers = {};
}
if( needRemove == true ){
delete $scope.engines[engineName];
}
});
// А теперь новые добавляю
angular.forEach(engines, function(engineOb, engineName){
if( $scope.engines[engineName] == undefined ){
$scope.engines[engineName] = engineOb;
if( workers[engineName] != undefined ){
if( $scope.engines[engineName].workers == undefined )
$scope.engines[engineName].workers = {};
angular.extend($scope.engines[engineName].workers, workers[engineName]);
}
$scope.checkEngineEvents($scope.engines[engineName]);
}
});
$timeout($scope.checkEngines, 2000);
});
}
$timeout($scope.checkEngines, 1000);