kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
180 lines
5.5 KiB
180 lines
5.5 KiB
11 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
10 years ago
|
module.exports = function(WorkPackagesHelper) {
|
||
11 years ago
|
var WorkPackagesTableHelper = {
|
||
11 years ago
|
/* builds rows from work packages, see IssuesHelper */
|
||
11 years ago
|
buildRows: function(workPackages, groupBy) {
|
||
11 years ago
|
var rows = [], ancestors = [];
|
||
11 years ago
|
var currentGroup, allGroups = [], groupIndex = -1;
|
||
11 years ago
|
|
||
|
angular.forEach(workPackages, function(workPackage, i) {
|
||
10 years ago
|
while(ancestors.length > 0 && workPackage.parent_id !== _.last(ancestors).object.id) {
|
||
11 years ago
|
// this helper method only reflects hierarchies if nested work packages follow one another
|
||
11 years ago
|
ancestors.pop();
|
||
|
}
|
||
|
|
||
11 years ago
|
|
||
|
// compose row
|
||
|
|
||
11 years ago
|
var row = {
|
||
|
level: ancestors.length,
|
||
10 years ago
|
parent: _.last(ancestors),
|
||
11 years ago
|
ancestors: ancestors.slice(0),
|
||
11 years ago
|
object: workPackage
|
||
|
};
|
||
11 years ago
|
|
||
11 years ago
|
// manage groups
|
||
|
|
||
|
// this helper method assumes that the work packages are passed in in blocks each of which consisting of work packages which belong to one group
|
||
|
|
||
|
if (groupBy) {
|
||
|
currentGroup = WorkPackagesHelper.getRowObjectContent(workPackage, groupBy);
|
||
|
|
||
|
if(allGroups.indexOf(currentGroup) === -1) {
|
||
|
allGroups.push(currentGroup);
|
||
|
groupIndex++;
|
||
|
}
|
||
|
|
||
|
angular.extend(row, {
|
||
|
groupIndex: groupIndex,
|
||
|
groupName: currentGroup
|
||
|
});
|
||
|
}
|
||
|
|
||
11 years ago
|
rows.push(row);
|
||
|
|
||
|
if (!workPackage['leaf?']) ancestors.push(row);
|
||
11 years ago
|
});
|
||
11 years ago
|
|
||
|
return rows;
|
||
11 years ago
|
},
|
||
|
|
||
|
allRowsChecked: function(rows) {
|
||
11 years ago
|
if( rows.length === 0 ) return false;
|
||
11 years ago
|
return rows
|
||
|
.map(function(row) {
|
||
|
return !!row.checked;
|
||
|
})
|
||
|
.reduce(function(a, b){
|
||
|
return a && b;
|
||
|
});
|
||
11 years ago
|
},
|
||
|
|
||
|
getColumnDifference: function (allColumns, columns) {
|
||
11 years ago
|
var identifiers = columns.map(function(column){
|
||
11 years ago
|
return column.name;
|
||
|
});
|
||
|
|
||
11 years ago
|
return this.getColumnDifferenceByName(allColumns, identifiers);
|
||
11 years ago
|
},
|
||
|
|
||
11 years ago
|
getColumnDifferenceByName: function (allColumns, identifiers) {
|
||
11 years ago
|
return allColumns.filter(function(column) {
|
||
11 years ago
|
return identifiers.indexOf(column.name) === -1;
|
||
11 years ago
|
});
|
||
|
},
|
||
|
|
||
11 years ago
|
getColumnUnionByName: function (allColumns, columnNames) {
|
||
11 years ago
|
return allColumns.filter(function(column) {
|
||
11 years ago
|
return columnNames.indexOf(column.name) !== -1;
|
||
11 years ago
|
});
|
||
|
},
|
||
|
|
||
|
getColumnIndexByName: function(columns, columnName) {
|
||
|
return columns
|
||
|
.map(function(column){
|
||
|
return column.name;
|
||
|
})
|
||
|
.indexOf(columnName);
|
||
|
},
|
||
|
|
||
|
detectColumnByName: function(columns, columnName) {
|
||
|
return columns[WorkPackagesTableHelper.getColumnIndexByName(columns, columnName)];
|
||
|
},
|
||
|
|
||
11 years ago
|
selectColumnsByName: function(columns, columnNames) {
|
||
|
return columns.filter(function(column) {
|
||
|
return columnNames.indexOf(column.name) !== -1;
|
||
|
});
|
||
|
},
|
||
|
|
||
11 years ago
|
mapIdentifiersToColumns: function(columns, columnNames) {
|
||
|
return columnNames.map(function(columnName) {
|
||
|
return WorkPackagesTableHelper.detectColumnByName(columns, columnName);
|
||
|
});
|
||
|
},
|
||
|
|
||
11 years ago
|
moveElementBy: function(array, index, positions) {
|
||
|
// TODO maybe extend the Array prototype
|
||
|
var newPosition = index + positions;
|
||
|
|
||
|
if (newPosition > -1 && newPosition < array.length) {
|
||
11 years ago
|
var elementToMove = array.splice(index, 1)[0];
|
||
11 years ago
|
array.splice(newPosition, 0, elementToMove);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
moveColumnBy: function(columns, columnName, by) {
|
||
|
var index = WorkPackagesTableHelper.getColumnIndexByName(columns, columnName);
|
||
|
|
||
|
WorkPackagesTableHelper.moveElementBy(columns, index, by);
|
||
11 years ago
|
},
|
||
|
|
||
11 years ago
|
moveColumns: function (columnNames, fromColumns, toColumns) {
|
||
|
angular.forEach(columnNames, function(columnName){
|
||
|
WorkPackagesTableHelper.removeColumn(columnName, fromColumns, function(removedColumn){
|
||
|
toColumns.push(removedColumn);
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
|
||
|
removeColumn: function(columnName, columns, callback) {
|
||
11 years ago
|
var removed = columns.splice(this.getColumnIndexByName(columns, columnName), 1)[0];
|
||
11 years ago
|
|
||
|
return typeof(callback) !== 'undefined' ? callback.call(this, removed) : null;
|
||
|
},
|
||
|
|
||
11 years ago
|
getSelectedRows: function(rows) {
|
||
|
return rows
|
||
|
.filter(function(row) {
|
||
|
return row.checked;
|
||
|
});
|
||
|
},
|
||
11 years ago
|
|
||
11 years ago
|
getWorkPackagesFromRows: function(rows) {
|
||
|
return rows
|
||
|
.map(function(row) {
|
||
|
return row.object;
|
||
|
});
|
||
|
}
|
||
11 years ago
|
};
|
||
|
|
||
|
return WorkPackagesTableHelper;
|
||
10 years ago
|
};
|