mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
graph(add annotation): initial backend implementation #1286
This commit is contained in:
@@ -45,6 +45,27 @@ func GetAnnotations(c *middleware.Context) Response {
|
|||||||
return Json(200, result)
|
return Json(200, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response {
|
||||||
|
repo := annotations.GetRepository()
|
||||||
|
|
||||||
|
item := annotations.Item{
|
||||||
|
OrgId: c.OrgId,
|
||||||
|
DashboardId: cmd.DashboardId,
|
||||||
|
PanelId: cmd.PanelId,
|
||||||
|
Epoch: cmd.Time / 1000,
|
||||||
|
Title: cmd.Title,
|
||||||
|
Text: cmd.Text,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := repo.Save(&item)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ApiError(500, "Failed to save annotation", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiSuccess("Annotation added")
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteAnnotations(c *middleware.Context, cmd dtos.DeleteAnnotationsCmd) Response {
|
func DeleteAnnotations(c *middleware.Context, cmd dtos.DeleteAnnotationsCmd) Response {
|
||||||
repo := annotations.GetRepository()
|
repo := annotations.GetRepository()
|
||||||
|
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ func (hs *HttpServer) registerRoutes() {
|
|||||||
}, reqEditorRole)
|
}, reqEditorRole)
|
||||||
|
|
||||||
r.Get("/annotations", wrap(GetAnnotations))
|
r.Get("/annotations", wrap(GetAnnotations))
|
||||||
|
r.Post("/annotations", bind(dtos.PostAnnotationsCmd{}), wrap(PostAnnotation))
|
||||||
r.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), wrap(DeleteAnnotations))
|
r.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), wrap(DeleteAnnotations))
|
||||||
|
|
||||||
// error test
|
// error test
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ type Annotation struct {
|
|||||||
Data *simplejson.Json `json:"data"`
|
Data *simplejson.Json `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PostAnnotationsCmd struct {
|
||||||
|
DashboardId int64 `json:"dashboardId"`
|
||||||
|
PanelId int64 `json:"panelId"`
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteAnnotationsCmd struct {
|
type DeleteAnnotationsCmd struct {
|
||||||
AlertId int64 `json:"alertId"`
|
AlertId int64 `json:"alertId"`
|
||||||
DashboardId int64 `json:"dashboardId"`
|
DashboardId int64 `json:"dashboardId"`
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ type ItemQuery struct {
|
|||||||
Limit int64 `json:"limit"`
|
Limit int64 `json:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PostParams struct {
|
||||||
|
DashboardId int64 `json:"dashboardId"`
|
||||||
|
PanelId int64 `json:"panelId"`
|
||||||
|
Epoch int64 `json:"epoch"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteParams struct {
|
type DeleteParams struct {
|
||||||
AlertId int64 `json:"alertId"`
|
AlertId int64 `json:"alertId"`
|
||||||
DashboardId int64 `json:"dashboardId"`
|
DashboardId int64 `json:"dashboardId"`
|
||||||
|
|||||||
@@ -126,13 +126,18 @@ export class AnnotationsSrv {
|
|||||||
return this.globalAnnotationsPromise;
|
return this.globalAnnotationsPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
postAnnotation(annotation) {
|
postAnnotation(annotations) {
|
||||||
console.log("POST /api/annotations\n", annotation);
|
console.log("POST /api/annotations\n", annotations);
|
||||||
|
|
||||||
// Not implemented yet
|
// Not implemented yet
|
||||||
let implemented = false;
|
let implemented = true;
|
||||||
if (implemented) {
|
if (implemented) {
|
||||||
return this.backendSrv.post('/api/annotations', annotation);
|
return Promise.all(_.map(annotations, annotation => {
|
||||||
|
return this.backendSrv.post('/api/annotations', annotation);
|
||||||
|
}))
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve("Not implemented");
|
return Promise.resolve("Not implemented");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user