2020-01-21 03:08:07 -06:00
|
|
|
import { IScope } from 'angular';
|
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
|
2019-05-13 02:38:19 -05:00
|
|
|
import { coreModule, NavModelSrv } from 'app/core/core';
|
2020-01-21 03:08:07 -06:00
|
|
|
import { promiseToDigest } from '../../core/utils/promiseToDigest';
|
2017-06-02 07:00:42 -05:00
|
|
|
|
|
|
|
export class AlertNotificationsListCtrl {
|
2016-06-16 07:29:20 -05:00
|
|
|
notifications: any;
|
2017-06-02 07:00:42 -05:00
|
|
|
navModel: any;
|
2016-06-15 03:48:04 -05:00
|
|
|
|
|
|
|
/** @ngInject */
|
2020-01-21 03:08:07 -06:00
|
|
|
constructor(private $scope: IScope, navModelSrv: NavModelSrv) {
|
2016-06-15 03:48:04 -05:00
|
|
|
this.loadNotifications();
|
2019-06-05 08:18:31 -05:00
|
|
|
this.navModel = navModelSrv.getNav('alerting', 'channels', 0);
|
2016-06-15 03:48:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
loadNotifications() {
|
2020-01-21 03:08:07 -06:00
|
|
|
promiseToDigest(this.$scope)(
|
|
|
|
getBackendSrv()
|
|
|
|
.get(`/api/alert-notifications`)
|
|
|
|
.then((result: any) => {
|
|
|
|
this.notifications = result;
|
|
|
|
})
|
|
|
|
);
|
2016-06-15 03:48:04 -05:00
|
|
|
}
|
2016-06-16 08:21:44 -05:00
|
|
|
|
2019-05-13 02:38:19 -05:00
|
|
|
deleteNotification(id: number) {
|
2020-01-21 03:08:07 -06:00
|
|
|
promiseToDigest(this.$scope)(
|
|
|
|
getBackendSrv()
|
|
|
|
.delete(`/api/alert-notifications/${id}`)
|
|
|
|
.then(() => {
|
|
|
|
this.notifications = this.notifications.filter((notification: any) => {
|
|
|
|
return notification.id !== id;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
2016-06-16 08:21:44 -05:00
|
|
|
}
|
2016-06-15 03:48:04 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('AlertNotificationsListCtrl', AlertNotificationsListCtrl);
|