UNPKG

angular-gantt

Version:

Gantt chart component for AngularJS

82 lines (67 loc) 3.05 kB
(function(){ 'use strict'; angular.module('gantt').factory('GanttTaskGroup', ['ganttUtils', 'GanttTask', function(utils, Task) { var TaskGroup = function (row, pluginScope) { var self = this; self.row = row; self.pluginScope = pluginScope; self.descendants = self.pluginScope.hierarchy.descendants(self.row); self.tasks = []; self.overviewTasks = []; self.promotedTasks = []; self.showGrouping = false; var groupRowGroups = self.row.model.groups; if (typeof(groupRowGroups) === 'boolean') { groupRowGroups = {enabled: groupRowGroups}; } var getTaskDisplay = function(task) { var taskGroups = task.model.groups; if (typeof(taskGroups) === 'boolean') { taskGroups = {enabled: taskGroups}; } var rowGroups = task.row.model.groups; if (typeof(rowGroups) === 'boolean') { rowGroups = {enabled: rowGroups}; } var enabledValue = utils.firstProperty([taskGroups, rowGroups, groupRowGroups], 'enabled', self.pluginScope.enabled); if (enabledValue) { var display = utils.firstProperty([taskGroups, rowGroups, groupRowGroups], 'display', self.pluginScope.display); return display; } }; angular.forEach(self.descendants, function(descendant) { angular.forEach(descendant.tasks, function(task) { var taskDisplay = getTaskDisplay(task); if (taskDisplay !== undefined) { self.tasks.push(task); var clone = new Task(self.row, task.model); if (taskDisplay === 'overview') { self.overviewTasks.push(clone); } else if(taskDisplay === 'promote'){ self.promotedTasks.push(clone); } else { self.showGrouping = true; } } }); }); self.from = undefined; angular.forEach(self.tasks, function (task) { if (self.from === undefined || task.model.from < self.from) { self.from = task.model.from; } }); self.to = undefined; angular.forEach(self.tasks, function (task) { if (self.to === undefined || task.model.to > self.to) { self.to = task.model.to; } }); if (self.showGrouping) { self.left = row.rowsManager.gantt.getPositionByDate(self.from); self.width = row.rowsManager.gantt.getPositionByDate(self.to) - self.left; } }; return TaskGroup; }]); }());