alert_list_ctrl.ts 1.4 KB

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