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 ...@@ -201,3 +201,16 @@ func UpdateAlertNotification(c *middleware.Context, cmd models.UpdateAlertNotifi
return Json(200, cmd.Result) 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) { ...@@ -257,6 +257,7 @@ func Register(r *macaron.Macaron) {
r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification)) r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
r.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification)) r.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
r.Get("/:notificationId", wrap(GetAlertNotificationById)) r.Get("/:notificationId", wrap(GetAlertNotificationById))
r.Delete("/:notificationId", wrap(DeleteAlertNotification))
}) })
r.Get("/changes", wrap(GetAlertChanges)) r.Get("/changes", wrap(GetAlertChanges))
......
...@@ -35,6 +35,11 @@ type UpdateAlertNotificationCommand struct { ...@@ -35,6 +35,11 @@ type UpdateAlertNotificationCommand struct {
Result *AlertNotification Result *AlertNotification
} }
type DeleteAlertNotificationCommand struct {
Id int64
OrgId int64
}
type GetAlertNotificationQuery struct { type GetAlertNotificationQuery struct {
Name string Name string
Id int64 Id int64
......
...@@ -15,6 +15,20 @@ func init() { ...@@ -15,6 +15,20 @@ func init() {
bus.AddHandler("sql", AlertNotificationQuery) bus.AddHandler("sql", AlertNotificationQuery)
bus.AddHandler("sql", CreateAlertNotificationCommand) bus.AddHandler("sql", CreateAlertNotificationCommand)
bus.AddHandler("sql", UpdateAlertNotification) 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 { func AlertNotificationQuery(query *m.GetAlertNotificationQuery) error {
......
...@@ -10,7 +10,7 @@ export class AlertNotificationEditCtrl { ...@@ -10,7 +10,7 @@ export class AlertNotificationEditCtrl {
notification: any; notification: any;
/** @ngInject */ /** @ngInject */
constructor(private $routeParams, private backendSrv) { constructor(private $routeParams, private backendSrv, private $scope) {
if ($routeParams.notificationId) { if ($routeParams.notificationId) {
this.loadNotification($routeParams.notificationId); this.loadNotification($routeParams.notificationId);
} }
...@@ -33,13 +33,17 @@ export class AlertNotificationEditCtrl { ...@@ -33,13 +33,17 @@ export class AlertNotificationEditCtrl {
this.backendSrv.put(`/api/alerts/notification/${this.notification.id}`, this.notification) this.backendSrv.put(`/api/alerts/notification/${this.notification.id}`, this.notification)
.then(result => { .then(result => {
this.notification = 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 { } else {
this.backendSrv.post(`/api/alerts/notification`, this.notification) this.backendSrv.post(`/api/alerts/notification`, this.notification)
.then(result => { .then(result => {
this.notification = 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 { ...@@ -10,7 +10,7 @@ export class AlertNotificationsListCtrl {
notifications: any; notifications: any;
/** @ngInject */ /** @ngInject */
constructor(private backendSrv) { constructor(private backendSrv, private $scope) {
this.loadNotifications(); this.loadNotifications();
} }
...@@ -19,7 +19,20 @@ export class AlertNotificationsListCtrl { ...@@ -19,7 +19,20 @@ export class AlertNotificationsListCtrl {
this.notifications = result; 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); coreModule.controller('AlertNotificationsListCtrl', AlertNotificationsListCtrl);
...@@ -4,32 +4,35 @@ ...@@ -4,32 +4,35 @@
<div class="page-container" > <div class="page-container" >
<div class="page-header"> <div class="page-header">
<h1>Alert notifications</h1> <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> <i class="fa fa-plus"></i>
New Notification New Notification
</button> </a>
</div> </div>
<table class="grafana-options-table"> <table class="grafana-options-table" style="/*width: 600px;*/">
<thead> <thead>
<th style="min-width: 200px"><strong>Name</strong></th> <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> <th style="width: 1%"></th>
</thead> </thead>
<tr ng-repeat="notification in ctrl.notifications"> <tr ng-repeat="notification in ctrl.notifications">
<td> <td>
<a href="alerting/notification{{notification.id}}/edit"> <a href="alerting/notification{{notification.id}}/edit">
{{alert.name}} {{notification.name}}
</a> </a>
</td> </td>
<td class="text-center"> <td>
{{notification.type}} {{notification.type}}
</td> </td>
<td class="text-center"> <td>
<a href="alerting/notification/{{notification.id}}/edit" class="btn btn-inverse btn-small"> <a href="alerting/notification/{{notification.id}}/edit" class="btn btn-inverse btn-small">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
edit edit
</a> </a>
<a ng-click="ctrl.deleteNotification(notification.id)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
</a>
</td> </td>
</tr> </tr>
</table> </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