Przeglądaj źródła

chore(alerting): style refactoring

bergquist 9 lat temu
rodzic
commit
3e462f2914

+ 7 - 5
pkg/models/alerts_state.go

@@ -14,14 +14,16 @@ type AlertState struct {
 }
 }
 
 
 var (
 var (
-	ALERT_STATE_OK           = "OK"
-	ALERT_STATE_CRITICAL     = "CRITICAL"
-	ALERT_STATE_WARN         = "WARN"
-	ALERT_STATE_ACKNOWLEDGED = "ACKNOWLEDGED"
+	VALID_STATES = []string{"OK", "WARN", "CRITICAL", "ACKNOWLEDGED"}
 )
 )
 
 
 func (this *UpdateAlertStateCommand) IsValidState() bool {
 func (this *UpdateAlertStateCommand) IsValidState() bool {
-	return this.NewState == ALERT_STATE_OK || this.NewState == ALERT_STATE_WARN || this.NewState == ALERT_STATE_CRITICAL || this.NewState == ALERT_STATE_ACKNOWLEDGED
+	for _, v := range VALID_STATES {
+		if this.NewState == v {
+			return true
+		}
+	}
+	return false
 }
 }
 
 
 // Commands
 // Commands

+ 4 - 6
public/app/features/alerts/alert_log_ctrl.ts

@@ -11,18 +11,16 @@ export class AlertLogCtrl {
 
 
   alertLogs: any;
   alertLogs: any;
   alert: any;
   alert: any;
-  alertId: any;
 
 
   /** @ngInject */
   /** @ngInject */
   constructor(private $route, private backendSrv) {
   constructor(private $route, private backendSrv) {
     if ($route.current.params.alertId) {
     if ($route.current.params.alertId) {
-      this.alertId = $route.current.params.alertId;
-      this.loadAlertLogs();
+      this.loadAlertLogs($route.current.params.alertId);
     }
     }
   }
   }
 
 
-  loadAlertLogs() {
-    this.backendSrv.get(`/api/alerts/rules/${this.alertId}/states`).then(result => {
+  loadAlertLogs(alertId: number) {
+    this.backendSrv.get(`/api/alerts/rules/${alertId}/states`).then(result => {
       this.alertLogs = _.map(result, log => {
       this.alertLogs = _.map(result, log => {
         log.iconCss = alertDef.getCssForState(log.newState);
         log.iconCss = alertDef.getCssForState(log.newState);
         log.humanTime = moment(log.created).format("YYYY-MM-DD HH:mm:ss");
         log.humanTime = moment(log.created).format("YYYY-MM-DD HH:mm:ss");
@@ -30,7 +28,7 @@ export class AlertLogCtrl {
       });
       });
     });
     });
 
 
-    this.backendSrv.get(`/api/alerts/rules/${this.alertId}`).then(result => {
+    this.backendSrv.get(`/api/alerts/rules/${alertId}`).then(result => {
       this.alert = result;
       this.alert = result;
     });
     });
   }
   }