From ff426ae9a37d31d16292f3c77619be4a0fc3593b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Apr 2017 12:23:32 +0200 Subject: [PATCH] more work on annotations --- public/app/core/services/popover_srv.ts | 42 +++++++++++-------- .../features/annotations/annotations_srv.ts | 1 + .../app/features/annotations/event_editor.ts | 11 +++-- .../annotations/partials/event_editor.html | 2 +- public/app/features/dashboard/all.js | 1 - public/app/plugins/panel/graph/graph.ts | 4 +- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/public/app/core/services/popover_srv.ts b/public/app/core/services/popover_srv.ts index 43afde31849..9cd13dfc280 100644 --- a/public/app/core/services/popover_srv.ts +++ b/public/app/core/services/popover_srv.ts @@ -19,6 +19,7 @@ function popoverSrv($compile, $rootScope, $timeout) { this.show = function(options) { if (openDrop) { openDrop.close(); + openDrop = null; } var scope = _.extend($rootScope.$new(true), options.model); @@ -27,12 +28,17 @@ function popoverSrv($compile, $rootScope, $timeout) { var cleanUp = () => { setTimeout(() => { scope.$destroy(); - drop.destroy(); + + if (drop.tether) { + drop.destroy(); + } if (options.onClose) { options.onClose(); } }); + + openDrop = null; }; scope.dismiss = () => { @@ -44,24 +50,26 @@ function popoverSrv($compile, $rootScope, $timeout) { $compile(contentElement)(scope); - drop = new Drop({ - target: options.element, - content: contentElement, - position: options.position, - classes: options.classNames || 'drop-popover', - openOn: options.openOn, - hoverCloseDelay: 200, - tetherOptions: { - constraints: [{to: 'scrollParent', attachment: "none both"}] - } - }); + $timeout(() => { + drop = new Drop({ + target: options.element, + content: contentElement, + position: options.position, + classes: options.classNames || 'drop-popover', + openOn: options.openOn, + hoverCloseDelay: 200, + tetherOptions: { + constraints: [{to: 'scrollParent', attachment: "none both"}] + } + }); - drop.on('close', () => { - cleanUp(); - }); + drop.on('close', () => { + cleanUp(); + }); - openDrop = drop; - $timeout(() => { drop.open(); }, 10); + openDrop = drop; + openDrop.open(); + }, 10); }; } diff --git a/public/app/features/annotations/annotations_srv.ts b/public/app/features/annotations/annotations_srv.ts index e9cdc0c20ec..310f565804c 100644 --- a/public/app/features/annotations/annotations_srv.ts +++ b/public/app/features/annotations/annotations_srv.ts @@ -135,6 +135,7 @@ export class AnnotationsSrv { } saveAnnotationEvent(annotation) { + this.globalAnnotationsPromise = null; return this.backendSrv.post('/api/annotations', annotation); } diff --git a/public/app/features/annotations/event_editor.ts b/public/app/features/annotations/event_editor.ts index 46e29a660a9..dc811661111 100644 --- a/public/app/features/annotations/event_editor.ts +++ b/public/app/features/annotations/event_editor.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import moment from 'moment'; -import coreModule from 'app/core/core_module'; +import {coreModule} from 'app/core/core'; import {MetricsPanelCtrl} from 'app/plugins/sdk'; export class AnnotationEvent { @@ -20,13 +20,13 @@ export class EventEditorCtrl { annotation: AnnotationEvent; timeRange: {from: number, to: number}; form: any; + close: any; /** @ngInject **/ constructor(private annotationsSrv) { this.annotation = new AnnotationEvent(); this.annotation.panelId = this.panelCtrl.panel.id; this.annotation.dashboardId = this.panelCtrl.dashboard.id; - this.annotation.text = "hello"; this.annotation.time = moment(this.timeRange.from); if (this.timeRange.to) { @@ -51,7 +51,10 @@ export class EventEditorCtrl { return; } - this.annotationsSrv.saveAnnotationEvent(saveModel); + this.annotationsSrv.saveAnnotationEvent(saveModel).then(() => { + this.panelCtrl.refresh(); + this.close(); + }); } } @@ -65,7 +68,7 @@ export function eventEditor() { scope: { "panelCtrl": "=", "timeRange": "=", - "cancel": "&", + "close": "&", } }; } diff --git a/public/app/features/annotations/partials/event_editor.html b/public/app/features/annotations/partials/event_editor.html index c2a75e92603..9454024c801 100644 --- a/public/app/features/annotations/partials/event_editor.html +++ b/public/app/features/annotations/partials/event_editor.html @@ -32,7 +32,7 @@
- Cancel + Cancel
diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index c3a71a11818..c362f9cd032 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -7,7 +7,6 @@ define([ './saveDashboardAsCtrl', './shareModalCtrl', './shareSnapshotCtrl', - './addAnnotationModalCtrl', './dashboard_srv', './viewStateSrv', './time_srv', diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 668f1973b42..f3a7f78b887 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -84,8 +84,8 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv, popoverSrv) { element: elem[0], classNames: 'drop-popover drop-popover--form', position: 'bottom center', - openOn: null, - template: '', + openOn: 'click', + template: '', model: { timeRange: timeRange, panelCtrl: ctrl,