angular-gantt
Version:
Gantt chart component for AngularJS
50 lines (41 loc) • 1.78 kB
JavaScript
(function(){
'use strict';
angular.module('gantt').factory('GanttCurrentDateManager', ['moment', function(moment) {
var GanttCurrentDateManager = function(gantt) {
var self = this;
this.gantt = gantt;
this.date = undefined;
this.position = undefined;
this.currentDateColumn = undefined;
this.gantt.$scope.simplifyMoment = function(d) {
return moment.isMoment(d) ? d.unix() : d;
};
this.gantt.$scope.$watchGroup(['currentDate', 'simplifyMoment(currentDateValue)'], function(newValues, oldValues) {
if (newValues !== oldValues) {
self.setCurrentDate(self.gantt.options.value('currentDateValue'));
}
});
};
GanttCurrentDateManager.prototype.setCurrentDate = function(currentDate) {
this.date = currentDate;
var oldColumn = this.currentDateColumn;
var newColumn;
if (this.date !== undefined && this.gantt.options.value('currentDate') === 'column') {
newColumn = this.gantt.columnsManager.getColumnByDate(this.date, true);
}
this.currentDateColumn = newColumn;
if (oldColumn !== newColumn) {
if (oldColumn !== undefined) {
oldColumn.currentDate = false;
oldColumn.updateView();
}
if (newColumn !== undefined) {
newColumn.currentDate = true;
newColumn.updateView();
}
}
this.position = this.gantt.getPositionByDate(this.date, true);
};
return GanttCurrentDateManager;
}]);
}());