|
|
@@ -48,19 +48,18 @@ export class AlertTabCtrl {
|
|
|
$onInit() {
|
|
|
this.addNotificationSegment = this.uiSegmentSrv.newPlusButton();
|
|
|
|
|
|
- this.initModel();
|
|
|
- this.validateModel();
|
|
|
+ // subscribe to graph threshold handle changes
|
|
|
+ var thresholdChangedEventHandler = this.graphThresholdChanged.bind(this);
|
|
|
+ this.panelCtrl.events.on('threshold-changed', thresholdChangedEventHandler);
|
|
|
|
|
|
- // set panel alert edit mode
|
|
|
+ // set panel alert edit mode
|
|
|
this.$scope.$on("$destroy", () => {
|
|
|
+ this.panelCtrl.events.off("threshold-changed", thresholdChangedEventHandler);
|
|
|
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
|
|
|
+ // build notification model
|
|
|
this.notifications = [];
|
|
|
this.alertNotifications = [];
|
|
|
this.alertHistory = [];
|
|
|
@@ -68,21 +67,8 @@ export class AlertTabCtrl {
|
|
|
return this.backendSrv.get('/api/alert-notifications').then(res => {
|
|
|
this.notifications = res;
|
|
|
|
|
|
- _.each(this.alert.notifications, item => {
|
|
|
- var model = _.find(this.notifications, {id: item.id});
|
|
|
- if (model) {
|
|
|
- model.iconClass = this.getNotificationIcon(model.type);
|
|
|
- this.alertNotifications.push(model);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- _.each(this.notifications, item => {
|
|
|
- if (item.isDefault) {
|
|
|
- item.iconClass = this.getNotificationIcon(item.type);
|
|
|
- item.bgColor = "#00678b";
|
|
|
- this.alertNotifications.push(item);
|
|
|
- }
|
|
|
- });
|
|
|
+ this.initModel();
|
|
|
+ this.validateModel();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -143,9 +129,8 @@ export class AlertTabCtrl {
|
|
|
}
|
|
|
|
|
|
initModel() {
|
|
|
- var alert = this.alert = this.panel.alert = this.panel.alert || {enabled: false};
|
|
|
-
|
|
|
- if (!this.alert.enabled) {
|
|
|
+ var alert = this.alert = this.panel.alert;
|
|
|
+ if (!alert) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -169,6 +154,22 @@ export class AlertTabCtrl {
|
|
|
|
|
|
ThresholdMapper.alertToGraphThresholds(this.panel);
|
|
|
|
|
|
+ for (let addedNotification of alert.notifications) {
|
|
|
+ var model = _.find(this.notifications, {id: addedNotification.id});
|
|
|
+ if (model) {
|
|
|
+ model.iconClass = this.getNotificationIcon(model.type);
|
|
|
+ this.alertNotifications.push(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let notification of this.notifications) {
|
|
|
+ if (notification.isDefault) {
|
|
|
+ notification.iconClass = this.getNotificationIcon(notification.type);
|
|
|
+ notification.bgColor = "#00678b";
|
|
|
+ this.alertNotifications.push(notification);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.panelCtrl.editingThresholds = true;
|
|
|
this.panelCtrl.render();
|
|
|
}
|
|
|
@@ -193,7 +194,7 @@ export class AlertTabCtrl {
|
|
|
}
|
|
|
|
|
|
validateModel() {
|
|
|
- if (!this.alert.enabled) {
|
|
|
+ if (!this.alert) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -310,17 +311,17 @@ export class AlertTabCtrl {
|
|
|
icon: 'fa-trash',
|
|
|
yesText: 'Delete',
|
|
|
onConfirm: () => {
|
|
|
- this.alert = this.panel.alert = {enabled: false};
|
|
|
+ delete this.panel.alert;
|
|
|
+ this.alert = null;
|
|
|
this.panel.thresholds = [];
|
|
|
this.conditionModels = [];
|
|
|
this.panelCtrl.render();
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
|
|
|
enable() {
|
|
|
- this.alert.enabled = true;
|
|
|
+ this.panel.alert = {};
|
|
|
this.initModel();
|
|
|
}
|
|
|
|