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.
93 lines
3.6 KiB
93 lines
3.6 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($scope, $filter, columnsModal, QueryService, WorkPackageService, WorkPackagesTableService, $rootScope) {
|
||
11 years ago
|
|
||
11 years ago
|
this.name = 'Columns';
|
||
|
this.closeMe = columnsModal.deactivate;
|
||
11 years ago
|
|
||
11 years ago
|
$scope.getObjectsData = function(term, result) {
|
||
10 years ago
|
var filtered = $filter('filter')($scope.availableColumnsData.filter(function(column) {
|
||
|
//Note: very special case; if such columns shall multiple, we better add a field
|
||
|
// to the query model hash of available columns
|
||
|
return column.id != "id";
|
||
|
}), {label: term});
|
||
|
var sorted = $filter('orderBy')(filtered, 'label');
|
||
10 years ago
|
return result(sorted);
|
||
11 years ago
|
};
|
||
|
|
||
11 years ago
|
// Data conversion for select2
|
||
|
function convertColumnsForSelect2(columns) {
|
||
|
return columns.map(function(column){
|
||
|
return { id: column.name, label: column.title, other: column.title };
|
||
11 years ago
|
});
|
||
11 years ago
|
}
|
||
|
function getColumnIdentifiersFromSelection(selectedColumnsData) {
|
||
11 years ago
|
return selectedColumnsData.map(function(column) { return column.id; });
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
// Selected Columns
|
||
11 years ago
|
var selectedColumns = QueryService.getSelectedColumns();
|
||
|
var previouslySelectedColumnNames = selectedColumns
|
||
11 years ago
|
.map(function(column){ return column.name; });
|
||
11 years ago
|
|
||
11 years ago
|
function getNewlyAddedColumns() {
|
||
|
return selectedColumns.select(function(column){
|
||
|
return previouslySelectedColumnNames.indexOf(column.name) < 0;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$scope.selectedColumnsData = convertColumnsForSelect2(selectedColumns);
|
||
|
|
||
|
// Available selectable Columns
|
||
11 years ago
|
QueryService.loadAvailableColumns()
|
||
|
.then(function(availableColumns){
|
||
|
$scope.availableColumns = availableColumns;
|
||
|
$scope.availableColumnsData = convertColumnsForSelect2(availableColumns);
|
||
11 years ago
|
});
|
||
|
|
||
11 years ago
|
|
||
11 years ago
|
$scope.updateSelectedColumns = function(){
|
||
11 years ago
|
// Note: Can't directly manipulate selected columns because select2 returns a new array when you change the values:(
|
||
11 years ago
|
QueryService.setSelectedColumns(getColumnIdentifiersFromSelection($scope.selectedColumnsData));
|
||
11 years ago
|
|
||
|
// Augment work packages with new columns data
|
||
11 years ago
|
var addedColumns = getNewlyAddedColumns(),
|
||
|
currentWorkPackages = WorkPackagesTableService.getRowsData(),
|
||
|
groupBy = WorkPackagesTableService.getGroupBy();
|
||
11 years ago
|
|
||
|
if(groupBy.length === 0) groupBy = undefined; // don't pass an empty string as groupBy
|
||
|
|
||
11 years ago
|
if(addedColumns.length) {
|
||
11 years ago
|
$rootScope.refreshWorkPackages = WorkPackageService.augmentWorkPackagesWithColumnsData(currentWorkPackages, addedColumns, groupBy);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
columnsModal.deactivate();
|
||
11 years ago
|
};
|
||
10 years ago
|
};
|