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: 'Alerting', value: 'alerting'},
  14. {text: 'No Data', value: 'no_data'},
  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. openHowTo() {
  39. appEvents.emit('show-modal', {
  40. src: 'public/app/features/alerting/partials/alert_howto.html',
  41. modalClass: 'confirm-modal',
  42. model: {}
  43. });
  44. }
  45. }
  46. coreModule.controller('AlertListCtrl', AlertListCtrl);