notification_edit_ctrl.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import coreModule from '../../core/core_module';
  5. import config from 'app/core/config';
  6. export class AlertNotificationEditCtrl {
  7. model: any;
  8. showTest: boolean = false;
  9. testSeverity: string = "critical";
  10. /** @ngInject */
  11. constructor(private $routeParams, private backendSrv, private $scope, private $location) {
  12. if ($routeParams.id) {
  13. this.loadNotification($routeParams.id);
  14. } else {
  15. this.model = {
  16. type: 'email',
  17. settings: {
  18. severityFilter: 'none'
  19. },
  20. isDefault: false
  21. };
  22. }
  23. }
  24. loadNotification(id) {
  25. this.backendSrv.get(`/api/alert-notifications/${id}`).then(result => {
  26. this.model = result;
  27. });
  28. }
  29. isNew() {
  30. return this.model.id === undefined;
  31. }
  32. save() {
  33. if (this.model.id) {
  34. this.backendSrv.put(`/api/alert-notifications/${this.model.id}`, this.model).then(res => {
  35. this.model = res;
  36. this.$scope.appEvent('alert-success', ['Notification updated', '']);
  37. });
  38. } else {
  39. this.backendSrv.post(`/api/alert-notifications`, this.model).then(res => {
  40. this.$scope.appEvent('alert-success', ['Notification created', '']);
  41. this.$location.path('alerting/notifications');
  42. });
  43. }
  44. }
  45. typeChanged() {
  46. this.model.settings = {};
  47. }
  48. toggleTest() {
  49. this.showTest = !this.showTest;
  50. }
  51. testNotification() {
  52. var payload = {
  53. name: this.model.name,
  54. type: this.model.type,
  55. settings: this.model.settings,
  56. severity: this.testSeverity
  57. };
  58. this.backendSrv.post(`/api/alert-notifications/test`, payload)
  59. .then(res => {
  60. this.$scope.appEvent('alert-succes', ['Test notification sent', '']);
  61. });
  62. }
  63. }
  64. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);