2016-06-16 07:29:20 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from '../../core/core_module';
|
|
|
|
import config from 'app/core/config';
|
|
|
|
|
|
|
|
export class AlertNotificationEditCtrl {
|
2016-07-25 09:26:28 -05:00
|
|
|
model: any;
|
2016-09-05 07:43:53 -05:00
|
|
|
showTest: boolean = false;
|
|
|
|
testSeverity: string = "critical";
|
2016-06-16 07:29:20 -05:00
|
|
|
|
|
|
|
/** @ngInject */
|
2016-07-25 09:26:28 -05:00
|
|
|
constructor(private $routeParams, private backendSrv, private $scope, private $location) {
|
|
|
|
if ($routeParams.id) {
|
|
|
|
this.loadNotification($routeParams.id);
|
2016-06-22 01:09:45 -05:00
|
|
|
} else {
|
2016-07-25 09:26:28 -05:00
|
|
|
this.model = {
|
2016-07-22 09:45:17 -05:00
|
|
|
type: 'email',
|
2016-09-06 06:19:05 -05:00
|
|
|
settings: {
|
|
|
|
severityFilter: 'none'
|
|
|
|
},
|
2016-09-05 14:33:05 -05:00
|
|
|
isDefault: false
|
2016-06-22 01:09:45 -05:00
|
|
|
};
|
2016-06-16 07:29:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 09:26:28 -05:00
|
|
|
loadNotification(id) {
|
|
|
|
this.backendSrv.get(`/api/alert-notifications/${id}`).then(result => {
|
|
|
|
this.model = result;
|
2016-06-16 07:29:20 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isNew() {
|
2016-07-25 09:26:28 -05:00
|
|
|
return this.model.id === undefined;
|
2016-06-16 07:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
2016-07-25 09:26:28 -05:00
|
|
|
if (this.model.id) {
|
|
|
|
this.backendSrv.put(`/api/alert-notifications/${this.model.id}`, this.model).then(res => {
|
|
|
|
this.model = res;
|
2016-08-22 07:49:40 -05:00
|
|
|
this.$scope.appEvent('alert-success', ['Notification updated', '']);
|
2016-07-25 09:26:28 -05:00
|
|
|
});
|
2016-06-16 07:29:20 -05:00
|
|
|
} else {
|
2016-07-25 09:26:28 -05:00
|
|
|
this.backendSrv.post(`/api/alert-notifications`, this.model).then(res => {
|
2016-08-22 07:49:40 -05:00
|
|
|
this.$scope.appEvent('alert-success', ['Notification created', '']);
|
2016-09-05 01:27:12 -05:00
|
|
|
this.$location.path('alerting/notifications');
|
2016-07-25 09:26:28 -05:00
|
|
|
});
|
2016-06-16 07:29:20 -05:00
|
|
|
}
|
|
|
|
}
|
2016-07-27 05:09:55 -05:00
|
|
|
|
|
|
|
typeChanged() {
|
|
|
|
this.model.settings = {};
|
|
|
|
}
|
2016-09-05 07:43:53 -05:00
|
|
|
|
|
|
|
toggleTest() {
|
|
|
|
this.showTest = !this.showTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
testNotification() {
|
|
|
|
var payload = {
|
|
|
|
name: this.model.name,
|
|
|
|
type: this.model.type,
|
|
|
|
settings: this.model.settings,
|
|
|
|
severity: this.testSeverity
|
|
|
|
};
|
|
|
|
|
|
|
|
this.backendSrv.post(`/api/alert-notifications/test`, payload)
|
|
|
|
.then(res => {
|
|
|
|
this.$scope.appEvent('alert-succes', ['Test notification sent', '']);
|
|
|
|
});
|
|
|
|
}
|
2016-06-16 07:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);
|
|
|
|
|