alert_log_ctrl.ts 999 B

12345678910111213141516171819202122232425262728293031323334353637
  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. import moment from 'moment';
  8. export class AlertLogCtrl {
  9. alertLogs: any;
  10. alert: any;
  11. /** @ngInject */
  12. constructor(private $route, private backendSrv) {
  13. if ($route.current.params.alertId) {
  14. this.loadAlertLogs($route.current.params.alertId);
  15. }
  16. }
  17. loadAlertLogs(alertId: number) {
  18. this.backendSrv.get(`/api/alerts/${alertId}/states`).then(result => {
  19. this.alertLogs = _.map(result, log => {
  20. log.iconCss = alertDef.getSeverityIconClass(log.severity);
  21. log.humanTime = moment(log.created).format("YYYY-MM-DD HH:mm:ss");
  22. return log;
  23. });
  24. });
  25. this.backendSrv.get(`/api/alerts/${alertId}`).then(result => {
  26. this.alert = result;
  27. });
  28. }
  29. }
  30. coreModule.controller('AlertLogCtrl', AlertLogCtrl);