feat(alerting): making progress on alert handles

This commit is contained in:
Torkel Ödegaard
2016-08-10 21:37:10 +02:00
parent 2639c38912
commit fbb8f8e691
5 changed files with 51 additions and 35 deletions

View File

@@ -63,10 +63,13 @@ export class AlertTabCtrl {
// set panel alert edit mode
this.$scope.$on("$destroy", () => {
this.panelCtrl.editingAlert = false;
this.panelCtrl.editingThresholds = false;
this.panelCtrl.render();
});
// subscribe to graph threshold handle changes
this.panelCtrl.events.on('threshold-changed', this.graphThresholdChanged.bind(this));
// build notification model
this.notifications = [];
this.alertNotifications = [];
@@ -139,12 +142,19 @@ export class AlertTabCtrl {
return memo;
}, []);
this.panelCtrl.editingAlert = true;
if (this.alert.enabled) {
this.panelCtrl.editingThresholds = true;
}
this.syncThresholds();
this.panelCtrl.render();
}
syncThresholds() {
if (this.panel.type !== 'graph') {
return;
}
var threshold: any = {};
if (this.panel.thresholds && this.panel.thresholds.length > 0) {
threshold = this.panel.thresholds[0];
@@ -160,16 +170,13 @@ export class AlertTabCtrl {
continue;
}
if (value !== threshold.from) {
threshold.from = value;
if (value !== threshold.value) {
threshold.value = value;
updated = true;
}
if (condition.evaluator.type === '<' && threshold.to !== -Infinity) {
threshold.to = -Infinity;
updated = true;
} else if (condition.evaluator.type === '>' && threshold.to !== Infinity) {
threshold.to = Infinity;
if (condition.evaluator.type !== threshold.op) {
threshold.op = condition.evaluator.type;
updated = true;
}
}
@@ -178,6 +185,15 @@ export class AlertTabCtrl {
return updated;
}
graphThresholdChanged(evt) {
for (var condition of this.alert.conditions) {
if (condition.type === 'query') {
condition.evaluator.params[0] = evt.threshold.value;
break;
}
}
}
buildDefaultCondition() {
return {
type: 'query',