From 6b17cdbca64c4417154430d0ca1dc4bde7338a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 6 Sep 2016 09:14:11 +0200 Subject: [PATCH] feat(alerting): Save As removes alerts from panels, closes #5965 --- .../app/features/alerting/alert_tab_ctrl.ts | 38 +++++++++++-------- .../features/alerting/partials/alert_tab.html | 1 - .../features/dashboard/saveDashboardAsCtrl.js | 8 ++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index c5ed6187f35..d10265a3ab7 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -74,18 +74,20 @@ export class AlertTabCtrl { this.alertNotifications.push(model); } }); - }).then(() => { - this.backendSrv.get(`/api/alert-history?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}`).then(res => { - this.alertHistory = _.map(res, ah => { - ah.time = moment(ah.timestamp).format('MMM D, YYYY HH:mm:ss'); - ah.stateModel = alertDef.getStateDisplayModel(ah.newState); + }); + } - ah.metrics = _.map(ah.data, ev=> { - return ev.Metric + "=" + ev.Value; - }).join(', '); + getAlertHistory() { + this.backendSrv.get(`/api/alert-history?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}`).then(res => { + this.alertHistory = _.map(res, ah => { + ah.time = moment(ah.timestamp).format('MMM D, YYYY HH:mm:ss'); + ah.stateModel = alertDef.getStateDisplayModel(ah.newState); - return ah; - }); + ah.metrics = _.map(ah.data, ev=> { + return ev.Metric + "=" + ev.Value; + }).join(', '); + + return ah; }); }); } @@ -125,7 +127,11 @@ export class AlertTabCtrl { } initModel() { - var alert = this.alert = this.panel.alert = this.panel.alert || {}; + var alert = this.alert = this.panel.alert = this.panel.alert || {enabled: false}; + + if (!this.alert.enabled) { + return; + } alert.conditions = alert.conditions || []; if (alert.conditions.length === 0) { @@ -145,11 +151,9 @@ export class AlertTabCtrl { return memo; }, []); - if (this.alert.enabled) { - this.panelCtrl.editingThresholds = true; - } - ThresholdMapper.alertToGraphThresholds(this.panel); + + this.panelCtrl.editingThresholds = true; this.panelCtrl.render(); } @@ -173,6 +177,10 @@ export class AlertTabCtrl { } validateModel() { + if (!this.alert.enabled) { + return; + } + let firstTarget; var fixed = false; let foundTarget = null; diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index e755496b732..85919ef8a63 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -65,7 +65,6 @@ -