var app = angular.module('multiZab', ['angularMoment', 'chart.js'])

app.config(['$interpolateProvider', function($interpolateProvider) {
  $interpolateProvider.startSymbol('{[');
  $interpolateProvider.endSymbol(']}');
}]);

app.factory('CacheFactory', function($cacheFactory){
    return $cacheFactory('alerts_cache')
})

app.controller('RefreshCacheCtrl', function($scope, $http, $q, $interval, CacheFactory){
    var deferred = $q.defer();
    $http.get('api/graphics')
        .success(function (data, status) {
            deferred.resolve(data);
        }).error(function (data, status) {
            deferred.reject('Error');
        });
    deferred.promise.then(function(result){
        angular.forEach(result.result, function(value, key){
            CacheFactory.put(key, value)
            })
    });
})

app.controller('CountAlertsCtrl', function($scope, $interval, CacheFactory){
    this.loadNotifications = function (){
        $scope.labels = []
        $scope.data = []
        angular.forEach(CacheFactory.get('count_alerts'), function(value, key){
            $scope.labels.push(key)
            $scope.data.push(value)
        })
    }

    $interval(function(){
        this.loadNotifications();
    }.bind(this), 100)

    this.loadNotifications();
})

app.controller('CountPerTypeCtrl', function ($scope, $interval, CacheFactory){
    this.loadNotifications = function (){
        $scope.labels = []
        $scope.data = []
        angular.forEach(CacheFactory.get('count_types'), function(value, key){
            $scope.labels.push(key)
            $scope.data.push(value)
        })
    }

    $interval(function(){
       this.loadNotifications();
    }.bind(this), 100);

    this.loadNotifications();
})

app.controller('CountPerTypesZabbixCtrl', function ($scope, $interval, CacheFactory){
    $scope.init = function(id) {
        $scope.id = id;
    }

    this.loadNotifications = function (){
        $scope.labels = []
        $scope.data = []
        angular.forEach(CacheFactory.get('count_types_per_zabbix')[$scope.id], function(value, key){
            $scope.labels.push(key)
            $scope.data.push(value)
        })
    }

    $interval(function(){
       this.loadNotifications();
    }.bind(this), 100);

    this.loadNotifications();
})
@@ -325,93 +325,140 @@
 app.
-controller('RefreshCacheCtrl', function($scope, $http, $q, $interval, CacheFactory)%7B%0A
+factory('GetFactory', function($http, $q)%7B%0A    var factory = %7B%0A        result : false,%0A        getResult : function(path) %7B%0A        
     
@@ -480,24 +480,32 @@
 $q.defer();%0A
+        
     $http.ge
@@ -510,32 +510,25 @@
 get(
-'api/graphics')%0A
+path)%0A   
         
 .suc
@@ -523,16 +523,21 @@
         
+     
 .success
@@ -579,40 +579,105 @@
     
-deferred.resolve(data);%0A
+        factory.result = data;%0A                    deferred.resolve(factory.result);%0A    
         
 %7D).e
@@ -672,16 +672,20 @@
         
+    
 %7D).error
@@ -715,32 +715,40 @@
 ) %7B%0A            
+        
 deferred.reject(
@@ -769,16 +769,24 @@
     
+ 
+       
 %7D);%0A    
 defe
@@ -785,24 +785,215 @@
     
-deferred.promise
+            return deferred.promise;%0A        %7D%0A    %7D%0A    return factory;%0A%7D)%0A%0Aapp.controller('RefreshCacheCtrl', function($scope, $interval, GetFactory, CacheFactory)%7B%0A    GetFactory.getResult('api/graphics')
 .the
@@ -1012,16 +1012,20 @@
 esult)%7B%0A
+    
         
@@ -1126,28 +1126,379 @@
         
+%7D)%0A
     %7D)%0A
-    %7D
+%7D)%0A%0Aapp.controller('AlertsListCtrl', function ($scope, $interval, GetFactory)%7B%0A    this.loadNotifications = function ()%7B%0A        GetFactory.getResult('api/alerts').then(function(result)%7B%0A            $scope.results = result%0A        %7D)%0A    %7D%0A%0A    $interval(function()%7B%0A        this.loadNotifications();%0A    %7D.bind(this), 5000)%0A%0A    this.loadNotifications(
 );%0A%7D)%0A%0Aa

fix missing controller