alerts_ctrl.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 AlertPageCtrl {
  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.filter.acknowleged && stats.push('acknowleged');
  28. this.$route.current.params.state = stats;
  29. this.$route.updateParams();
  30. }
  31. loadAlerts() {
  32. var stats = [];
  33. this.filter.ok && stats.push('Ok');
  34. this.filter.warn && stats.push('Warn');
  35. this.filter.critical && stats.push('critical');
  36. this.filter.acknowleged && stats.push('acknowleged');
  37. var params = {
  38. state: stats
  39. };
  40. this.backendSrv.get('/api/alerts/rules', params).then(result => {
  41. this.alerts = _.map(result, alert => {
  42. alert.iconCss = alertDef.getCssForState(alert.state);
  43. return alert;
  44. });
  45. });
  46. }
  47. }
  48. coreModule.controller('AlertPageCtrl', AlertPageCtrl);