angular-gantt
Version:
Gantt chart component for AngularJS
262 lines (219 loc) • 10.5 kB
JavaScript
/*
Project: angular-gantt v1.2.9 - Gantt chart component for AngularJS
Authors: Marco Schweighauser, Rémi Alvergnat
License: MIT
Homepage: https://www.angular-gantt.com
Github: https://github.com/angular-gantt/angular-gantt.git
*/
(function(){
'use strict';
angular.module('gantt.groups', ['gantt', 'gantt.groups.templates']).directive('ganttGroups', ['ganttUtils', 'GanttHierarchy', '$compile', '$document', function(utils, Hierarchy, $compile, $document) {
// Provides the row sort functionality to any Gantt row
// Uses the sortableState to share the current row
return {
restrict: 'E',
require: '^gantt',
scope: {
enabled: '=?',
display: '=?'
},
link: function(scope, element, attrs, ganttCtrl) {
var api = ganttCtrl.gantt.api;
// Load options from global options attribute.
if (scope.options && typeof(scope.options.sortable) === 'object') {
for (var option in scope.options.sortable) {
scope[option] = scope.options[option];
}
}
if (scope.enabled === undefined) {
scope.enabled = true;
}
if (scope.display === undefined) {
scope.display = 'group';
}
scope.hierarchy = new Hierarchy();
function refresh() {
scope.hierarchy.refresh(ganttCtrl.gantt.rowsManager.filteredRows);
}
ganttCtrl.gantt.api.registerMethod('groups', 'refresh', refresh, this);
ganttCtrl.gantt.$scope.$watchCollection('gantt.rowsManager.filteredRows', function() {
refresh();
});
api.directives.on.new(scope, function(directiveName, rowScope, rowElement) {
if (directiveName === 'ganttRow') {
var taskGroupScope = rowScope.$new();
taskGroupScope.pluginScope = scope;
var ifElement = $document[0].createElement('div');
angular.element(ifElement).attr('data-ng-if', 'pluginScope.enabled');
var taskGroupElement = $document[0].createElement('gantt-task-group');
if (attrs.templateUrl !== undefined) {
angular.element(taskGroupElement).attr('data-template-url', attrs.templateUrl);
}
if (attrs.template !== undefined) {
angular.element(taskGroupElement).attr('data-template', attrs.template);
}
angular.element(ifElement).append(taskGroupElement);
rowElement.append($compile(ifElement)(taskGroupScope));
}
});
}
};
}]);
}());
(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);
}]);
}());
(function(){
'use strict';
angular.module('gantt.groups').directive('ganttTaskGroup', ['GanttDirectiveBuilder', function(Builder) {
var builder = new Builder('ganttTaskGroup', 'plugins/groups/taskGroup.tmpl.html');
return builder.build();
}]);
}());
(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;
}]);
}());
(function(){
'use strict';
angular.module('gantt').directive('ganttTaskOverview', ['GanttDirectiveBuilder', function(Builder) {
var builder = new Builder('ganttTaskOverview', 'plugins/groups/taskOverview.tmpl.html');
builder.controller = function($scope, $element) {
$scope.task.$element = $element;
$scope.task.$scope = $scope;
$scope.task.updatePosAndSize();
};
return builder.build();
}]);
}());
angular.module('gantt.groups.templates', []).run(['$templateCache', function($templateCache) {
$templateCache.put('plugins/groups/taskGroup.tmpl.html',
'<div ng-controller="GanttGroupController">\n' +
' <div class="gantt-task-group-overview" ng-if="taskGroup.overviewTasks.length > 0">\n' +
' <gantt-task-overview ng-repeat="task in taskGroup.overviewTasks"></gantt-task-overview>\n' +
' </div>\n' +
' <div class="gantt-task-group-promote" ng-if="taskGroup.row._collapsed && taskGroup.promotedTasks.length > 0">\n' +
' <gantt-task ng-repeat="task in taskGroup.promotedTasks"></gantt-task>\n' +
' </div>\n' +
' <div class="gantt-task-group"\n' +
' ng-if="taskGroup.showGrouping"\n' +
' ng-style="{\'left\': taskGroup.left + \'px\', \'width\': taskGroup.width + \'px\'}">\n' +
' <div class="gantt-task-group-left-main"></div>\n' +
' <div class="gantt-task-group-right-main"></div>\n' +
' <div class="gantt-task-group-left-symbol"></div>\n' +
' <div class="gantt-task-group-right-symbol"></div>\n' +
' </div>\n' +
'</div>\n' +
'\n' +
'');
$templateCache.put('plugins/groups/taskOverview.tmpl.html',
'<div class="gantt-task gantt-task-overview" ng-class="task.model.classes">\n' +
' <gantt-task-background></gantt-task-background>\n' +
' <gantt-task-content></gantt-task-content>\n' +
' <gantt-task-foreground></gantt-task-foreground>\n' +
'</div>\n' +
'\n' +
'');
}]);
//# sourceMappingURL=angular-gantt-groups-plugin.js.map