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

73 lines
2.3 KiB

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