alerts_ctrl.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.getSeverityIconClass(alert.severity);
  41. return alert;
  42. });
  43. });
  44. }
  45. }
  46. coreModule.controller('AlertListCtrl', AlertListCtrl);