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.
72 lines
2.3 KiB
72 lines
2.3 KiB
angular.module('openproject.services')
|
|
|
|
.service('WorkPackageService', ['$http', 'PathHelper', 'WorkPackagesHelper', function($http, PathHelper, WorkPackagesHelper) {
|
|
|
|
var WorkPackageService = {
|
|
getWorkPackages: function(projectId, query, errorHanlder) {
|
|
var url = projectId ? PathHelper.projectWorkPackagesPath(projectId) : PathHelper.workPackagesPath();
|
|
|
|
return WorkPackageService.doQuery(url, query.toParams(), errorHanlder);
|
|
},
|
|
|
|
loadWorkPackageColumnsData: function(workPackages, columnNames, errorHanlder) {
|
|
var url = PathHelper.workPackagesColumnDataPath();
|
|
|
|
var params = {
|
|
'ids[]': workPackages.map(function(workPackage){
|
|
return workPackage.id;
|
|
}),
|
|
'column_names[]': columnNames
|
|
};
|
|
|
|
return WorkPackageService.doQuery(url, params, errorHanlder);
|
|
},
|
|
|
|
// Note: Should this be on a project-service?
|
|
getWorkPackagesSums: function(projectId, columns, errorHanlder){
|
|
var columnNames = columns.map(function(column){
|
|
return column.name;
|
|
});
|
|
|
|
var url = PathHelper.workPackagesSumsPath(projectId);
|
|
|
|
var params = {
|
|
'column_names[]': columnNames
|
|
};
|
|
|
|
return WorkPackageService.doQuery(url, params, errorHanlder);
|
|
},
|
|
|
|
augmentWorkPackagesWithColumnsData: function(workPackages, columns, errorHanlder) {
|
|
var columnNames = columns.map(function(column){
|
|
return column.name;
|
|
});
|
|
|
|
return WorkPackageService.loadWorkPackageColumnsData(workPackages, columnNames, errorHanlder)
|
|
.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, errorHanlder) {
|
|
return $http({
|
|
method: 'GET',
|
|
url: url,
|
|
params: params,
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
}).error(function(data, status, headers, config){
|
|
return errorHanlder.call(this, data);
|
|
}).then(function(response){
|
|
return response.data;
|
|
});
|
|
}
|
|
};
|
|
|
|
return WorkPackageService;
|
|
}]);
|
|
|