chore(alerting): style refactoring

This commit is contained in:
bergquist 2016-05-09 12:10:53 +02:00
parent 35c73902da
commit 3e462f2914
2 changed files with 11 additions and 11 deletions

View File

@ -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

View File

@ -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;
});
}