graph(create annotation): refactor, AddAnnotationModalCtrl

This commit is contained in:
Alexander Zobnin
2017-04-12 21:07:39 +03:00
parent 17d3970673
commit 2142323da9

View File

@@ -4,12 +4,7 @@ import angular from 'angular';
import moment from 'moment';
export class AddAnnotationModalCtrl {
annotationTimeFormat = 'YYYY-MM-DD HH:mm:ss';
annotationTimeFrom: any;
annotationTimeTo: any = null;
annotationTitle: string;
annotationTextFrom: string;
annotationTextTo: string;
timeFormat = 'YYYY-MM-DD HH:mm:ss';
annotation: any;
graphCtrl: any;
@@ -29,21 +24,20 @@ export class AddAnnotationModalCtrl {
text: ""
};
this.annotation.time = moment($scope.annotationTimeRange.from).format(this.annotationTimeFormat);
this.annotation.time = moment($scope.annotationTimeRange.from).format(this.timeFormat);
if ($scope.annotationTimeRange.to) {
this.annotation.timeTo = moment($scope.annotationTimeRange.to).format(this.annotationTimeFormat);
this.annotation.timeTo = moment($scope.annotationTimeRange.to).format(this.timeFormat);
}
}
addAnnotation() {
this.annotation.time = moment(this.annotation.time, this.annotationTimeFormat).valueOf();
this.annotation.time = moment(this.annotation.time, this.timeFormat).valueOf();
if (this.annotation.timeTo) {
this.annotation.timeTo = moment(this.annotation.timeTo, this.annotationTimeFormat).valueOf();
this.annotation.timeTo = moment(this.annotation.timeTo, this.timeFormat).valueOf();
}
this.graphCtrl.pushAnnotation(this.annotation)
.then(response => {
console.log(response);
this.close();
})
.catch(error => {