alert_list_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 moment from 'moment';
  6. import alertDef from './alert_def';
  7. export class AlertListCtrl {
  8. alerts: any;
  9. stateFilters = [
  10. {text: 'All', value: null},
  11. {text: 'OK', value: 'ok'},
  12. {text: 'Pending', value: 'pending'},
  13. {text: 'Warning', value: 'warning'},
  14. {text: 'Critical', value: 'critical'},
  15. {text: 'Execution Error', value: 'execution_error'},
  16. ];
  17. filters = {
  18. state: 'ALL'
  19. };
  20. /** @ngInject */
  21. constructor(private backendSrv, private $location) {
  22. var params = $location.search();
  23. this.filters.state = params.state || null;
  24. this.loadAlerts();
  25. }
  26. filtersChanged() {
  27. this.$location.search(this.filters);
  28. }
  29. loadAlerts() {
  30. this.backendSrv.get('/api/alerts', this.filters).then(result => {
  31. this.alerts = _.map(result, alert => {
  32. alert.stateModel = alertDef.getStateDisplayModel(alert.state);
  33. alert.newStateDateAgo = moment(alert.newStateDate).fromNow().replace(" ago", "");
  34. return alert;
  35. });
  36. });
  37. }
  38. }
  39. coreModule.controller('AlertListCtrl', AlertListCtrl);