UNPKG

angular-gantt

Version:

Gantt chart component for AngularJS

58 lines (49 loc) 2.55 kB
(function(){ 'use strict'; angular.module('gantt.progress', ['gantt', 'gantt.progress.templates']).directive('ganttProgress', ['moment', '$compile', '$document', function(moment, $compile, $document) { return { restrict: 'E', require: '^gantt', scope: { enabled: '=?' }, link: function(scope, element, attrs, ganttCtrl) { var api = ganttCtrl.gantt.api; // Load options from global options attribute. if (scope.options && typeof(scope.options.progress) === 'object') { for (var option in scope.options.progress) { scope[option] = scope.options[option]; } } if (scope.enabled === undefined) { scope.enabled = true; } api.directives.on.new(scope, function(directiveName, taskScope, taskElement) { if (directiveName === 'ganttTaskBackground') { var progressScope = taskScope.$new(); progressScope.pluginScope = scope; var ifElement = $document[0].createElement('div'); angular.element(ifElement).attr('data-ng-if', 'task.model.progress !== undefined && pluginScope.enabled'); var progressElement = $document[0].createElement('gantt-task-progress'); if (attrs.templateUrl !== undefined) { angular.element(progressElement).attr('data-template-url', attrs.templateUrl); } if (attrs.template !== undefined) { angular.element(progressElement).attr('data-template', attrs.template); } angular.element(ifElement).append(progressElement); taskElement.append($compile(ifElement)(progressScope)); } }); api.tasks.on.clean(scope, function(model) { if (model.est !== undefined && !moment.isMoment(model.est)) { model.est = moment(model.est); //Earliest Start Time } if (model.lct !== undefined && !moment.isMoment(model.lct)) { model.lct = moment(model.lct); //Latest Completion Time } }); } }; }]); }());