alertSrv.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. define([
  2. 'angular',
  3. 'underscore'
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('kibana.services');
  8. module.service('alertSrv', function($timeout) {
  9. var self = this;
  10. // List of all alert objects
  11. this.list = [];
  12. this.set = function(title,text,severity,timeout) {
  13. var
  14. _a = {
  15. title: title || '',
  16. text: text || '',
  17. severity: severity || 'info',
  18. },
  19. _ca = angular.toJson(_a),
  20. _clist = _.map(self.list,function(alert){return angular.toJson(alert);});
  21. // If we already have this alert, remove it and add a new one
  22. // Why do this instead of skipping the add because it resets the timer
  23. if(_.contains(_clist,_ca)) {
  24. _.remove(self.list,_.indexOf(_clist,_ca));
  25. }
  26. self.list.push(_a);
  27. if (timeout > 0) {
  28. $timeout(function() {
  29. self.list = _.without(self.list,_a);
  30. }, timeout);
  31. }
  32. return(_a);
  33. };
  34. this.clear = function(alert) {
  35. self.list = _.without(self.list,alert);
  36. };
  37. this.clearAll = function() {
  38. self.list = [];
  39. };
  40. });
  41. });