Commit 0156a94a by Torkel Ödegaard

annotations: you can now read annoations via manually created annoation query

parent 78f4bd2d
...@@ -39,6 +39,7 @@ func GetAnnotations(c *middleware.Context) Response { ...@@ -39,6 +39,7 @@ func GetAnnotations(c *middleware.Context) Response {
Text: item.Text, Text: item.Text,
Metric: item.Metric, Metric: item.Metric,
Title: item.Title, Title: item.Title,
PanelId: item.PanelId,
}) })
} }
...@@ -55,6 +56,8 @@ func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response ...@@ -55,6 +56,8 @@ func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response
Epoch: cmd.Time / 1000, Epoch: cmd.Time / 1000,
Title: cmd.Title, Title: cmd.Title,
Text: cmd.Text, Text: cmd.Text,
CategoryId: cmd.CategoryId,
Type: annotations.EventType,
} }
err := repo.Save(&item) err := repo.Save(&item)
......
...@@ -277,8 +277,10 @@ func (hs *HttpServer) registerRoutes() { ...@@ -277,8 +277,10 @@ 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.Group("/annotations", func() {
r.Post("/", bind(dtos.PostAnnotationsCmd{}), wrap(PostAnnotation))
}, reqEditorRole)
// error test // error test
r.Get("/metrics/error", wrap(GenerateError)) r.Get("/metrics/error", wrap(GenerateError))
......
...@@ -19,6 +19,7 @@ type Annotation struct { ...@@ -19,6 +19,7 @@ type Annotation struct {
type PostAnnotationsCmd struct { type PostAnnotationsCmd struct {
DashboardId int64 `json:"dashboardId"` DashboardId int64 `json:"dashboardId"`
PanelId int64 `json:"panelId"` PanelId int64 `json:"panelId"`
CategoryId int64 `json:"categoryId"`
Time int64 `json:"time"` Time int64 `json:"time"`
Title string `json:"title"` Title string `json:"title"`
Text string `json:"text"` Text string `json:"text"`
......
...@@ -49,6 +49,7 @@ type ItemType string ...@@ -49,6 +49,7 @@ type ItemType string
const ( const (
AlertType ItemType = "alert" AlertType ItemType = "alert"
EventType ItemType = "event"
) )
type Item struct { type Item struct {
......
...@@ -35,6 +35,13 @@ export class AnnotationsSrv { ...@@ -35,6 +35,13 @@ export class AnnotationsSrv {
// combine the annotations and flatten results // combine the annotations and flatten results
var annotations = _.flattenDeep([results[0], results[1]]); var annotations = _.flattenDeep([results[0], results[1]]);
// filter out annotations that do not belong to requesting panel
annotations = _.filter(annotations, item => {
if (item.panelId && options.panel.id !== item.panelId) {
return false;
}
return true;
});
// look for alert state for this panel // look for alert state for this panel
var alertState = _.find(results[2], {panelId: options.panel.id}); var alertState = _.find(results[2], {panelId: options.panel.id});
......
...@@ -61,7 +61,6 @@ export class AddAnnotationModalCtrl { ...@@ -61,7 +61,6 @@ export class AddAnnotationModalCtrl {
} }
close() { close() {
this.graphCtrl.inAddAnnotationMode = false;
this.$scope.dismiss(); this.$scope.dismiss();
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-7">Type</span> <span class="gf-form-label width-7">Type</span>
<div class="gf-form-select-wrapper"> <div class="gf-form-select-wrapper">
<select class="gf-form-input" ng-model="ctrl.annotation.type" ng-options="f.value as f.text for f in [{text: 'Alert', value: 'alert'}]"> <select class="gf-form-input" ng-model="ctrl.annotation.type" ng-options="f.value as f.text for f in [{text: 'Event', value: 'event'}, {text: 'Alert', value: 'alert'}]">
</select> </select>
</div> </div>
</div> </div>
......
...@@ -84,7 +84,7 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) { ...@@ -84,7 +84,7 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
let thisPanelEvent = event.panel.id === ctrl.panel.id; let thisPanelEvent = event.panel.id === ctrl.panel.id;
// Select time for new annotation // Select time for new annotation
let createAnnotation = ctrl.inAddAnnotationMode || event.pos.ctrlKey || event.pos.metaKey; let createAnnotation = event.pos.ctrlKey || event.pos.metaKey;
if (createAnnotation && thisPanelEvent) { if (createAnnotation && thisPanelEvent) {
let timeRange = { let timeRange = {
from: event.pos.x, from: event.pos.x,
...@@ -92,7 +92,6 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) { ...@@ -92,7 +92,6 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
}; };
ctrl.showAddAnnotationModal(timeRange); ctrl.showAddAnnotationModal(timeRange);
ctrl.inAddAnnotationMode = false;
} }
}, scope); }, scope);
...@@ -656,12 +655,11 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) { ...@@ -656,12 +655,11 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
} }
elem.bind("plotselected", function (event, ranges) { elem.bind("plotselected", function (event, ranges) {
if (ctrl.inAddAnnotationMode || ranges.ctrlKey || ranges.metaKey) { if (ranges.ctrlKey || ranges.metaKey) {
// Create new annotation from time range // Create new annotation from time range
let timeRange = ranges.xaxis; let timeRange = ranges.xaxis;
ctrl.showAddAnnotationModal(timeRange); ctrl.showAddAnnotationModal(timeRange);
plot.clearSelection(); plot.clearSelection();
ctrl.inAddAnnotationMode = false;
} else { } else {
scope.$apply(function() { scope.$apply(function() {
timeSrv.setTime({ timeSrv.setTime({
......
...@@ -24,7 +24,6 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -24,7 +24,6 @@ class GraphCtrl extends MetricsPanelCtrl {
dataList: any = []; dataList: any = [];
annotations: any = []; annotations: any = [];
alertState: any; alertState: any;
inAddAnnotationMode = false;
annotationsPromise: any; annotationsPromise: any;
dataWarning: any; dataWarning: any;
...@@ -303,8 +302,8 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -303,8 +302,8 @@ class GraphCtrl extends MetricsPanelCtrl {
} }
enableAddAnnotationMode() { enableAddAnnotationMode() {
// TODO: notify user about time selection mode // placehoder for some other way to teach users
this.inAddAnnotationMode = true; alert('selection region while holding down CTRL or CMD');
} }
// Get annotation info from dialog and push it to backend // Get annotation info from dialog and push it to backend
......
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