addAnnotationModalCtrl.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import moment from 'moment';
  4. export class AddAnnotationModalCtrl {
  5. timeFormat = 'YYYY-MM-DD HH:mm:ss';
  6. annotation: any;
  7. graphCtrl: any;
  8. /** @ngInject */
  9. constructor(private $scope) {
  10. this.graphCtrl = $scope.ctrl;
  11. $scope.ctrl = this;
  12. let dashboardId = this.graphCtrl.dashboard.id;
  13. let panelId = this.graphCtrl.panel.id;
  14. this.annotation = {
  15. dashboardId: dashboardId,
  16. panelId: panelId,
  17. time: null,
  18. timeTo: null,
  19. title: "",
  20. text: ""
  21. };
  22. this.annotation.time = moment($scope.annotationTimeRange.from).format(this.timeFormat);0
  23. if ($scope.annotationTimeRange.to) {
  24. this.annotation.timeTo = moment($scope.annotationTimeRange.to).format(this.timeFormat);
  25. }
  26. }
  27. addAnnotation() {
  28. this.annotation.time = moment(this.annotation.time, this.timeFormat).valueOf();
  29. if (this.annotation.timeTo) {
  30. this.annotation.timeTo = moment(this.annotation.timeTo, this.timeFormat).valueOf();
  31. }
  32. this.graphCtrl.pushAnnotation(this.annotation)
  33. .then(response => {
  34. this.close();
  35. })
  36. .catch(error => {
  37. console.log(error);
  38. this.close();
  39. });
  40. }
  41. close() {
  42. this.$scope.dismiss();
  43. }
  44. }
  45. angular
  46. .module('grafana.controllers')
  47. .controller('AddAnnotationModalCtrl', AddAnnotationModalCtrl);