From 43f13746616a0370d7e03625452e82d81cab5974 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 30 Aug 2013 09:29:37 -0700 Subject: [PATCH 1/2] Make alerts unique, wip --- js/services.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/js/services.js b/js/services.js index 5d3b03e7de5..9c3f0a8ba26 100644 --- a/js/services.js +++ b/js/services.js @@ -11,16 +11,27 @@ angular.module('kibana.services', []) this.list = []; this.set = function(title,text,severity,timeout) { - var _a = { - title: title || '', - text: text || '', - severity: severity || 'info', - }; - self.list.push(_a); - if (timeout > 0) { - $timeout(function() { - self.list = _.without(self.list,_a); - }, timeout); + var + _a = { + title: title || '', + text: text || '', + severity: severity || 'info', + }, + _ca = angular.copy(_a), + _clist = angular.copy(self.list); + + console.log(_.contains(_clist,_ca)) + + // If there isn't already a message with the same text + if(!_.contains(_clist,_ca)) { + console.log(_clist); + console.log([_ca]); + self.list.push(_a); + if (timeout > 0) { + $timeout(function() { + self.list = _.without(self.list,_a); + }, timeout); + } } }; From a8abaaf5de9eae5768f9828376283d1451833479 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 30 Aug 2013 10:53:42 -0700 Subject: [PATCH 2/2] Check if alert exists already. Closes #442 --- js/services.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/js/services.js b/js/services.js index 9c3f0a8ba26..c2547358827 100644 --- a/js/services.js +++ b/js/services.js @@ -17,21 +17,20 @@ angular.module('kibana.services', []) text: text || '', severity: severity || 'info', }, - _ca = angular.copy(_a), - _clist = angular.copy(self.list); + _ca = angular.toJson(_a), + _clist = _.map(self.list,function(alert){return angular.toJson(alert);}); - console.log(_.contains(_clist,_ca)) + // 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)); + } - // If there isn't already a message with the same text - if(!_.contains(_clist,_ca)) { - console.log(_clist); - console.log([_ca]); - self.list.push(_a); - if (timeout > 0) { - $timeout(function() { - self.list = _.without(self.list,_a); - }, timeout); - } + self.list.push(_a); + if (timeout > 0) { + $timeout(function() { + self.list = _.without(self.list,_a); + }, timeout); } };