Files
grafana/public/app/features/annotations/event_editor.ts

66 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-04-14 10:18:49 +02:00
///<reference path="../../headers/common.d.ts" />
import _ from 'lodash';
2017-04-14 12:23:32 +02:00
import {coreModule} from 'app/core/core';
2017-04-14 10:18:49 +02:00
import {MetricsPanelCtrl} from 'app/plugins/sdk';
import {AnnotationEvent} from './event';
2017-04-14 10:18:49 +02:00
export class EventEditorCtrl {
panelCtrl: MetricsPanelCtrl;
2017-04-14 14:43:06 +02:00
event: AnnotationEvent;
2017-04-14 10:18:49 +02:00
timeRange: {from: number, to: number};
form: any;
2017-04-14 12:23:32 +02:00
close: any;
2017-04-14 10:18:49 +02:00
/** @ngInject **/
2017-04-14 11:41:02 +02:00
constructor(private annotationsSrv) {
2017-04-14 14:43:06 +02:00
this.event.panelId = this.panelCtrl.panel.id;
this.event.dashboardId = this.panelCtrl.dashboard.id;
2017-04-14 10:18:49 +02:00
}
save() {
if (!this.form.$valid) {
return;
}
2017-04-14 11:41:02 +02:00
2017-04-14 14:43:06 +02:00
let saveModel = _.cloneDeep(this.event);
2017-04-14 11:41:02 +02:00
saveModel.time = saveModel.time.valueOf();
2017-04-14 14:43:06 +02:00
saveModel.timeEnd = 0;
2017-04-14 11:41:02 +02:00
if (saveModel.isRegion) {
saveModel.timeEnd = saveModel.timeEnd.valueOf();
2017-04-14 14:43:06 +02:00
if (saveModel.timeEnd < saveModel.time) {
console.log('invalid time');
return;
}
2017-04-14 11:41:02 +02:00
}
2017-04-14 12:23:32 +02:00
this.annotationsSrv.saveAnnotationEvent(saveModel).then(() => {
this.panelCtrl.refresh();
this.close();
});
2017-04-14 10:18:49 +02:00
}
2017-04-14 14:43:06 +02:00
timeChanged() {
this.panelCtrl.render();
}
2017-04-14 10:18:49 +02:00
}
export function eventEditor() {
return {
restrict: 'E',
controller: EventEditorCtrl,
bindToController: true,
controllerAs: 'ctrl',
templateUrl: 'public/app/features/annotations/partials/event_editor.html',
scope: {
"panelCtrl": "=",
2017-04-14 14:43:06 +02:00
"event": "=",
2017-04-14 12:23:32 +02:00
"close": "&",
2017-04-14 10:18:49 +02:00
}
};
}
coreModule.directive('eventEditor', eventEditor);