angular-gantt
Version:
Gantt chart component for AngularJS
51 lines (41 loc) • 1.96 kB
JavaScript
(function(){
'use strict';
angular.module('gantt.groups').controller('GanttGroupController', ['$scope', 'GanttTaskGroup', 'ganttUtils', function($scope, TaskGroup, utils) {
var updateTaskGroup = function() {
var rowGroups = $scope.row.model.groups;
if (typeof(rowGroups) === 'boolean') {
rowGroups = {enabled: rowGroups};
}
var enabledValue = utils.firstProperty([rowGroups], 'enabled', $scope.pluginScope.enabled);
if (enabledValue) {
$scope.display = utils.firstProperty([rowGroups], 'display', $scope.pluginScope.display);
$scope.taskGroup = new TaskGroup($scope.row, $scope.pluginScope);
$scope.row.setFromTo();
$scope.row.setFromToByValues($scope.taskGroup.from, $scope.taskGroup.to);
} else {
$scope.taskGroup = undefined;
$scope.display = undefined;
}
};
$scope.gantt.api.tasks.on.change($scope, function(task) {
if ($scope.taskGroup !== undefined) {
if ($scope.taskGroup.tasks.indexOf(task) > -1) {
$scope.$evalAsync(function() {
updateTaskGroup();
});
} else {
var descendants = $scope.pluginScope.hierarchy.descendants($scope.row);
if (descendants.indexOf(task.row) > -1) {
$scope.$evalAsync(function() {
updateTaskGroup();
});
}
}
}
});
var removeWatch = $scope.pluginScope.$watch('display', updateTaskGroup);
$scope.$watchCollection('gantt.rowsManager.filteredRows', updateTaskGroup);
$scope.gantt.api.columns.on.refresh($scope, updateTaskGroup);
$scope.$on('$destroy', removeWatch);
}]);
}());