notification_edit_ctrl.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. testSeverity: string = "critical";
  9. /** @ngInject */
  10. constructor(private $routeParams, private backendSrv, private $scope, private $location) {
  11. if ($routeParams.id) {
  12. this.loadNotification($routeParams.id);
  13. } else {
  14. this.model = {
  15. type: 'email',
  16. settings: {
  17. severityFilter: 'none'
  18. },
  19. isDefault: false
  20. };
  21. }
  22. }
  23. loadNotification(id) {
  24. this.backendSrv.get(`/api/alert-notifications/${id}`).then(result => {
  25. this.model = result;
  26. });
  27. }
  28. isNew() {
  29. return this.model.id === undefined;
  30. }
  31. save() {
  32. if (this.model.id) {
  33. this.backendSrv.put(`/api/alert-notifications/${this.model.id}`, this.model).then(res => {
  34. this.model = res;
  35. this.$scope.appEvent('alert-success', ['Notification updated', '']);
  36. });
  37. } else {
  38. this.backendSrv.post(`/api/alert-notifications`, this.model).then(res => {
  39. this.$scope.appEvent('alert-success', ['Notification created', '']);
  40. this.$location.path('alerting/notifications');
  41. });
  42. }
  43. }
  44. typeChanged() {
  45. this.model.settings = {};
  46. }
  47. testNotification() {
  48. var payload = {
  49. name: this.model.name,
  50. type: this.model.type,
  51. settings: this.model.settings,
  52. };
  53. this.backendSrv.post(`/api/alert-notifications/test`, payload)
  54. .then(res => {
  55. this.$scope.appEvent('alert-succes', ['Test notification sent', '']);
  56. });
  57. }
  58. }
  59. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);