addAnnotationModalCtrl.ts 1.1 KB

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