notification_edit_ctrl.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. notification: any;
  8. /** @ngInject */
  9. constructor(private $routeParams, private backendSrv, private $scope) {
  10. if ($routeParams.notificationId) {
  11. this.loadNotification($routeParams.notificationId);
  12. } else {
  13. this.notification = {
  14. settings: {
  15. sendCrit: true,
  16. sendWarn: true,
  17. }
  18. };
  19. }
  20. }
  21. loadNotification(notificationId) {
  22. this.backendSrv.get(`/api/alerts/notification/${notificationId}`).then(result => {
  23. console.log(result);
  24. this.notification = result;
  25. });
  26. }
  27. isNew() {
  28. return this.notification === undefined || this.notification.id === undefined;
  29. }
  30. save() {
  31. if (this.notification.id) {
  32. console.log('this.notification: ', this.notification);
  33. this.backendSrv.put(`/api/alerts/notification/${this.notification.id}`, this.notification)
  34. .then(result => {
  35. this.notification = result;
  36. this.$scope.appEvent('alert-success', ['Notification created!', '']);
  37. }, () => {
  38. this.$scope.appEvent('alert-error', ['Unable to create notification.', '']);
  39. });
  40. } else {
  41. this.backendSrv.post(`/api/alerts/notification`, this.notification)
  42. .then(result => {
  43. this.notification = result;
  44. this.$scope.appEvent('alert-success', ['Notification updated!', '']);
  45. }, () => {
  46. this.$scope.appEvent('alert-error', ['Unable to update notification.', '']);
  47. });
  48. }
  49. }
  50. }
  51. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);