diff --git a/public/app/features/annotations/all.ts b/public/app/features/annotations/all.ts
index 0be292a7fa1..cde82c24a48 100644
--- a/public/app/features/annotations/all.ts
+++ b/public/app/features/annotations/all.ts
@@ -1,8 +1,9 @@
import {AnnotationsSrv} from './annotations_srv';
-import {eventEditor} from './event_editor';
+import {eventEditor, EventManager} from './event_editor';
export {
AnnotationsSrv,
- eventEditor
+ eventEditor,
+ EventManager
};
diff --git a/public/app/features/annotations/event_editor.ts b/public/app/features/annotations/event_editor.ts
index dc811661111..737e48d3776 100644
--- a/public/app/features/annotations/event_editor.ts
+++ b/public/app/features/annotations/event_editor.ts
@@ -17,22 +17,15 @@ export class AnnotationEvent {
export class EventEditorCtrl {
panelCtrl: MetricsPanelCtrl;
- annotation: AnnotationEvent;
+ event: 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.time = moment(this.timeRange.from);
- if (this.timeRange.to) {
- this.annotation.timeEnd = moment(this.timeRange.to);
- this.annotation.isRegion = true;
- }
+ this.event.panelId = this.panelCtrl.panel.id;
+ this.event.dashboardId = this.panelCtrl.dashboard.id;
}
save() {
@@ -40,15 +33,17 @@ export class EventEditorCtrl {
return;
}
- let saveModel = _.cloneDeep(this.annotation);
+ let saveModel = _.cloneDeep(this.event);
saveModel.time = saveModel.time.valueOf();
+ saveModel.timeEnd = 0;
+
if (saveModel.isRegion) {
saveModel.timeEnd = saveModel.timeEnd.valueOf();
- }
- if (saveModel.timeEnd < saveModel.time) {
- console.log('invalid time');
- return;
+ if (saveModel.timeEnd < saveModel.time) {
+ console.log('invalid time');
+ return;
+ }
}
this.annotationsSrv.saveAnnotationEvent(saveModel).then(() => {
@@ -56,6 +51,10 @@ export class EventEditorCtrl {
this.close();
});
}
+
+ timeChanged() {
+ this.panelCtrl.render();
+ }
}
export function eventEditor() {
@@ -67,10 +66,68 @@ export function eventEditor() {
templateUrl: 'public/app/features/annotations/partials/event_editor.html',
scope: {
"panelCtrl": "=",
- "timeRange": "=",
+ "event": "=",
"close": "&",
}
};
}
coreModule.directive('eventEditor', eventEditor);
+
+export class EventManager {
+ event: AnnotationEvent;
+
+ constructor(private panelCtrl: MetricsPanelCtrl,
+ private elem,
+ private popoverSrv) {
+ }
+
+ editorClosed() {
+ console.log('editorClosed');
+ this.event = null;
+ this.panelCtrl.render();
+ }
+
+ updateTime(range) {
+ let newEvent = true;
+
+ if (this.event) {
+ newEvent = false;
+ } else {
+ // init new event
+ this.event = new AnnotationEvent();
+ this.event.dashboardId = this.panelCtrl.dashboard.id;
+ this.event.panelId = this.panelCtrl.panel.id;
+ }
+
+ // update time
+ this.event.time = moment(range.from);
+ this.event.isRegion = false;
+ if (range.to) {
+ this.event.timeEnd = moment(range.to);
+ this.event.isRegion = true;
+ }
+
+ // newEvent means the editor is not visible
+ if (!newEvent) {
+ this.panelCtrl.render();
+ return;
+ }
+
+ this.popoverSrv.show({
+ element: this.elem[0],
+ classNames: 'drop-popover drop-popover--form',
+ position: 'bottom center',
+ openOn: null,
+ template: '