From d2f3d7d138bde58708c61bbd2932b61847f94085 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 12 Apr 2017 16:06:48 +0300 Subject: [PATCH 1/6] graph(add annotation): get alerts for all panels --- public/app/features/annotations/annotations_srv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/annotations/annotations_srv.ts b/public/app/features/annotations/annotations_srv.ts index d3b83982f51..380cc93ead9 100644 --- a/public/app/features/annotations/annotations_srv.ts +++ b/public/app/features/annotations/annotations_srv.ts @@ -53,7 +53,7 @@ export class AnnotationsSrv { var panel = options.panel; var dashboard = options.dashboard; - if (panel && panel.alert) { + if (panel) { return this.backendSrv.get('/api/annotations', { from: options.range.from.valueOf(), to: options.range.to.valueOf(), From 8a1c35e1c233562ea595d8c8a226afb3ee758e33 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 12 Apr 2017 20:27:32 +0300 Subject: [PATCH 2/6] graph(create annotation): refactor, fix two modal after range selection bind create annotation handler directly to plotclick event, not to global graph-click --- public/app/plugins/panel/graph/graph.ts | 30 ++++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 4d68e10bbc0..88a0f545cc9 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -79,22 +79,6 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) { } }, scope); - appEvents.on('graph-click', (event) => { - // Add event only for selected panel - let thisPanelEvent = event.panel.id === ctrl.panel.id; - - // Select time for new annotation - let createAnnotation = event.pos.ctrlKey || event.pos.metaKey; - if (createAnnotation && thisPanelEvent) { - let timeRange = { - from: event.pos.x, - to: null - }; - - ctrl.showAddAnnotationModal(timeRange); - } - }, scope); - function getLegendHeight(panelHeight) { if (!panel.legend.show || panel.legend.rightSide) { return 0; @@ -670,6 +654,20 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) { } }); + elem.bind("plotclick", function (event, pos, item) { + // Skip if range selected (added in "plotselected" event handler) + let isRangeSelection = pos.x !== pos.x1; + let createAnnotation = !isRangeSelection && (pos.ctrlKey || pos.metaKey); + if (createAnnotation) { + let timeRange = { + from: pos.x, + to: null + }; + + ctrl.showAddAnnotationModal(timeRange); + } + }); + scope.$on('$destroy', function() { tooltip.destroy(); elem.off(); From ef99ff0ad737a8b1c9d493f6307039cf5e3e7455 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 12 Apr 2017 20:37:33 +0300 Subject: [PATCH 3/6] graph(create annotation): use single description for range --- .../dashboard/partials/addAnnotationModal.html | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/public/app/features/dashboard/partials/addAnnotationModal.html b/public/app/features/dashboard/partials/addAnnotationModal.html index 1ea3b7d7a6f..49832075a17 100644 --- a/public/app/features/dashboard/partials/addAnnotationModal.html +++ b/public/app/features/dashboard/partials/addAnnotationModal.html @@ -42,8 +42,7 @@
-
Description
-
Description Start
+
Description
- -
-
-
Description Stop
-
- -
-
diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 5686ef2bfe8..fac9971ece3 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -307,8 +307,8 @@ class GraphCtrl extends MetricsPanelCtrl { } // Get annotation info from dialog and push it to backend - pushAnnotations(annotations) { - return this.annotationsSrv.postAnnotation(annotations); + pushAnnotation(annotation) { + return this.annotationsSrv.postAnnotation(annotation); } showAddAnnotationModal(timeRange) { From 2142323da9fbd623543aa461c357538b269ce86e Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 12 Apr 2017 21:07:39 +0300 Subject: [PATCH 5/6] graph(create annotation): refactor, AddAnnotationModalCtrl --- .../features/dashboard/addAnnotationModalCtrl.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/public/app/features/dashboard/addAnnotationModalCtrl.ts b/public/app/features/dashboard/addAnnotationModalCtrl.ts index 00fa9d8887b..f691da1c0d0 100644 --- a/public/app/features/dashboard/addAnnotationModalCtrl.ts +++ b/public/app/features/dashboard/addAnnotationModalCtrl.ts @@ -4,12 +4,7 @@ import angular from 'angular'; import moment from 'moment'; export class AddAnnotationModalCtrl { - annotationTimeFormat = 'YYYY-MM-DD HH:mm:ss'; - annotationTimeFrom: any; - annotationTimeTo: any = null; - annotationTitle: string; - annotationTextFrom: string; - annotationTextTo: string; + timeFormat = 'YYYY-MM-DD HH:mm:ss'; annotation: any; graphCtrl: any; @@ -29,21 +24,20 @@ export class AddAnnotationModalCtrl { text: "" }; - this.annotation.time = moment($scope.annotationTimeRange.from).format(this.annotationTimeFormat); + this.annotation.time = moment($scope.annotationTimeRange.from).format(this.timeFormat); if ($scope.annotationTimeRange.to) { - this.annotation.timeTo = moment($scope.annotationTimeRange.to).format(this.annotationTimeFormat); + this.annotation.timeTo = moment($scope.annotationTimeRange.to).format(this.timeFormat); } } addAnnotation() { - this.annotation.time = moment(this.annotation.time, this.annotationTimeFormat).valueOf(); + this.annotation.time = moment(this.annotation.time, this.timeFormat).valueOf(); if (this.annotation.timeTo) { - this.annotation.timeTo = moment(this.annotation.timeTo, this.annotationTimeFormat).valueOf(); + this.annotation.timeTo = moment(this.annotation.timeTo, this.timeFormat).valueOf(); } this.graphCtrl.pushAnnotation(this.annotation) .then(response => { - console.log(response); this.close(); }) .catch(error => { From ab99a7c1c7083ea7ad376a2fdd01538c43c3fe89 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 13 Apr 2017 16:57:22 +0300 Subject: [PATCH 6/6] graph(create annotation): add initial annotation_category table --- .../migrations/annotation_category_mig.go | 26 +++++++++++++++++++ .../sqlstore/migrations/migrations.go | 1 + 2 files changed, 27 insertions(+) create mode 100644 pkg/services/sqlstore/migrations/annotation_category_mig.go diff --git a/pkg/services/sqlstore/migrations/annotation_category_mig.go b/pkg/services/sqlstore/migrations/annotation_category_mig.go new file mode 100644 index 00000000000..331aeea2500 --- /dev/null +++ b/pkg/services/sqlstore/migrations/annotation_category_mig.go @@ -0,0 +1,26 @@ +package migrations + +import ( + . "github.com/grafana/grafana/pkg/services/sqlstore/migrator" +) + +func addAnnotationCategoryMig(mg *Migrator) { + category := Table{ + Name: "annotation_category", + Columns: []*Column{ + {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, + {Name: "org_id", Type: DB_BigInt, Nullable: false}, + {Name: "user_id", Type: DB_BigInt, Nullable: true}, + {Name: "name", Type: DB_Text, Nullable: false}, + }, + Indices: []*Index{ + {Cols: []string{"org_id", "name"}, Type: IndexType}, + }, + } + + // create table + mg.AddMigration("create annotation_category table", NewAddTableMigration(category)) + + // create indices + mg.AddMigration("add index org_id & name", NewAddIndexMigration(category, category.Indices[0])) +} diff --git a/pkg/services/sqlstore/migrations/migrations.go b/pkg/services/sqlstore/migrations/migrations.go index 163c6d762a8..e9e20fb190c 100644 --- a/pkg/services/sqlstore/migrations/migrations.go +++ b/pkg/services/sqlstore/migrations/migrations.go @@ -26,6 +26,7 @@ func AddMigrations(mg *Migrator) { addAnnotationMig(mg) addStatsMigrations(mg) addTestDataMigrations(mg) + // addAnnotationCategoryMig(mg) } func addMigrationLogMigrations(mg *Migrator) {