diff --git a/public/app/features/annotations/annotations_srv.ts b/public/app/features/annotations/annotations_srv.ts
index 759e4500c7d..f50fce8e08a 100644
--- a/public/app/features/annotations/annotations_srv.ts
+++ b/public/app/features/annotations/annotations_srv.ts
@@ -126,6 +126,18 @@ export class AnnotationsSrv {
return this.globalAnnotationsPromise;
}
+ postAnnotation(annotation) {
+ console.log("POST /api/annotations\n", annotation);
+
+ // Not implemented yet
+ let implemented = false;
+ if (implemented) {
+ return this.backendSrv.post('/api/annotations', annotation);
+ } else {
+ return Promise.resolve("Not implemented");
+ }
+ }
+
translateQueryResult(annotation, results) {
for (var item of results) {
item.source = annotation;
diff --git a/public/app/features/dashboard/addAnnotationModalCtrl.ts b/public/app/features/dashboard/addAnnotationModalCtrl.ts
new file mode 100644
index 00000000000..0967eda14b1
--- /dev/null
+++ b/public/app/features/dashboard/addAnnotationModalCtrl.ts
@@ -0,0 +1,49 @@
+///
+
+import angular from 'angular';
+import moment from 'moment';
+
+export class AddAnnotationModalCtrl {
+ annotationTime: any;
+ annotationTimeFormat = 'YYYY-MM-DD HH:mm:ss';
+ annotation: any;
+ graphCtrl: any;
+
+ /** @ngInject */
+ constructor(private $scope) {
+ this.graphCtrl = $scope.ctrl;
+ $scope.ctrl = this;
+
+ this.annotation = {
+ time: null,
+ title: "",
+ text: ""
+ };
+
+ this.annotationTime = moment(this.$scope.annotationTimeUnix).format(this.annotationTimeFormat);
+ }
+
+ addAnnotation() {
+ let time = moment(this.annotationTime, this.annotationTimeFormat);
+ this.annotation.time = time.valueOf();
+
+ this.graphCtrl.pushAnnotation(this.annotation)
+ .then(response => {
+ console.log(response);
+ this.close();
+ })
+ .catch(error => {
+ console.log(error);
+ this.close();
+ });
+ }
+
+ close() {
+ this.graphCtrl.inAddAnnotationMode = false;
+ this.$scope.dismiss();
+ }
+}
+
+angular
+ .module('grafana.controllers')
+ .controller('AddAnnotationModalCtrl', AddAnnotationModalCtrl);
diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js
index c362f9cd032..c3a71a11818 100644
--- a/public/app/features/dashboard/all.js
+++ b/public/app/features/dashboard/all.js
@@ -7,6 +7,7 @@ define([
'./saveDashboardAsCtrl',
'./shareModalCtrl',
'./shareSnapshotCtrl',
+ './addAnnotationModalCtrl',
'./dashboard_srv',
'./viewStateSrv',
'./time_srv',
diff --git a/public/app/features/dashboard/partials/addAnnotationModal.html b/public/app/features/dashboard/partials/addAnnotationModal.html
new file mode 100644
index 00000000000..f16656bba77
--- /dev/null
+++ b/public/app/features/dashboard/partials/addAnnotationModal.html
@@ -0,0 +1,62 @@
+
+
diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts
index 5a684a42fd3..3a75c189dbd 100755
--- a/public/app/plugins/panel/graph/graph.ts
+++ b/public/app/plugins/panel/graph/graph.ts
@@ -79,6 +79,14 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
}
}, scope);
+ appEvents.on('graph-click', (event) => {
+
+ // Select time for new annotation
+ if (ctrl.inAddAnnotationMode) {
+ ctrl.showAddAnnotationModal(event);
+ }
+ }, scope);
+
function getLegendHeight(panelHeight) {
if (!panel.legend.show || panel.legend.rightSide) {
return 0;
diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts
index e98d1c25ad7..b8ab763550b 100644
--- a/public/app/plugins/panel/graph/module.ts
+++ b/public/app/plugins/panel/graph/module.ts
@@ -24,6 +24,7 @@ class GraphCtrl extends MetricsPanelCtrl {
dataList: any = [];
annotations: any = [];
alertState: any;
+ inAddAnnotationMode = false;
annotationsPromise: any;
dataWarning: any;
@@ -144,6 +145,7 @@ class GraphCtrl extends MetricsPanelCtrl {
actions.push({text: 'Export CSV (series as rows)', click: 'ctrl.exportCsv()'});
actions.push({text: 'Export CSV (series as columns)', click: 'ctrl.exportCsvColumns()'});
actions.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'});
+ actions.push({ text: 'Add Annotation', click: 'ctrl.enableAddAnnotationMode()' });
}
issueQueries(datasource) {
@@ -300,6 +302,27 @@ class GraphCtrl extends MetricsPanelCtrl {
this.refresh();
}
+ enableAddAnnotationMode() {
+ // TODO: notify user about time selection mode
+ this.inAddAnnotationMode = true;
+ }
+
+ // Get annotation info from dialog and push it to backend
+ pushAnnotation(annotation) {
+ return this.annotationsSrv.postAnnotation(annotation);
+ }
+
+ showAddAnnotationModal(event) {
+ let addAnnotationScope = this.$scope.$new();
+ let annotationTimeUnix = Math.round(event.pos.x);
+ addAnnotationScope.annotationTimeUnix = annotationTimeUnix;
+
+ this.publishAppEvent('show-modal', {
+ src: 'public/app/features/dashboard/partials/addAnnotationModal.html',
+ scope: addAnnotationScope
+ });
+ }
+
legendValuesOptionChanged() {
var legend = this.panel.legend;
legend.values = legend.min || legend.max || legend.avg || legend.current || legend.total;