diff --git a/public/app/plugins/panel/graph/alert_tab_ctrl.ts b/public/app/plugins/panel/graph/alert_tab_ctrl.ts index 4ee59248257..c47d58631b8 100644 --- a/public/app/plugins/panel/graph/alert_tab_ctrl.ts +++ b/public/app/plugins/panel/graph/alert_tab_ctrl.ts @@ -62,37 +62,20 @@ export class AlertTabCtrl { }); } - getThresholdWithDefaults(thresholds, type, copyFrom) { + getThresholdWithDefaults(thresholds, type) { var threshold = thresholds[type] || {}; - var defaultValue = (copyFrom[type] || {}).value || undefined; - threshold.op = threshold.op || '>'; - threshold.value = threshold.value || defaultValue; + threshold.value = threshold.value || undefined; return threshold; } - initThresholdsOnlyMode() { - if (!this.panel.thresholds) { - return; - } - - this.thresholds = this.panel.thresholds; - - // set threshold defaults - this.thresholds.warn = this.getThresholdWithDefaults(this.thresholds, 'warn', {}); - this.thresholds.crit = this.getThresholdWithDefaults(this.thresholds, 'crit', {}); - - this.panelCtrl.editingAlert = true; - this.panelCtrl.render(); - } - initModel() { var alert = this.alert = this.panel.alert = this.panel.alert || {}; // set threshold defaults alert.thresholds = alert.thresholds || {}; - alert.thresholds.warn = this.getThresholdWithDefaults(alert.thresholds, 'warn', this.panel.thresholds); - alert.thresholds.crit = this.getThresholdWithDefaults(alert.thresholds, 'crit', this.panel.thresholds); + alert.thresholds.warn = this.getThresholdWithDefaults(alert.thresholds, 'warn'); + alert.thresholds.crit = this.getThresholdWithDefaults(alert.thresholds, 'crit'); alert.frequency = alert.frequency || '60s'; alert.handler = alert.handler || 1; @@ -150,21 +133,18 @@ export class AlertTabCtrl { } delete() { - delete this.alert; - delete this.panel.alert; - // clear thresholds - if (this.panel.thresholds) { - this.panel.thresholds = {}; - } + // keep threshold object (instance used by graph handles) + var thresholds = this.alert.thresholds; + thresholds.warn.value = undefined; + thresholds.crit.value = undefined; + + // reset model but keep thresholds instance + this.alert = this.panel.alert = {thresholds: thresholds}; this.initModel(); } enable() { - if (this.thresholds) { - delete this.thresholds; - this.panelCtrl. - } - this.panel.alert = {}; + this.alert.enabled = true; this.initModel(); } diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 381565e8f3f..b76956ff6e8 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -333,13 +333,11 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) { } function addGridThresholds(options, panel) { - var thresholds = panel.thresholds; - - // use alert thresholds if there are any - if (panel.alert) { - thresholds = panel.alert.thresholds; + if (!panel.alert || !panel.alert.thresholds) { + return; } + var thresholds = panel.alert.thresholds; var crit = thresholds.crit; var warn = thresholds.warn; var critEdge = Infinity; diff --git a/public/app/plugins/panel/graph/partials/tab_alerting.html b/public/app/plugins/panel/graph/partials/tab_alerting.html index 38873ec829e..c07886aeddf 100644 --- a/public/app/plugins/panel/graph/partials/tab_alerting.html +++ b/public/app/plugins/panel/graph/partials/tab_alerting.html @@ -1,5 +1,5 @@ -