annotation: added region support to annoations

This commit is contained in:
Torkel Ödegaard
2017-04-12 16:26:34 +02:00
parent b867921b3b
commit 593b2ef866
5 changed files with 41 additions and 3 deletions

View File

@@ -40,6 +40,7 @@ func GetAnnotations(c *middleware.Context) Response {
Metric: item.Metric,
Title: item.Title,
PanelId: item.PanelId,
RegionId: item.RegionId,
})
}
@@ -57,15 +58,30 @@ func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response
Title: cmd.Title,
Text: cmd.Text,
CategoryId: cmd.CategoryId,
NewState: cmd.FillColor,
Type: annotations.EventType,
}
err := repo.Save(&item)
if err != nil {
if err := repo.Save(&item); err != nil {
return ApiError(500, "Failed to save annotation", err)
}
// handle regions
if cmd.IsRegion {
item.RegionId = item.Id
if err := repo.Update(&item); err != nil {
return ApiError(500, "Failed set regionId on annotation", err)
}
item.Id = 0
item.Epoch = cmd.EndTime
if err := repo.Save(&item); err != nil {
return ApiError(500, "Failed save annotation for region end time", err)
}
}
return ApiSuccess("Annotation added")
}

View File

@@ -12,6 +12,7 @@ type Annotation struct {
Title string `json:"title"`
Text string `json:"text"`
Metric string `json:"metric"`
RegionId int64 `json:"regionId"`
Data *simplejson.Json `json:"data"`
}
@@ -23,6 +24,10 @@ type PostAnnotationsCmd struct {
Time int64 `json:"time"`
Title string `json:"title"`
Text string `json:"text"`
FillColor string `json:"fillColor"`
IsRegion bool `json:"isRegion"`
EndTime int64 `json:"endTime"`
}
type DeleteAnnotationsCmd struct {