angular-gantt
Version:
Gantt chart component for AngularJS
69 lines (55 loc) • 2.79 kB
JavaScript
(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));
}
});
}
};
}]);
}());