alerts_ctrl.ts 895 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. /** @ngInject */
  10. constructor(private backendSrv) {
  11. this.loadAlerts();
  12. }
  13. loadAlerts() {
  14. this.backendSrv.get('/api/alerts').then(result => {
  15. this.alerts = _.map(result, alert => {
  16. alert.iconCss = alertDef.getCssForState(alert.state);
  17. return alert;
  18. });
  19. });
  20. }
  21. deleteAlert(alert) {
  22. this.backendSrv.delete('/api/alerts/' + alert.id).then(result => {
  23. if (result.alertId) {
  24. this.alerts = this.alerts.filter(alert => {
  25. return alert.id !== result.alertId;
  26. });
  27. }
  28. });
  29. }
  30. }
  31. coreModule.controller('AlertPageCtrl', AlertPageCtrl);