Procházet zdrojové kódy

Merge pull request #447 from rashidkpc/singleAlerts

Duplicate alerts should not stack up
Rashid Khan před 12 roky
rodič
revize
cd919a3e46
1 změnil soubory, kde provedl 15 přidání a 5 odebrání
  1. 15 5
      js/services.js

+ 15 - 5
js/services.js

@@ -11,11 +11,21 @@ angular.module('kibana.services', [])
   this.list = [];
 
   this.set = function(title,text,severity,timeout) {
-    var _a = {
-      title: title || '',
-      text: text || '',
-      severity: severity || 'info',
-    };
+    var
+      _a = {
+        title: title || '',
+        text: text || '',
+        severity: severity || 'info',
+      },
+      _ca = angular.toJson(_a),
+      _clist = _.map(self.list,function(alert){return angular.toJson(alert);});
+
+    // If we already have this alert, remove it and add a new one
+    // Why do this instead of skipping the add because it resets the timer
+    if(_.contains(_clist,_ca)) {
+      _.remove(self.list,_.indexOf(_clist,_ca));
+    }
+
     self.list.push(_a);
     if (timeout > 0) {
       $timeout(function() {