event_editor.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {coreModule} from 'app/core/core';
  4. import {MetricsPanelCtrl} from 'app/plugins/sdk';
  5. import {AnnotationEvent} from './event';
  6. export class EventEditorCtrl {
  7. panelCtrl: MetricsPanelCtrl;
  8. event: AnnotationEvent;
  9. timeRange: {from: number, to: number};
  10. form: any;
  11. close: any;
  12. /** @ngInject **/
  13. constructor(private annotationsSrv) {
  14. this.event.panelId = this.panelCtrl.panel.id;
  15. this.event.dashboardId = this.panelCtrl.dashboard.id;
  16. }
  17. save() {
  18. if (!this.form.$valid) {
  19. return;
  20. }
  21. let saveModel = _.cloneDeep(this.event);
  22. saveModel.time = saveModel.time.valueOf();
  23. saveModel.timeEnd = 0;
  24. if (saveModel.isRegion) {
  25. saveModel.timeEnd = saveModel.timeEnd.valueOf();
  26. if (saveModel.timeEnd < saveModel.time) {
  27. console.log('invalid time');
  28. return;
  29. }
  30. }
  31. this.annotationsSrv.saveAnnotationEvent(saveModel).then(() => {
  32. this.panelCtrl.refresh();
  33. this.close();
  34. });
  35. }
  36. timeChanged() {
  37. this.panelCtrl.render();
  38. }
  39. }
  40. export function eventEditor() {
  41. return {
  42. restrict: 'E',
  43. controller: EventEditorCtrl,
  44. bindToController: true,
  45. controllerAs: 'ctrl',
  46. templateUrl: 'public/app/features/annotations/partials/event_editor.html',
  47. scope: {
  48. "panelCtrl": "=",
  49. "event": "=",
  50. "close": "&",
  51. }
  52. };
  53. }
  54. coreModule.directive('eventEditor', eventEditor);