From 47e4b7714036183c54192e3cf481a470bfc998d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 6 Jan 2015 13:03:55 +0100 Subject: [PATCH] lodash remove override fix, Fixes #1304 --- src/app/components/lodash.extended.js | 4 ---- src/app/services/alertSrv.js | 31 +++++++++++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/app/components/lodash.extended.js b/src/app/components/lodash.extended.js index 40372239672..4edae35f02d 100644 --- a/src/app/components/lodash.extended.js +++ b/src/app/components/lodash.extended.js @@ -14,10 +14,6 @@ function () { array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]); return array; }, - remove: function (array, index) { - array.splice(index, 1); - return array; - }, // If variable is value, then return alt. If variable is anything else, return value; toggle: function (variable, value, alt) { return variable === value ? alt : value; diff --git a/src/app/services/alertSrv.js b/src/app/services/alertSrv.js index 74b3308c4e8..6d5801ad649 100644 --- a/src/app/services/alertSrv.js +++ b/src/app/services/alertSrv.js @@ -27,28 +27,27 @@ function (angular, _) { this.list = []; this.set = function(title,text,severity,timeout) { - var - _a = { - title: title || '', - text: $sce.trustAsHtml(text || ''), - severity: severity || 'info', - }, - _ca = angular.toJson(_a), - _clist = _.map(self.list,function(alert) {return angular.toJson(alert);}); + var newAlert = { + title: title || '', + text: $sce.trustAsHtml(text || ''), + severity: severity || 'info', + }; - // 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)); - } + var newAlertJson = angular.toJson(newAlert); - self.list.push(_a); + // remove same alert if it already exists + _.remove(self.list, function(value) { + return angular.toJson(value) === newAlertJson; + }); + + self.list.push(newAlert); if (timeout > 0) { $timeout(function() { - self.list = _.without(self.list,_a); + self.list = _.without(self.list,newAlert); }, timeout); } - return(_a); + + return(newAlert); }; this.clear = function(alert) {