Commit b907ce34 by bergquist

feat(alerting): enables deletes for alert notifications

parent 149c2ae9
......@@ -201,3 +201,16 @@ func UpdateAlertNotification(c *middleware.Context, cmd models.UpdateAlertNotifi
return Json(200, cmd.Result)
}
func DeleteAlertNotification(c *middleware.Context) Response {
cmd := models.DeleteAlertNotificationCommand{
OrgId: c.OrgId,
Id: c.ParamsInt64("notificationId"),
}
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to delete alert notification", err)
}
return Json(200, map[string]interface{}{"notificationId": cmd.Id})
}
......@@ -257,6 +257,7 @@ func Register(r *macaron.Macaron) {
r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
r.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
r.Get("/:notificationId", wrap(GetAlertNotificationById))
r.Delete("/:notificationId", wrap(DeleteAlertNotification))
})
r.Get("/changes", wrap(GetAlertChanges))
......
......@@ -35,6 +35,11 @@ type UpdateAlertNotificationCommand struct {
Result *AlertNotification
}
type DeleteAlertNotificationCommand struct {
Id int64
OrgId int64
}
type GetAlertNotificationQuery struct {
Name string
Id int64
......
......@@ -15,6 +15,20 @@ func init() {
bus.AddHandler("sql", AlertNotificationQuery)
bus.AddHandler("sql", CreateAlertNotificationCommand)
bus.AddHandler("sql", UpdateAlertNotification)
bus.AddHandler("sql", DeleteAlertNotification)
}
func DeleteAlertNotification(cmd *m.DeleteAlertNotificationCommand) error {
return inTransaction(func(sess *xorm.Session) error {
sql := "DELETE FROM alert_notification WHERE alert_notification.org_id = ? AND alert_notification.id = ?"
_, err := sess.Exec(sql, cmd.OrgId, cmd.Id)
if err != nil {
return err
}
return nil
})
}
func AlertNotificationQuery(query *m.GetAlertNotificationQuery) error {
......
......@@ -10,7 +10,7 @@ export class AlertNotificationEditCtrl {
notification: any;
/** @ngInject */
constructor(private $routeParams, private backendSrv) {
constructor(private $routeParams, private backendSrv, private $scope) {
if ($routeParams.notificationId) {
this.loadNotification($routeParams.notificationId);
}
......@@ -33,13 +33,17 @@ export class AlertNotificationEditCtrl {
this.backendSrv.put(`/api/alerts/notification/${this.notification.id}`, this.notification)
.then(result => {
this.notification = result;
console.log('updated notification', result);
this.$scope.appEvent('alert-success', ['Notification created!', '']);
}, () => {
this.$scope.appEvent('alert-error', ['Unable to create notification.', '']);
});
} else {
this.backendSrv.post(`/api/alerts/notification`, this.notification)
.then(result => {
this.notification = result;
console.log('created new notification', result);
this.$scope.appEvent('alert-success', ['Notification updated!', '']);
}, () => {
this.$scope.appEvent('alert-error', ['Unable to update notification.', '']);
});
}
}
......
......@@ -10,7 +10,7 @@ export class AlertNotificationsListCtrl {
notifications: any;
/** @ngInject */
constructor(private backendSrv) {
constructor(private backendSrv, private $scope) {
this.loadNotifications();
}
......@@ -19,7 +19,20 @@ export class AlertNotificationsListCtrl {
this.notifications = result;
});
}
deleteNotification(notificationId) {
this.backendSrv.delete(`/api/alerts/notification/${notificationId}`)
.then(() => {
this.notifications = this.notifications.filter(notification => {
return notification.id !== notificationId;
});
this.$scope.appEvent('alert-success', ['Notification deleted', '']);
}, () => {
this.$scope.appEvent('alert-error', ['Unable to delete notification', '']);
});
}
}
coreModule.controller('AlertNotificationsListCtrl', AlertNotificationsListCtrl);
......@@ -4,32 +4,35 @@
<div class="page-container" >
<div class="page-header">
<h1>Alert notifications</h1>
<button class="btn btn-success pull-right">
<a href="alerting/notification/new" class="btn btn-success pull-right">
<i class="fa fa-plus"></i>
New Notification
</button>
</a>
</div>
<table class="grafana-options-table">
<table class="grafana-options-table" style="/*width: 600px;*/">
<thead>
<th style="min-width: 200px"><strong>Name</strong></th>
<th style="width: 1%">Type</th>
<th style="min-width: 100px">Type</th>
<th style="width: 1%"></th>
</thead>
<tr ng-repeat="notification in ctrl.notifications">
<td>
<a href="alerting/notification{{notification.id}}/edit">
{{alert.name}}
{{notification.name}}
</a>
</td>
<td class="text-center">
<td>
{{notification.type}}
</td>
<td class="text-center">
<td>
<a href="alerting/notification/{{notification.id}}/edit" class="btn btn-inverse btn-small">
<i class="fa fa-edit"></i>
edit
</a>
<a ng-click="ctrl.deleteNotification(notification.id)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
</a>
</td>
</tr>
</table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment