alerts_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import coreModule from '../../core/core_module';
  5. import config from 'app/core/config';
  6. import alertDef from './alert_def';
  7. export class AlertListCtrl {
  8. alerts: any;
  9. filter = {
  10. ok: false,
  11. warn: false,
  12. critical: false,
  13. acknowleged: false
  14. };
  15. /** @ngInject */
  16. constructor(private backendSrv, private $route) {
  17. _.each($route.current.params.state, state => {
  18. this.filter[state.toLowerCase()] = true;
  19. });
  20. this.loadAlerts();
  21. }
  22. updateFilter() {
  23. var stats = [];
  24. this.filter.ok && stats.push('OK');
  25. this.filter.warn && stats.push('Warn');
  26. this.filter.critical && stats.push('critical');
  27. this.$route.current.params.state = stats;
  28. this.$route.updateParams();
  29. }
  30. loadAlerts() {
  31. var stats = [];
  32. this.filter.ok && stats.push('OK');
  33. this.filter.warn && stats.push('Warn');
  34. this.filter.critical && stats.push('critical');
  35. var params = {
  36. state: stats
  37. };
  38. this.backendSrv.get('/api/alerts', params).then(result => {
  39. this.alerts = _.map(result, alert => {
  40. alert.severityClass = alertDef.getSeverityClass(alert.severity);
  41. alert.stateClass = alertDef.getStateClass(alert.state);
  42. return alert;
  43. });
  44. });
  45. }
  46. }
  47. coreModule.controller('AlertListCtrl', AlertListCtrl);