OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/assets/javascripts/angular/helpers/timeline-table-helper.js

74 lines
2.3 KiB

angular.module('openproject.timelines.helpers')
.factory('TimelineTableHelper', [function() {
var NodeFilter = function(options) {
this.options = options;
};
NodeFilter.prototype.memberOfHiddenOtherGroup = function(node) {
return this.options && this.options.hide_other_group === 'yes' && node.level === 1 && node.payload.objectType === 'Project' && node.payload.getFirstLevelGrouping() === 0;
};
NodeFilter.prototype.hiddenOrFilteredOut = function(node) {
var nodeObject = node.payload;
return nodeObject.hide() || nodeObject.filteredOut();
};
NodeFilter.prototype.nodeExcluded = function(node) {
return this.hiddenOrFilteredOut(node) || this.memberOfHiddenOtherGroup(node);
};
TimelineTableHelper = {
flattenTimelineTree: function(root, filterCallback, processNodeCallback){
var nodes = [];
angular.forEach(root.childNodes, function(node){
if (!filterCallback(node)) {
// add relevant information to row
if (processNodeCallback) processNodeCallback(node, root);
// add subtree to nodes
nodes.push(node);
nodes = nodes.concat(TimelineTableHelper.flattenTimelineTree(node, filterCallback, processNodeCallback));
}
});
return nodes;
},
addRowDataToNode: function(node, parent) {
// ancestors
if (parent) {
node.ancestors = [parent];
if(parent.ancestors) node.ancestors = parent.ancestors.concat(node.ancestors);
}
// first level group
isNested = node.level >= 2;
if (node.payload.objectType === 'Project' && !isNested) {
node.firstLevelGroup = node.payload.getFirstLevelGrouping();
node.firstLevelGroupingName = node.payload.getFirstLevelGroupingName();
} else {
// inherit group from parent
node.firstLevelGroup = parent.firstLevelGroup;
}
},
getTableRowsFromTimelineTree: function(tree, options) {
nodeFilter = new NodeFilter(options);
// add relevant information to tree root serving as first row
TimelineTableHelper.addRowDataToNode(tree);
rows = TimelineTableHelper.flattenTimelineTree(tree, function(node) { return nodeFilter.nodeExcluded(node); }, TimelineTableHelper.addRowDataToNode);
rows.unshift(tree);
return rows;
}
};
return TimelineTableHelper;
}]);