From 3e462f29146372bfdf7a3fd2c73281eb443305b5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 9 May 2016 12:10:53 +0200 Subject: [PATCH] chore(alerting): style refactoring --- pkg/models/alerts_state.go | 12 +++++++----- public/app/features/alerts/alert_log_ctrl.ts | 10 ++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/models/alerts_state.go b/pkg/models/alerts_state.go index 278995af846..dfd3ac376e3 100644 --- a/pkg/models/alerts_state.go +++ b/pkg/models/alerts_state.go @@ -14,14 +14,16 @@ type AlertState struct { } 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 { - 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 diff --git a/public/app/features/alerts/alert_log_ctrl.ts b/public/app/features/alerts/alert_log_ctrl.ts index 9452d24c551..8b7a92c2f4e 100644 --- a/public/app/features/alerts/alert_log_ctrl.ts +++ b/public/app/features/alerts/alert_log_ctrl.ts @@ -11,18 +11,16 @@ export class AlertLogCtrl { alertLogs: any; alert: any; - alertId: any; /** @ngInject */ constructor(private $route, private backendSrv) { 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 => { log.iconCss = alertDef.getCssForState(log.newState); 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; }); }