mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): added clear history button to alert state history view, #6244
This commit is contained in:
@@ -44,3 +44,19 @@ func GetAnnotations(c *middleware.Context) Response {
|
||||
|
||||
return Json(200, result)
|
||||
}
|
||||
|
||||
func DeleteAnnotations(c *middleware.Context, cmd dtos.DeleteAnnotationsCmd) Response {
|
||||
repo := annotations.GetRepository()
|
||||
|
||||
err := repo.Delete(&annotations.DeleteParams{
|
||||
AlertId: cmd.PanelId,
|
||||
DashboardId: cmd.DashboardId,
|
||||
PanelId: cmd.PanelId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ApiError(500, "Failed to delete annotations", err)
|
||||
}
|
||||
|
||||
return ApiSuccess("Annotations deleted")
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ func Register(r *macaron.Macaron) {
|
||||
}, reqOrgAdmin)
|
||||
|
||||
r.Get("/annotations", wrap(GetAnnotations))
|
||||
r.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), wrap(DeleteAnnotations))
|
||||
|
||||
// error test
|
||||
r.Get("/metrics/error", wrap(GenerateError))
|
||||
|
||||
@@ -15,3 +15,9 @@ type Annotation struct {
|
||||
|
||||
Data *simplejson.Json `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteAnnotationsCmd struct {
|
||||
AlertId int64 `json:"alertId"`
|
||||
DashboardId int64 `json:"dashboardId"`
|
||||
PanelId int64 `json:"panelId"`
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import "github.com/grafana/grafana/pkg/components/simplejson"
|
||||
type Repository interface {
|
||||
Save(item *Item) error
|
||||
Find(query *ItemQuery) ([]*Item, error)
|
||||
Delete(params *DeleteParams) error
|
||||
}
|
||||
|
||||
type ItemQuery struct {
|
||||
@@ -20,6 +21,12 @@ type ItemQuery struct {
|
||||
Limit int64 `json:"alertId"`
|
||||
}
|
||||
|
||||
type DeleteParams struct {
|
||||
AlertId int64 `json:"alertId"`
|
||||
DashboardId int64 `json:"dashboardId"`
|
||||
PanelId int64 `json:"panelId"`
|
||||
}
|
||||
|
||||
var repositoryInstance Repository
|
||||
|
||||
func GetRepository() Repository {
|
||||
|
||||
@@ -84,3 +84,17 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (r *SqlAnnotationRepo) Delete(params *annotations.DeleteParams) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
|
||||
sql := "DELETE FROM annotation WHERE dashboard_id = ? AND panel_id = ?"
|
||||
|
||||
_, err := sess.Exec(sql, params.DashboardId, params.PanelId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user