event_editor.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import moment from 'moment';
  4. import coreModule from 'app/core/core_module';
  5. import {MetricsPanelCtrl} from 'app/plugins/sdk';
  6. export class AnnotationItem {
  7. dashboardId: number;
  8. panelId: number;
  9. time: Date;
  10. timeEnd: Date;
  11. isRegion: boolean;
  12. title: string;
  13. text: string;
  14. }
  15. export class EventEditorCtrl {
  16. panelCtrl: MetricsPanelCtrl;
  17. timeFormat = 'YYYY-MM-DD HH:mm:ss';
  18. annotation: AnnotationItem;
  19. timeRange: {from: number, to: number};
  20. form: any;
  21. /** @ngInject **/
  22. constructor() {
  23. this.annotation = new AnnotationItem();
  24. this.annotation.panelId = this.panelCtrl.panel.id;
  25. this.annotation.dashboardId = this.panelCtrl.dashboard.id;
  26. this.annotation.text = "hello";
  27. this.annotation.time = moment(this.timeRange.from);
  28. if (this.timeRange.to) {
  29. this.annotation.timeEnd = moment(this.timeRange.to);
  30. this.annotation.isRegion = true;
  31. }
  32. }
  33. save() {
  34. if (!this.form.$valid) {
  35. return;
  36. }
  37. }
  38. }
  39. export function eventEditor() {
  40. return {
  41. restrict: 'E',
  42. controller: EventEditorCtrl,
  43. bindToController: true,
  44. controllerAs: 'ctrl',
  45. templateUrl: 'public/app/features/annotations/partials/event_editor.html',
  46. scope: {
  47. "panelCtrl": "=",
  48. "timeRange": "="
  49. }
  50. };
  51. }
  52. coreModule.directive('eventEditor', eventEditor);