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/services/work-package-service.js

63 lines
1.8 KiB

angular.module('openproject.services')
.service('WorkPackageService', ['$http', 'PathHelper', 'WorkPackagesHelper', function($http, PathHelper, WorkPackagesHelper) {
var WorkPackageService = {
getWorkPackages: function(projectId, query) {
var url = projectId ? PathHelper.projectWorkPackagesPath(projectId) : PathHelper.workPackagesPath();
var params = {
'c[]': query.selectedColumns.map(function(column){
return columnName;
}),
'group_by': query.group_by
};
return WorkPackageService.doQuery(url, params);
},
loadWorkPackageColumnsData: function(workPackages, columnNames) {
var url = PathHelper.workPackagesColumnDataPath();
var params = {
'ids[]': workPackages.map(function(workPackage){
return workPackage.id;
}),
'column_names[]': columnNames
};
return WorkPackageService.doQuery(url, params);
},
augmentWorkPackagesWithColumnsData: function(workPackages, columns) {
var columnNames = columns.map(function(column){
return column.name;
});
return WorkPackageService.loadWorkPackageColumnsData(workPackages, columnNames)
.then(function(columnsData){
angular.forEach(workPackages, function(workPackage, i) {
angular.forEach(columns, function(column, j){
WorkPackagesHelper.augmentWorkPackageWithData(workPackage, column.name, !!column.custom_field, columnsData[j][i]);
});
});
return workPackages;
});
},
doQuery: function(url, params) {
return $http({
method: 'GET',
url: url,
params: params,
headers: {'Content-Type': 'application/x-www-form-urlencoded'
}}).then(function(response){
return response.data;
});
}
};
return WorkPackageService;
}]);