Merge pull request #1072 from opf/feature/angular-api-work-package-loading

Feature/angular api work package loading
pull/1075/head
Alex Coles 11 years ago
commit 05a957883a
  1. 43
      app/assets/javascripts/angular/config/work-packages-config.js
  2. 111
      app/assets/javascripts/angular/controllers/work-packages-controller.js
  3. 4
      app/assets/javascripts/angular/directives/components/icon-wrapper-directive.js
  4. 34
      app/assets/javascripts/angular/directives/components/table_pagination.js
  5. 14
      app/assets/javascripts/angular/directives/components/toggled-multiselect-directive.js
  6. 4
      app/assets/javascripts/angular/directives/work_packages/query-columns-directive.js
  7. 51
      app/assets/javascripts/angular/directives/work_packages/query-filter-directive.js
  8. 6
      app/assets/javascripts/angular/directives/work_packages/query-filters-directive.js
  9. 3
      app/assets/javascripts/angular/directives/work_packages/query-form-directive.js
  10. 1
      app/assets/javascripts/angular/directives/work_packages/sort-header-directive.js
  11. 4
      app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js
  12. 6
      app/assets/javascripts/angular/directives/work_packages/work-package-total-sums-directive.js
  13. 4
      app/assets/javascripts/angular/directives/work_packages/work-packages-loading-directive.js
  14. 6
      app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js
  15. 18
      app/assets/javascripts/angular/helpers/components/function-decorators.js
  16. 74
      app/assets/javascripts/angular/helpers/components/path-helper.js
  17. 2
      app/assets/javascripts/angular/helpers/components/work-packages-helper.js
  18. 2
      app/assets/javascripts/angular/helpers/filter-query-string-builder.js
  19. 38
      app/assets/javascripts/angular/helpers/function-decorators.js
  20. 14
      app/assets/javascripts/angular/helpers/work-packages-table-helper.js
  21. 26
      app/assets/javascripts/angular/models/filter.js
  22. 28
      app/assets/javascripts/angular/models/query.js
  23. 26
      app/assets/javascripts/angular/models/sortation.js
  24. 2
      app/assets/javascripts/angular/models/timelines/timeline.js
  25. 9
      app/assets/javascripts/angular/openproject-app.js
  26. 21
      app/assets/javascripts/angular/services/group-service.js
  27. 52
      app/assets/javascripts/angular/services/pagination-service.js
  28. 21
      app/assets/javascripts/angular/services/priority-service.js
  29. 70
      app/assets/javascripts/angular/services/query-service.js
  30. 21
      app/assets/javascripts/angular/services/role-service.js
  31. 27
      app/assets/javascripts/angular/services/status-service.js
  32. 6
      app/assets/javascripts/angular/services/timeline-loader-service.js
  33. 28
      app/assets/javascripts/angular/services/type-service.js
  34. 32
      app/assets/javascripts/angular/services/user-service.js
  35. 21
      app/assets/javascripts/angular/services/version-service.js
  36. 45
      app/assets/javascripts/angular/services/work-package-service.js
  37. 5
      app/assets/stylesheets/work_packages.css
  38. 3
      app/controllers/api/v2/api_controller.rb
  39. 51
      app/controllers/api/v3/api_controller.rb
  40. 51
      app/controllers/api/v3/concerns/column_data.rb
  41. 47
      app/controllers/api/v3/groups_controller.rb
  42. 24
      app/controllers/api/v3/queries_controller.rb
  43. 47
      app/controllers/api/v3/roles_controller.rb
  44. 54
      app/controllers/api/v3/versions_controller.rb
  45. 196
      app/controllers/api/v3/work_packages_controller.rb
  46. 261
      app/controllers/work_packages_controller.rb
  47. 2
      app/helpers/queries_helper.rb
  48. 8
      app/models/queries/filter.rb
  49. 2
      app/models/queries/filter_serializer.rb
  50. 9
      app/models/query.rb
  51. 2
      app/models/user.rb
  52. 24
      app/models/work_package.rb
  53. 4
      app/services/user_search_service.rb
  54. 4
      app/views/api/v3/groups/index.api.rabl
  55. 36
      app/views/api/v3/queries/available_columns.api.rabl
  56. 4
      app/views/api/v3/roles/index.api.rabl
  57. 4
      app/views/api/v3/versions/index.api.rabl
  58. 33
      app/views/api/v3/work_packages/column_data.api.rabl
  59. 31
      app/views/api/v3/work_packages/column_sums.api.rabl
  60. 62
      app/views/api/v3/work_packages/index.api.rabl
  61. 9
      app/views/work_packages/_list.html.erb
  62. 9
      app/views/work_packages/index.html.erb
  63. 2
      config/locales/js-de.yml
  64. 2
      config/locales/js-en.yml
  65. 23
      config/routes.rb
  66. 7
      lib/redmine.rb
  67. 2
      mocha/index.html
  68. 4
      public/templates/components/icon_wrapper.html
  69. 2
      public/templates/components/table_pagination.html
  70. 14
      public/templates/components/toggled_multiselect.html
  71. 22
      public/templates/work_packages/query_filters.html
  72. 2
      public/templates/work_packages/sort_header.html
  73. 2
      public/templates/work_packages/work_packages_loading.html
  74. 11
      public/templates/work_packages/work_packages_table.html
  75. 15
      spec/controllers/api/v2/users_controller_spec.rb
  76. 7
      spec/models/query_spec.rb
  77. 59
      spec/views/api/v3/groups/index_api_json_spec.rb
  78. 89
      spec/views/api/v3/queries/available_columns_api_json_spec.rb
  79. 59
      spec/views/api/v3/roles/index_api_json_spec.rb
  80. 59
      spec/views/api/v3/versions/index_api_json_spec.rb
  81. 56
      spec/views/api/v3/work_packages/column_data_api_json_spec.rb
  82. 57
      spec/views/api/v3/work_packages/column_sums_api_json_spec.rb
  83. 83
      spec/views/api/v3/work_packages/index_api_json_spec.rb

@ -0,0 +1,43 @@
angular.module('openproject.workPackages.config')
.constant('INITIALLY_SELECTED_COLUMNS', ['id', 'project', 'type', 'status', 'priority', 'subject', 'assigned_to_id', 'updated_at'])
.constant('OPERATORS_AND_LABELS_BY_FILTER_TYPE', {
list: {'=':'is','!':'is not'},
list_model: {'=':'is','!':'is not'},
list_status: {'o':'open','=':'is','!':'is not','c':'closed','*':'all'}, // TODO RS: Need a generalised solution
list_optional: {'=':'is','!':'is not','!*':'none','*':'all'},
list_subprojects: {'*':'all','!*':'none','=':'is'},
date: {'<t+':'in less than','>t+':'in more than','t+':'in','t':'today','w':'this week','>t-':'less than days ago','<t-':'more than days ago','t-':'days ago'},
date_past: {'>t-':'less than days ago','<t-':'more than days ago','t-':'days ago','t':'today','w':'this week'},
string: {'=':'is','~':'contains','!':'is not','!~':"doesn't contain"},
text: {'~':'contains','!~':"doesn't contain"},
integer: {'=':'is','>=':'>=','<=':'<=','!*':'none','*':'all'}
})
.constant('AVAILABLE_WORK_PACKAGE_FILTERS', {
status_id: { type: 'list_status', modelName: 'status' , order: 1, name: 'Status' },
type_id: { type: 'list_model', modelName: 'type', order: 2, name: 'Type' },
priority_id: { type: 'list_model', modelName: 'priority', order: 3, name: 'Priority'},
assigned_to_id: { type: 'list_model', modelName: 'user' , order: 4, name: 'Assigned to' },
author_id: { type: 'list_model', modelName: 'user' , order: 5, name: 'Author' },
responsible_id: {type: 'list_model', modelName: 'user', order: 6, name: 'Watcher'},
fixed_version_id: {type: 'list_model', modelName: 'version', order: 7, name: 'Version'},
member_of_group: {type: 'list_model', modelName: 'group', order: 8, name: 'Assignee\'s group'},
assigned_to_role: {type: 'list_model', modelName: 'role', order: 9, name: 'Assignee\'s role'},
subject: { type: 'text', order: 10, name: 'Subject' },
created_at: { type: 'date_past', order: 11, name: 'Created on' },
updated_at: { type: 'date_past', order: 12, name: 'Updated on' },
start_date: { type: 'date', order: 13, name: 'Start date' },
due_date: { type: 'date', order: 14, name: 'Due date' },
estimated_hours: { type: 'integer', order: 15, name: 'Estimated time' },
done_ratio: { type: 'integer', order: 16, name: '% done' },
})
.constant('DEFAULT_SORT_CRITERIA', 'parent:desc')
.constant('DEFAULT_PAGINATION_OPTIONS', {
page: 1,
perPage: 10,
perPageOptions: [10, 20, 50, 100, 500, 1000]
});

@ -1,30 +1,51 @@
angular.module('openproject.workPackages.controllers')
.controller('WorkPackagesController', ['$scope', 'WorkPackagesTableHelper', 'Query', 'Sortation', 'WorkPackageService', function($scope, WorkPackagesTableHelper, Query, Sortation, WorkPackageService) {
.controller('WorkPackagesController', ['$scope', '$window', 'WorkPackagesTableHelper', 'Query', 'Sortation', 'WorkPackageService', 'QueryService', 'PaginationService', 'WorkPackageLoadingHelper', 'INITIALLY_SELECTED_COLUMNS', 'OPERATORS_AND_LABELS_BY_FILTER_TYPE',
function($scope, $window, WorkPackagesTableHelper, Query, Sortation, WorkPackageService, QueryService, PaginationService, WorkPackageLoadingHelper, INITIALLY_SELECTED_COLUMNS, OPERATORS_AND_LABELS_BY_FILTER_TYPE) {
function setUrlParams(location) {
$scope.projectIdentifier = location.pathname.split('/')[2];
var regexp = /query_id=(\d+)/g;
var match = regexp.exec(location.search);
if(match) $scope.query_id = match[1];
}
function initialSetup() {
$scope.projectIdentifier = gon.project_identifier;
$scope.operatorsAndLabelsByFilterType = gon.operators_and_labels_by_filter_type;
$scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE;
$scope.loading = false;
$scope.disableFilters = false;
$scope.withLoading(WorkPackageService.getWorkPackagesByQueryId, [$scope.projectIdentifier, $scope.query_id])
.then($scope.setupWorkPackagesTable)
.then(initAvailableColumns);
}
function setupQuery() {
$scope.query = new Query(gon.query);
function initQuery(queryData) {
$scope.query = new Query({
id: $scope.queryId,
displaySums: queryData.display_sums,
groupSums: queryData.group_sums,
sums: queryData.sums,
filters: queryData.filters,
columns: $scope.columns
}); // TODO init sortation according to queryData
sortation = new Sortation(gon.sort_criteria);
$scope.query.setSortation(sortation);
$scope.query.setSortation(new Sortation(queryData.sort_criteria));
// Columns
$scope.columns = gon.columns;
$scope.availableColumns = WorkPackagesTableHelper.getColumnDifference(gon.available_columns, $scope.columns);
$scope.showFilters = $scope.query.filters.length > 0;
$scope.currentSortation = gon.sort_criteria;
return $scope.query;
}
angular.extend($scope.query, {
selectedColumns: $scope.columns
function initAvailableColumns() {
return QueryService.getAvailableColumns($scope.projectIdentifier)
.then(function(data){
$scope.availableColumns = WorkPackagesTableHelper.getColumnDifference(data.available_columns, $scope.columns);
return $scope.availableColumns;
});
};
}
$scope.submitQueryForm = function(){
jQuery("#selected_columns option").attr('selected',true);
@ -32,63 +53,39 @@ angular.module('openproject.workPackages.controllers')
return false;
};
function setupPagination(json) {
$scope.paginationOptions = {
page: json.page,
perPage: json.per_page
};
$scope.perPageOptions = json.per_page_options;
}
$scope.setupWorkPackagesTable = function(json) {
$scope.workPackageCountByGroup = json.work_package_count_by_group;
var meta = json.meta;
if (!$scope.columns) $scope.columns = meta.columns;
if (!$scope.query) initQuery(meta.query);
PaginationService.setPerPageOptions(meta.per_page_options);
PaginationService.setPerPage(meta.per_page);
PaginationService.setPage(meta.page);
$scope.rows = WorkPackagesTableHelper.getRows(json.work_packages, $scope.query.group_by);
$scope.totalSums = json.sums;
$scope.groupSums = json.group_sums;
$scope.totalEntries = json.total_entries;
setupPagination(json);
$scope.workPackageCountByGroup = meta.work_package_count_by_group;
$scope.totalEntries = meta.total_entries;
angular.forEach($scope.columns, function(column, i){
column.total_sum = meta.sums[i];
if (meta.group_sums) column.group_sums = meta.group_sums[i];
});
};
// Initially setup scope via gon
initialSetup();
setupQuery(gon);
// Initialize work package table
$scope.setupWorkPackagesTable(gon);
$scope.updateResults = function() {
$scope.withLoading(WorkPackageService.getWorkPackages, [$scope.projectIdentifier, $scope.query, $scope.paginationOptions])
return $scope.withLoading(WorkPackageService.getWorkPackages, [$scope.projectIdentifier, $scope.query, PaginationService.getPaginationOptions()])
.then($scope.setupWorkPackagesTable);
};
function serviceErrorHandler(data) {
// TODO RS: This is where we'd want to put an error message on the dom
$scope.loading = false;
$scope.isLoading = false;
}
/**
* @name withLoading
*
* @description Wraps a data-loading function and manages the loading state within the scope
* @param {function} callback Function returning a promise
* @param {array} params Params forwarded to the callback
* @returns {promise} Promise returned by the callback
*/
$scope.withLoading = function(callback, params){
startedLoading();
return callback.apply(this, params)
.then(function(data){
finishedLoading();
return data;
}, serviceErrorHandler);
return WorkPackageLoadingHelper.withLoading($scope, callback, params, serviceErrorHandler);
};
function startedLoading() {
$scope.loading = true;
}
function finishedLoading() {
$scope.loading = false;
}
setUrlParams($window.location);
initialSetup();
}]);

@ -1,11 +1,11 @@
// TODO move to UI components
angular.module('openproject.uiComponents')
.directive('iconWrapper', ['I18n', function(I18n){
.directive('iconWrapper', [function(){
return {
restrict: 'EA',
replace: true,
scope: { iconName: '@', title: '=iconTitle' },
scope: { iconName: '@', title: '@iconTitle' },
templateUrl: '/templates/components/icon_wrapper.html'
};
}]);

@ -1,27 +1,28 @@
angular.module('openproject.uiComponents')
.directive('tablePagination', [function(){
.directive('tablePagination', ['PaginationService', function(PaginationService) {
return {
restrict: 'EA',
templateUrl: '/templates/components/table_pagination.html',
scope: {
paginationOptions: '=',
perPageOptions: '=',
totalEntries: '=',
updateResults: '&'
},
link: function(scope, element, attributes) {
scope.paginationOptions = PaginationService.getPaginationOptions();
scope.selectPerPage = function(perPage){
scope.paginationOptions.perPage = perPage;
PaginationService.setPerPage(perPage);
updatePageNumbers();
scope.showPage(1);
};
scope.showPage = function(pageNumber){
scope.paginationOptions.page = pageNumber;
PaginationService.setPage(pageNumber);
updateCurrentRangeLabel();
updateCurrentRange();
scope.updateResults(); // update table
};
@ -30,19 +31,8 @@ angular.module('openproject.uiComponents')
*
* @description Defines a string containing page bound information inside the directive scope
*/
updateCurrentRange = function() {
var page = scope.paginationOptions.page;
var perPage = scope.paginationOptions.perPage;
scope.currentRange = "(" + getLowerPageBound(page, perPage) + " - " + getUpperPageBound(page, perPage) + "/" + scope.totalEntries + ")";
};
function getLowerPageBound(page, perPage) {
return perPage * (page - 1) + 1;
}
function getUpperPageBound(page, perPage) {
return Math.min(perPage * page, scope.totalEntries);
function updateCurrentRangeLabel() {
scope.currentRange = "(" + PaginationService.getLowerPageBound() + " - " + PaginationService.getUpperPageBound(scope.totalEntries) + "/" + scope.totalEntries + ")";
}
/**
@ -50,16 +40,16 @@ angular.module('openproject.uiComponents')
*
* @description Defines a list of all pages in numerical order inside the scope
*/
updatePageNumbers = function() {
function updatePageNumbers() {
var pageNumbers = [];
for (var i = 1; i <= Math.ceil(scope.totalEntries / scope.paginationOptions.perPage); i++) {
pageNumbers.push(i);
}
scope.pageNumbers = pageNumbers;
};
}
scope.$watch('totalEntries', function() {
updateCurrentRange();
updateCurrentRangeLabel();
updatePageNumbers();
});

@ -1,22 +1,28 @@
// TODO move to UI components
angular.module('openproject.uiComponents')
.directive('toggledMultiselect', ['WorkPackagesHelper', function(WorkPackagesHelper){
.directive('toggledMultiselect', ['WorkPackagesHelper', 'I18n', function(WorkPackagesHelper, I18n){
return {
restrict: 'EA',
replace: true,
scope: {
name: '=',
values: '=',
availableFilterValues: '=',
availableOptions: '='
},
templateUrl: '/templates/components/toggled_multiselect.html',
link: function(scope, element, attributes){
scope.I18n = I18n;
scope.toggleMultiselect = function(){
scope.isMultiselect = !scope.isMultiselect;
}
};
scope.isSelected = function(value) {
return Array.isArray(scope.values) && (scope.values.indexOf(value) !== -1 || scope.values.indexOf(value.toString()) !== -1);
};
scope.isMultiselect = (scope.values != undefined && scope.values.length > 1);
scope.isMultiselect = (Array.isArray(scope.values) && scope.values.length > 1);
}
};
}]);

@ -31,7 +31,9 @@ angular.module('openproject.workPackages.directives')
var newColumns = WorkPackagesTableHelper.selectColumnsByName(scope.columns, columnNames);
// work package rows
scope.withLoading(WorkPackageService.augmentWorkPackagesWithColumnsData, [workPackages, newColumns]);
var params = [workPackages, newColumns];
if( scope.groupByColumn) params.push(scope.groupByColumn.name);
scope.withLoading(WorkPackageService.augmentWorkPackagesWithColumnsData, params);
}
function removeColumn(columnName, columns, callback) {

@ -1,13 +1,26 @@
angular.module('openproject.workPackages.directives')
.directive('queryFilter', ['WorkPackagesTableHelper', 'WorkPackageService', 'FunctionDecorators', function(WorkPackagesTableHelper, WorkPackageService, FunctionDecorators) {
.directive('queryFilter', ['WorkPackagesTableHelper', 'WorkPackageService', 'WorkPackageLoadingHelper', 'QueryService', 'PaginationService', 'I18n', function(WorkPackagesTableHelper, WorkPackageService, WorkPackageLoadingHelper, QueryService, PaginationService, I18n) {
return {
restrict: 'A',
scope: true,
link: function(scope, element, attributes) {
scope.availableValues = scope.query.getAvailableFilterValues(scope.filter.name);
scope.I18n = I18n;
scope.isLoading = false; // shadow isLoading as its used for a different purpose in this context
scope.showValueOptionsAsSelect = ['list', 'list_optional', 'list_status', 'list_subprojects'].indexOf(scope.query.getFilterType(scope.filter.name)) !== -1;
scope.showValueOptionsAsSelect = ['list', 'list_optional', 'list_status', 'list_subprojects', 'list_model'].indexOf(scope.query.getFilterType(scope.filter.name)) !== -1;
if (scope.showValueOptionsAsSelect) {
WorkPackageLoadingHelper.withLoading(scope, QueryService.getAvailableFilterValues, [scope.filter.name, scope.projectIdentifier])
.then(buildOptions)
.then(addStandardOptions)
.then(function(options) {
scope.availableFilterValueOptions = options;
});
}
// Filter updates
scope.$watch('filter.operator', function(operator) {
if(operator) scope.showValuesInput = scope.filter.requiresValues();
@ -15,17 +28,39 @@ angular.module('openproject.workPackages.directives')
scope.$watch('filter', function(filter, oldFilter) {
if (filter !== oldFilter) {
if (filter.isConfigured()) {
if (filter.isConfigured() || valueReset(filter, oldFilter)) {
scope.query.hasChanged();
scope.paginationOptions.page = 1; // reset page
PaginationService.resetPage();
applyFiltersWithDelay();
applyFilters();
}
}
}, true);
function applyFiltersWithDelay() {
return FunctionDecorators.withDelay(800, scope.updateResults);
function applyFilters() {
if (scope.showValueOptionsAsSelect) {
return scope.updateResults();
} else {
return WorkPackageLoadingHelper.withDelay(800, scope.updateResults);
}
}
function buildOptions(values) {
return values.map(function(value) {
return [value.name, value.id];
});
}
function addStandardOptions(options) {
if (scope.filter.getModelName() === 'user') {
options.unshift(['<< ' + I18n.t('js.label_me') + ' >>', 'me']);
}
return options;
}
function valueReset(filter, oldFilter) {
return oldFilter.hasValues() && !filter.hasValues();
}
}
};

@ -9,8 +9,6 @@ angular.module('openproject.workPackages.directives')
compile: function(tElement) {
return {
pre: function(scope) {
scope.showFilters = scope.query.filters.length > 0;
scope.$watch('filterToBeAdded', function(filterName) {
if (filterName) {
scope.query.addFilter(filterName);
@ -18,10 +16,6 @@ angular.module('openproject.workPackages.directives')
}
});
scope.query.filters = scope.query.filters.map(function(filter){
var name = Object.keys(filter)[0];
return new Filter(angular.extend(filter[name], { name: name }));
});
}
};
}

@ -11,7 +11,8 @@ angular.module('openproject.workPackages.directives')
scope.showQueryOptions = false;
scope.$watch('query.group_by', function(oldValue, newValue) {
if (newValue !== oldValue) {
if (newValue !== oldValue && newValue !== undefined) {
// TODO find out why newValue get set to undefined on initial page load
scope.updateResults();
}
});

@ -10,7 +10,6 @@ angular.module('openproject.workPackages.directives')
headerName: '=',
headerTitle: '=',
sortable: '=',
updateResults: '&',
locale: '='
},
link: function(scope, element, attributes) {

@ -23,6 +23,8 @@ angular.module('openproject.workPackages.directives')
var custom_field = scope.column.custom_field;
scope.displayText = WorkPackagesHelper.getFormattedCustomValue(scope.workPackage, custom_field) || '';
if (scope.column.meta_data.data_type === 'user') loadUserName();
} else {
// custom display types
if (scope.column.name === 'done_ratio') scope.displayType = 'progress_bar';
@ -30,8 +32,6 @@ angular.module('openproject.workPackages.directives')
scope.displayText = WorkPackagesHelper.getFormattedColumnData(scope.workPackage, scope.column) || '';
}
if (scope.column.meta_data.data_type === 'user') loadUserName();
// Example of how we can look to the provided meta data to format the column
// This relies on the meta being sent from the server
if (scope.column.meta_data.link.display) {

@ -10,8 +10,10 @@ angular.module('openproject.workPackages.directives')
pre: function(scope, iElement, iAttrs, controller) {
function fetchSums() {
scope.withLoading(WorkPackageService.getWorkPackagesSums, [scope.projectIdentifier, scope.columns])
.then(function(sumsData){
scope.sums = sumsData;
.then(function(data){
angular.forEach(scope.columns, function(column, i){
column.total_sum = data.column_sums[i];
});
});
}

@ -5,8 +5,6 @@ angular.module('openproject.workPackages.directives')
return {
restrict: 'E',
templateUrl: '/templates/work_packages/work_packages_loading.html',
scope: true,
link: function(scope, element, attributes) {
}
scope: true
};
}]);

@ -5,12 +5,14 @@ angular.module('openproject.workPackages.directives')
restrict: 'E',
templateUrl: '/templates/work_packages/work_packages_options.html',
link: function(scope, element, attributes) {
scope.$watch('query.group_by', function() {
scope.$watch('query.group_by', function(groupBy) {
if (scope.columns) {
var groupByColumnIndex = scope.columns.map(function(column){
return column.name;
}).indexOf(scope.query.group_by);
}).indexOf(groupBy);
scope.groupByColumn = scope.columns[groupByColumnIndex];
}
});
}
};

@ -1,18 +0,0 @@
// TODO move to UI components
angular.module('openproject.helpers')
.service('FunctionDecorators', ['$timeout', function($timeout) {
var currentRun;
return {
withDelay: function(delay, callback, params) {
$timeout.cancel(currentRun);
currentRun = $timeout(function() {
return callback.apply(this, params);
}, delay);
return currentRun;
}
};
}]);

@ -3,7 +3,8 @@ angular.module('openproject.helpers')
.service('PathHelper', [function() {
PathHelper = {
apiPrefix: '/api/v2',
apiPrefixV2: '/api/v2',
apiPrefixV3: '/api/v3',
projectPath: function(projectIdentifier) {
return '/projects/' + projectIdentifier;
@ -14,24 +15,73 @@ angular.module('openproject.helpers')
workPackagePath: function(id) {
return '/work_packages/' + id;
},
projectWorkPackagesPath: function(projectIdentifier) {
return PathHelper.projectPath(projectIdentifier) + PathHelper.workPackagesPath();
},
usersPath: function() {
return '/users';
},
userPath: function(id) {
return PathHelper.usersPath() + id;
},
workPackagesColumnDataPath: function() {
return PathHelper.workPackagesPath() + '/column_data';
return PathHelper.usersPath() + '/' + id;
},
workPackagesSumsPath: function(projectIdentifier) {
return PathHelper.projectPath(projectIdentifier) + '/column_sums';
versionsPath: function() {
return '/versions';
},
versionPath: function(versionId) {
return '/versions/' + versionId;
}
return PathHelper.versionsPath() + '/' + versionId;
},
apiV2ProjectPath: function(projectIdentifier) {
return PathHelper.apiPrefixV2 + PathHelper.projectPath(projectIdentifier);
},
apiV3ProjectPath: function(projectIdentifier) {
return PathHelper.apiPrefixV3 + PathHelper.projectPath(projectIdentifier);
},
apiWorkPackagesPath: function() {
return PathHelper.apiPrefixV3 + '/work_packages';
},
apiProjectWorkPackagesPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.workPackagesPath();
},
apiAvailableColumnsPath: function() {
return PathHelper.apiPrefixV3 + '/queries/available_columns';
},
apiProjectAvailableColumnsPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + '/queries/available_columns';
},
apiWorkPackagesColumnDataPath: function() {
return PathHelper.apiWorkPackagesPath() + '/column_data';
},
apiPrioritiesPath: function() {
return PathHelper.apiPrefixV2 + '/planning_element_priorities';
},
apiStatusesPath: function() {
return PathHelper.apiPrefixV2 + '/statuses';
},
apiProjectStatusesPath: function(projectIdentifier) {
return PathHelper.apiV2ProjectPath(projectIdentifier) + '/statuses';
},
apiGroupsPath: function() {
return PathHelper.apiPrefixV3 + '/groups';
},
apiRolesPath: function() {
return PathHelper.apiPrefixV3 + '/roles';
},
apiWorkPackageTypesPath: function() {
return PathHelper.apiPrefixV2 + '/planning_element_types';
},
apiProjectWorkPackageTypesPath: function(projectIdentifier) {
return PathHelper.apiV2ProjectPath(projectIdentifier) + '/planning_element_types';
},
apiUsersPath: function() {
return PathHelper.apiPrefixV2 + PathHelper.usersPath();
},
apiProjectVersionsPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.versionsPath();
},
apiProjectUsersPath: function(projectIdentifier) {
return PathHelper.apiV2ProjectPath(projectIdentifier) + PathHelper.usersPath();
},
apiWorkPackagesSumsPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.workPackagesPath() + '/column_sums';
},
};
return PathHelper;

@ -30,7 +30,7 @@ angular.module('openproject.workPackages.helpers')
if (!object.custom_values) return null;
var customValue = object.custom_values.filter(function(customValue){
return customValue.custom_field_id === customField.id;
return customValue && customValue.custom_field_id === customField.id;
}).first();
if(customValue) {

@ -101,7 +101,7 @@ angular.module('openproject.timelines.helpers')
};
FilterQueryStringBuilder.prototype.buildFilterDataForValue = function(key, value) {
if (value instanceof Array) {
if (Array.isArray(value)) {
this.prepareFilterDataForKeyAndArrayOfValues(key, value);
} else {
this.prepareFilterDataForKeyAndValue(key, value);

@ -0,0 +1,38 @@
// TODO move to UI components
angular.module('openproject.helpers')
.service('WorkPackageLoadingHelper', ['$timeout', function($timeout) {
var currentRun;
return {
withDelay: function(delay, callback, params) {
$timeout.cancel(currentRun);
currentRun = $timeout(function() {
return callback.apply(this, params);
}, delay);
return currentRun;
},
/**
* @name withLoading
*
* @description Wraps a data-loading function and manages the loading state within the scope
* @param {scope} a scope on which an isLoading flag is set
* @param {function} callback Function returning a promise
* @param {array} params Params forwarded to the callback
* @returns {promise} Promise returned by the callback
*/
withLoading: function(scope, callback, params, errorCallback) {
scope.isLoading = true;
return callback.apply(this, params)
.then(function(results){
scope.isLoading = false;
return results;
}, errorCallback);
}
};
}]);

@ -50,7 +50,7 @@ angular.module('openproject.workPackages.helpers')
},
allRowsChecked: function(rows) {
if( rows.length == 0 ) return false;
if( rows.length === 0 ) return false;
return rows
.map(function(row) {
return !!row.checked;
@ -65,8 +65,18 @@ angular.module('openproject.workPackages.helpers')
return column.name;
});
return this.getColumnDifferenceByName(allColumns, columnValues);
},
getColumnDifferenceByName: function (allColumns, columnValues) {
return allColumns.filter(function(column) {
return !(columnValues.indexOf(column.name) > -1);
return columnValues.indexOf(column.name) === -1;
});
},
getColumnUnionByName: function (allColumns, columnNames) {
return allColumns.filter(function(column) {
return columnNames.indexOf(column.name) !== -1;
});
},

@ -1,9 +1,10 @@
angular.module('openproject.models')
.constant('OPERATORS_REQUIRING_VALUES', ['o', 'c', '!*', '*', 't', 'w'])
.factory('Filter', ['OPERATORS_REQUIRING_VALUES', function(OPERATORS_REQUIRING_VALUES) {
.factory('Filter', ['OPERATORS_REQUIRING_VALUES', 'AVAILABLE_WORK_PACKAGE_FILTERS', function(OPERATORS_REQUIRING_VALUES, AVAILABLE_WORK_PACKAGE_FILTERS) {
Filter = function (data) {
angular.extend(this, data);
this.pruneValues();
};
Filter.prototype = {
@ -17,7 +18,10 @@ angular.module('openproject.models')
},
valuesAsArray: function() {
if (this.values instanceof Array) {
if (Array.isArray(this.values)) {
if (this.values.length === 0) return ['']; // Workaround: The array must not be empty for backend compatibility so that the values are passed as a URL param at all even if `this` is the only query filter
// TODO fix this on the backend side, so that filters can be initialized on a query without providing values
return this.values;
} else {
return [this.values];
@ -29,7 +33,23 @@ angular.module('openproject.models')
},
isConfigured: function() {
return this.operator && (this.values || !this.requiresValues());
return this.operator && (this.hasValues() || !this.requiresValues());
},
getModelName: function() {
return AVAILABLE_WORK_PACKAGE_FILTERS[this.name].modelName;
},
pruneValues: function() {
if (this.values) {
this.values = this.values.filter(function(value) {
return value !== '';
});
}
},
hasValues: function() {
return Array.isArray(this.values) ? this.values.length > 0 : !!this.values;
}
};

@ -1,20 +1,36 @@
angular.module('openproject.models')
.factory('Query', ['Filter', 'Sortation', function(Filter, Sortation) {
.factory('Query', ['Filter', 'Sortation', 'AVAILABLE_WORK_PACKAGE_FILTERS', function(Filter, Sortation, AVAILABLE_WORK_PACKAGE_FILTERS) {
Query = function (data, options) {
this.available_work_package_filters = AVAILABLE_WORK_PACKAGE_FILTERS;
angular.extend(this, data, options);
this.group_by = this.group_by || '';
if (this.filters === undefined) this.filters = [];
if (this.filters === undefined){
this.filters = [];
} else {
this.filters = this.filters.map(function(filterData){
return new Filter(filterData);
});
}
};
Query.prototype = {
/**
* @name toParams
*
* @description Serializes the query to parameters required by the backend
* @returns {params} Request parameters
*/
toParams: function() {
return angular.extend.apply(this, [
{
'f[]': this.getFilterNames(this.getActiveConfiguredFilters()),
'c[]': this.selectedColumns.map(function(column) {
'c[]': this.columns.map(function(column) {
return column.name;
}),
'group_by': this.group_by,
@ -56,12 +72,8 @@ angular.module('openproject.models')
if (!loading) filter.deactivated = true;
},
getAvailableFilterValues: function(filterName) {
return this.available_work_package_filters[filterName].values;
},
getFilterType: function(filterName) {
return this.available_work_package_filters[filterName].type;
return AVAILABLE_WORK_PACKAGE_FILTERS[filterName].type;
},
getActiveFilters: function() {

@ -1,16 +1,21 @@
angular.module('openproject.models')
.factory('Sortation', [function() {
.factory('Sortation', ['DEFAULT_SORT_CRITERIA', function(DEFAULT_SORT_CRITERIA) {
var defaultSortDirection = 'asc';
var Sortation = function(encodedSortation) {
if (encodedSortation) {
this.sortElements = encodedSortation.split(',').map(function(sortParam) {
fieldAndDirection = sortParam.split(':');
return { field: fieldAndDirection[0], direction: fieldAndDirection[1] || defaultSortDirection};
var Sortation = function(sortation) {
if (Array.isArray(sortation)) {
if (sortation.length > 0) {
// Convert sortation element from API meta format
this.sortElements = sortation.map(function(sortElement) {
return {field: sortElement.first(), direction: sortElement.last()};
});
} else {
this.sortElements = [];
this.sortElements = this.decodeEncodedSortation(DEFAULT_SORT_CRITERIA);
}
} else {
// Unless it's an array we expect the sortation to be in a serialized form
this.sortElements = this.decodeEncodedSortation(sortation || DEFAULT_SORT_CRITERIA);
}
};
@ -59,6 +64,13 @@ angular.module('openproject.models')
return targetSortation;
};
Sortation.prototype.decodeEncodedSortation = function(encodedSortation) {
return encodedSortation.split(',').map(function(sortParam) {
fieldAndDirection = sortParam.split(':');
return { field: fieldAndDirection[0], direction: fieldAndDirection[1] || defaultSortDirection};
});
};
Sortation.prototype.encode = function() {
return this.sortElements.map(function(sortation){
if (sortation.direction === 'asc') {

@ -516,7 +516,7 @@ angular.module('openproject.timelines.models')
// if parents is not an array, turn it into one with length 1, so
// the following each does not fail.
if (!(parents instanceof Array)) {
if (!(Array.isArray(parents))) {
parents = [parents];
}

@ -1,7 +1,7 @@
// global
angular.module('openproject.services', ['openproject.uiComponents', 'openproject.helpers']);
angular.module('openproject.services', ['openproject.uiComponents', 'openproject.helpers', 'openproject.workPackages.config']);
angular.module('openproject.helpers', ['openproject.services']);
angular.module('openproject.models', []);
angular.module('openproject.models', ['openproject.workPackages.config']);
// timelines
angular.module('openproject.timelines', ['openproject.timelines.controllers', 'openproject.timelines.directives', 'openproject.uiComponents']);
@ -15,8 +15,9 @@ angular.module('openproject.timelines.directives', ['openproject.timelines.model
angular.module('openproject.workPackages', ['openproject.workPackages.controllers', 'openproject.workPackages.filters', 'openproject.workPackages.directives', 'openproject.uiComponents']);
angular.module('openproject.workPackages.helpers', ['openproject.helpers']);
angular.module('openproject.workPackages.filters', ['openproject.workPackages.helpers']);
angular.module('openproject.workPackages.controllers', ['openproject.models', 'openproject.workPackages.helpers', 'openproject.services']);
angular.module('openproject.workPackages.directives', ['openproject.helpers', 'openproject.workPackages.helpers', 'openproject.services']);
angular.module('openproject.workPackages.config', []);
angular.module('openproject.workPackages.controllers', ['openproject.models', 'openproject.workPackages.helpers', 'openproject.services', 'openproject.workPackages.config']);
angular.module('openproject.workPackages.directives', ['openproject.uiComponents', 'openproject.services']);
// main app
var openprojectApp = angular.module('openproject', ['ui.select2', 'ui.date', 'openproject.uiComponents', 'openproject.timelines', 'openproject.workPackages', 'ngAnimate']);

@ -0,0 +1,21 @@
angular.module('openproject.services')
.service('GroupService', ['$http', 'PathHelper', function($http, PathHelper) {
var GroupService = {
getGroups: function() {
var url = PathHelper.apiGroupsPath();
return GroupService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.groups;
});
}
};
return GroupService;
}]);

@ -0,0 +1,52 @@
angular.module('openproject.services')
.service('PaginationService', ['DEFAULT_PAGINATION_OPTIONS', function(DEFAULT_PAGINATION_OPTIONS) {
var paginationOptions = {
page: DEFAULT_PAGINATION_OPTIONS.page,
perPage: DEFAULT_PAGINATION_OPTIONS.perPage,
perPageOptions: DEFAULT_PAGINATION_OPTIONS.perPageOptions
};
PaginationService = {
getPaginationOptions: function() {
return paginationOptions;
},
getPage: function() {
return paginationOptions.page;
},
setPage: function(page) {
paginationOptions.page = page;
},
getPerPage: function() {
return paginationOptions.perPage;
},
setPerPage: function(perPage) {
paginationOptions.perPage = perPage;
},
getPerPageOptions: function() {
return paginationOptions.perPageOptions;
},
setPerPageOptions: function(perPageOptions) {
paginationOptions.perPageOptions = perPageOptions;
},
getLowerPageBound: function() {
return paginationOptions.perPage * (paginationOptions.page - 1) + 1;
},
getUpperPageBound: function(limit) {
return Math.min(paginationOptions.perPage * paginationOptions.page, limit);
},
resetPage: function() {
paginationOptions.page = 1;
},
nextPage: function() {
paginationOptions.page = paginationOptions.page + 1;
},
previousPage: function() {
paginationOptions.page = paginationOptions.page - 1;
}
};
return PaginationService;
}]);

@ -0,0 +1,21 @@
angular.module('openproject.services')
.service('PriorityService', ['$http', 'PathHelper', function($http, PathHelper) {
var PriorityService = {
getPriorities: function() {
var url = PathHelper.apiPrioritiesPath();
return PriorityService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.planning_element_priorities;
});
}
};
return PriorityService;
}]);

@ -0,0 +1,70 @@
angular.module('openproject.services')
.service('QueryService', ['$http', 'PathHelper', '$q', 'AVAILABLE_WORK_PACKAGE_FILTERS', 'StatusService', 'TypeService', 'PriorityService', 'UserService', 'VersionService', 'RoleService', 'GroupService', function($http, PathHelper, $q, AVAILABLE_WORK_PACKAGE_FILTERS, StatusService, TypeService, PriorityService, UserService, VersionService, RoleService, GroupService) {
var availableColumns = [], availableFilterValues = {};
var QueryService = {
getAvailableColumns: function(projectIdentifier) {
var url = projectIdentifier ? PathHelper.apiProjectAvailableColumnsPath(projectIdentifier) : PathHelper.apiAvailableColumnsPath();
return QueryService.doQuery(url);
},
getAvailableFilterValues: function(filterName, projectIdentifier) {
var modelName = AVAILABLE_WORK_PACKAGE_FILTERS[filterName].modelName;
if(availableFilterValues[modelName]) {
return $q.when(availableFilterValues[modelName]);
} else {
var retrieveAvailableValues;
switch(modelName) {
case 'status':
retrieveAvailableValues = StatusService.getStatuses(projectIdentifier);
break;
case 'type':
retrieveAvailableValues = TypeService.getTypes(projectIdentifier);
break;
case 'priority':
retrieveAvailableValues = PriorityService.getPriorities(projectIdentifier);
break;
case 'user':
retrieveAvailableValues = UserService.getUsers(projectIdentifier);
break;
case 'version':
retrieveAvailableValues = VersionService.getProjectVersions(projectIdentifier);
break;
case 'role':
retrieveAvailableValues = RoleService.getRoles();
break;
case 'group':
retrieveAvailableValues = GroupService.getGroups();
break;
}
return retrieveAvailableValues.then(function(values) {
return QueryService.storeAvailableFilterValues(modelName, values);
});
}
},
storeAvailableFilterValues: function(modelName, values) {
availableFilterValues[modelName] = values;
return values;
},
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 QueryService;
}]);

@ -0,0 +1,21 @@
angular.module('openproject.services')
.service('RoleService', ['$http', 'PathHelper', function($http, PathHelper) {
var RoleService = {
getRoles: function() {
var url = PathHelper.apiRolesPath();
return RoleService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.roles;
});
}
};
return RoleService;
}]);

@ -0,0 +1,27 @@
angular.module('openproject.services')
.service('StatusService', ['$http', 'PathHelper', function($http, PathHelper) {
var StatusService = {
getStatuses: function(projectIdentifier) {
var url;
if(projectIdentifier) {
url = PathHelper.apiProjectStatusesPath(projectIdentifier);
} else {
url = PathHelper.apiStatusesPath();
}
return StatusService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.statuses;
});
}
};
return StatusService;
}]);

@ -242,7 +242,7 @@ angular.module('openproject.timelines.services')
var i, e, id, map = {};
if (data instanceof Array) {
if (Array.isArray(data)) {
for (i = 0; i < data.length; i++) {
e = data[i];
e.timeline = this.timeline;
@ -424,7 +424,7 @@ angular.module('openproject.timelines.services')
var associations = e[ProjectAssociation.identifier];
var j, a, other;
if (associations instanceof Array) {
if (Array.isArray(associations)) {
for (j = 0; j < associations.length; j++) {
a = associations[j];
a.timeline = dataEnhancer.timeline;
@ -799,7 +799,7 @@ angular.module('openproject.timelines.services')
// w/ custom values that are empty and work packages w/o
// custom values.
if (value instanceof Array && value.indexOf("-1") !== -1) {
if (Array.isArray(value) && value.indexOf("-1") !== -1) {
value.push("");
}

@ -0,0 +1,28 @@
angular.module('openproject.services')
.service('TypeService', ['$http', 'PathHelper', function($http, PathHelper) {
var TypeService = {
getTypes: function(projectIdentifier) {
var url;
if(projectIdentifier) {
url = PathHelper.apiProjectWorkPackageTypesPath(projectIdentifier);
} else {
url = PathHelper.apiWorkPackageTypesPath();
}
return TypeService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.planning_element_types;
});
}
};
return TypeService;
}]);

@ -1,9 +1,22 @@
angular.module('openproject.services')
.service('UserService', ['$http', 'PathHelper', 'FunctionDecorators', function($http, PathHelper, FunctionDecorators) {
.service('UserService', ['$http', 'PathHelper', 'WorkPackageLoadingHelper', function($http, PathHelper, WorkPackageLoadingHelper) {
var registeredUserIds = [], cachedUsers = {};
UserService = {
getUsers: function(projectIdentifier) {
var url, params;
if (projectIdentifier) {
url = PathHelper.apiProjectUsersPath(projectIdentifier);
} else {
url = PathHelper.apiUsersPath();
params = {status: 'all'};
}
return UserService.doQuery(url, params);
},
registerUserId: function(id) {
var user = cachedUsers[id];
if (user) return user;
@ -11,7 +24,7 @@ angular.module('openproject.services')
registeredUserIds.push(id);
cachedUsers[id] = { name: '', firstname: '', lastname: '' }; // create an empty object and fill its values on load
FunctionDecorators.withDelay(10, UserService.loadRegisteredUsers); // HACK
WorkPackageLoadingHelper.withDelay(10, UserService.loadRegisteredUsers); // HACK
// TODO hook into a given promise chain to post-load user data, or if ngView is used trigger load on $viewContentLoaded
return cachedUsers[id];
@ -19,10 +32,9 @@ angular.module('openproject.services')
loadRegisteredUsers: function() {
if (registeredUserIds.length > 0) {
return $http.get(PathHelper.apiPrefix + PathHelper.usersPath(), {
params: { 'ids[]': registeredUserIds }
}).then(function(response){
UserService.storeUsers(response.data.users);
return UserService.doQuery(PathHelper.apiUsersPath(), { 'ids[]': registeredUserIds })
.then(function(users){
UserService.storeUsers(users);
return cachedUsers;
});
}
@ -37,7 +49,15 @@ angular.module('openproject.services')
cachedUser.lastname = user.lastname;
cachedUser.name = user.name;
});
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.users;
});
}
};
return UserService;

@ -0,0 +1,21 @@
angular.module('openproject.services')
.service('VersionService', ['$http', 'PathHelper', function($http, PathHelper) {
var VersionService = {
getProjectVersions: function(projectIdentifier) {
var url = PathHelper.apiProjectVersionsPath(projectIdentifier);
return VersionService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return response.data.versions;
});
}
};
return VersionService;
}]);

@ -1,10 +1,20 @@
angular.module('openproject.services')
.service('WorkPackageService', ['$http', 'PathHelper', 'WorkPackagesHelper', function($http, PathHelper, WorkPackagesHelper) {
.constant('DEFAULT_FILTER_PARAMS', {'fields[]': 'status_id', 'operators[status_id]': 'o'})
.service('WorkPackageService', ['$http', 'PathHelper', 'WorkPackagesHelper', 'DEFAULT_FILTER_PARAMS', function($http, PathHelper, WorkPackagesHelper, DEFAULT_FILTER_PARAMS) {
var WorkPackageService = {
getWorkPackages: function(projectId, query, paginationOptions) {
var url = projectId ? PathHelper.projectWorkPackagesPath(projectId) : PathHelper.workPackagesPath();
getWorkPackagesByQueryId: function(projectIdentifier, queryId) {
var url = projectIdentifier ? PathHelper.apiProjectWorkPackagesPath(projectIdentifier) : PathHelper.apiWorkPackagesPath();
var params = queryId ? { query_id: queryId } : DEFAULT_FILTER_PARAMS;
return WorkPackageService.doQuery(url, params);
},
getWorkPackages: function(projectIdentifier, query, paginationOptions) {
var url = projectIdentifier ? PathHelper.apiProjectWorkPackagesPath(projectIdentifier) : PathHelper.apiWorkPackagesPath();
var params = angular.extend(query.toParams(), {
page: paginationOptions.page,
per_page: paginationOptions.perPage
@ -13,26 +23,27 @@ angular.module('openproject.services')
return WorkPackageService.doQuery(url, params);
},
loadWorkPackageColumnsData: function(workPackages, columnNames) {
var url = PathHelper.workPackagesColumnDataPath();
loadWorkPackageColumnsData: function(workPackages, columnNames, group_by) {
var url = PathHelper.apiWorkPackagesColumnDataPath();
var params = {
'ids[]': workPackages.map(function(workPackage){
return workPackage.id;
}),
'column_names[]': columnNames
'column_names[]': columnNames,
'group_by': group_by
};
return WorkPackageService.doQuery(url, params);
},
// Note: Should this be on a project-service?
getWorkPackagesSums: function(projectId, columns){
getWorkPackagesSums: function(projectIdentifier, columns){
var columnNames = columns.map(function(column){
return column.name;
});
var url = PathHelper.workPackagesSumsPath(projectId);
var url = PathHelper.apiWorkPackagesSumsPath(projectIdentifier);
var params = {
'column_names[]': columnNames
@ -41,16 +52,22 @@ angular.module('openproject.services')
return WorkPackageService.doQuery(url, params);
},
augmentWorkPackagesWithColumnsData: function(workPackages, columns) {
augmentWorkPackagesWithColumnsData: function(workPackages, columns, group_by) {
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 WorkPackageService.loadWorkPackageColumnsData(workPackages, columnNames, group_by)
.then(function(data){
var columnsData = data.columns_data;
var columnsMeta = data.columns_meta;
angular.forEach(columns, function(column, i){
column.total_sum = columnsMeta.total_sums[i];
if (columnsMeta.group_sums) column.group_sums = columnsMeta.group_sums[i];
angular.forEach(workPackages, function(workPackage, j) {
WorkPackagesHelper.augmentWorkPackageWithData(workPackage, column.name, !!column.custom_field, columnsData[i][j]);
});
});

@ -39,7 +39,10 @@ See doc/COPYRIGHT.rdoc for more details.
cursor: pointer;
}
select.to-validate.ng-pristine, input.to-validate.ng-pristine { border:1px solid Gold; }
.sort-header {
cursor: pointer;
}
select.to-validate.ng-dirty.ng-valid, input.to-validate.ng-dirty.ng-valid { border:1px solid Green; }
select.to-validate.ng-dirty.ng-invalid, input.to-validate.ng-dirty.ng-invalid { border:1px solid Red; }
select.to-validate.ng-dirty.ng-valid ~ span.ok, input.to-validate.ng-dirty.ng-valid ~ span.ok { color:green; display:inline; }

@ -39,7 +39,8 @@ module Api
/api\/v2\//
end
permeate_permissions :apply_at_timestamp,
permeate_permissions :authorize,
:apply_at_timestamp,
:determine_base,
:find_all_projects_by_project_id,
:find_project_by_project_id,

@ -0,0 +1,51 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 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.
#++
module Api
module V3
module ApiController
include ::Api::V2::ApiController
extend ::Api::V2::ApiController::ClassMethods
def api_version
/api\/v3\//
end
permeate_permissions :authorize,
:apply_at_timestamp,
:determine_base,
:find_all_projects_by_project_id,
:find_project_by_project_id,
:jump_to_project_menu_item,
:find_optional_project_and_raise_error
end
end
end

@ -0,0 +1,51 @@
module Api::V3::Concerns::ColumnData
def get_columns_for_json(columns)
columns.map do |column|
{ name: column.name,
title: column.caption,
sortable: column.sortable,
groupable: column.groupable,
custom_field: column.is_a?(QueryCustomFieldColumn) &&
column.custom_field.as_json(only: [:id, :field_format]),
meta_data: get_column_meta(column)
}
end
end
private
def get_column_meta(column)
# This is where we want to add column specific behaviour to instruct the front end how to deal with it
# Needs to be things like user link,project link, datetime
{
data_type: column_data_type(column),
link: !!(link_meta()[column.name]) ? link_meta()[column.name] : { display: false }
}
end
def link_meta
{
subject: { display: true, model_type: "work_package" },
type: { display: false },
status: { display: false },
priority: { display: false },
parent: { display: true, model_type: "user" },
assigned_to: { display: true, model_type: "user" },
responsible: { display: true, model_type: "user" },
author: { display: true, model_type: "user" },
project: { display: true, model_type: "project" }
}
end
def column_data_type(column)
if column.is_a?(QueryCustomFieldColumn)
return column.custom_field.field_format
elsif (c = WorkPackage.columns_hash[column.name.to_s] and !c.nil?)
return c.type.to_s
elsif (c = WorkPackage.columns_hash[column.name.to_s + "_id"] and !c.nil?)
return "object"
else
return "default"
end
end
end

@ -0,0 +1,47 @@
#-- encoding: UTF-8
#-- 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.
#++
module Api
module V3
class GroupsController < ApplicationController
include ::Api::V3::ApiController
def index
@groups = Group.all
respond_to do |format|
format.api
end
end
end
end
end

@ -0,0 +1,24 @@
module Api::V3
class QueriesController < ApplicationController
unloadable
include ApiController
include Concerns::ColumnData
include QueriesHelper
include ExtendedHTTP
before_filter :find_optional_project
def available_columns
query = retrieve_query
@available_columns = get_columns_for_json(query.available_columns)
respond_to do |format|
format.api
end
end
end
end

@ -0,0 +1,47 @@
#-- encoding: UTF-8
#-- 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.
#++
module Api
module V3
class RolesController < ApplicationController
include ::Api::V3::ApiController
def index
@roles = Role.all
respond_to do |format|
format.api
end
end
end
end
end

@ -0,0 +1,54 @@
#-- encoding: UTF-8
#-- 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.
#++
module Api
module V3
class VersionsController < ApplicationController
before_filter :find_project
include ::Api::V3::ApiController
def index
@versions = @project.shared_versions.all
respond_to do |format|
format.api
end
end
private
def find_project
@project = Project.find(params[:project_id])
end
end
end
end

@ -0,0 +1,196 @@
module Api
module V3
class WorkPackagesController < ApplicationController
unloadable
DEFAULT_SORT_ORDER = ['parent', 'desc']
include ApiController
include Concerns::ColumnData
include PaginationHelper
include QueriesHelper
include SortHelper
include ExtendedHTTP
# before_filter :authorize # TODO specify authorization
before_filter :authorize_request, only: [:column_data]
before_filter :find_optional_project, only: [:index]
before_filter :load_query, only: [:index]
before_filter :assign_work_packages, only: [:index]
def index
@custom_field_column_names = @query.columns.select{|c| c.name.to_s =~ /cf_(.*)/}.map(&:name)
@column_names = ['id'] | @query.columns.map(&:name) - @custom_field_column_names
# the data for the index is already produced in the assign_work_packages
respond_to do |format|
format.api
end
end
def column_data
raise 'API Error: No IDs' unless params[:ids]
raise 'API Error: No column names' unless params[:column_names]
column_names = params[:column_names]
ids = params[:ids].map(&:to_i)
work_packages = Array.wrap(WorkPackage.visible.find(*ids)).sort {|a,b| ids.index(a.id) <=> ids.index(b.id)}
@columns_data = fetch_columns_data(column_names, work_packages)
@columns_meta = {
total_sums: columns_total_sums(column_names, work_packages),
group_sums: columns_group_sums(column_names, work_packages, params[:group_by])
}
end
def column_sums
raise 'API Error' unless params[:column_names]
column_names = params[:column_names]
project = Project.find_visible(current_user, params[:project_id])
work_packages = project.work_packages
@column_sums = columns_total_sums(column_names, work_packages)
end
private
def columns_total_sums(column_names, work_packages)
column_names.map do |column_name|
column_sum(column_name, work_packages)
end
end
def column_sum(column_name, work_packages)
fetch_column_data(column_name, work_packages, false).map{|c| c.nil? ? 0 : c}.compact.sum if column_should_be_summed_up?(column_name)
end
def columns_group_sums(column_names, work_packages, group_by)
# NOTE RS: This is basically the grouped_sums method from sums.rb but we have no query to play with here
return unless group_by
column_names.map do |column_name|
work_packages.map { |wp| wp.send(group_by) }
.uniq
.inject({}) do |group_sums, current_group|
work_packages_in_current_group = work_packages.select{|wp| wp.send(group_by) == current_group}
group_sums.merge current_group => column_sum(column_name, work_packages_in_current_group)
end
end
end
def load_query
@query ||= retrieve_query
rescue ActiveRecord::RecordNotFound
render_404
end
def authorize_request
# TODO: need to give this action a global role i think. tried making load_column_data role in reminde.rb
# but couldn't get it working.
# authorize_global unless performed?
end
def assign_work_packages
@work_packages = current_work_packages(@project) unless performed?
end
def current_work_packages(projects)
sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria)
sort_update(@query.sortable_columns)
results = @query.results include: [:assigned_to, :type, :priority, :category, :fixed_version],
order: sort_clause
work_packages = results.work_packages
.page(page_param)
.per_page(per_page_param)
.changed_since(@since)
.all
set_work_packages_meta_data(@query, results, work_packages)
work_packages
end
def set_work_packages_meta_data(query, results, work_packages)
@display_meta = true
@work_packages_meta_data = {
query: query.as_json(except: :filters, include: :filters),
columns: get_columns_for_json(query.columns),
work_package_count_by_group: results.work_package_count_by_group,
sums: query.columns.map { |column| results.total_sum_of(column) },
group_sums: query.group_by_column && query.columns.map { |column| results.grouped_sums(column) },
page: page_param,
per_page: per_page_param,
per_page_options: Setting.per_page_options_array,
total_entries: work_packages.total_entries
}
end
# TODO RS: Taken from work_packages_controller, not dry - move to application controller.
def per_page_param
case params[:format]
when 'csv', 'pdf'
Setting.work_packages_export_limit.to_i
when 'atom'
Setting.feeds_limit.to_i
else
super
end
end
def fetch_columns_data(column_names, work_packages)
column_names.map do |column_name|
fetch_column_data(column_name, work_packages)
end
end
def fetch_column_data(column_name, work_packages, display = true)
if column_name =~ /cf_(.*)/
custom_field = CustomField.find($1)
work_packages.map do |work_package|
custom_value = work_package.custom_values.find_by_custom_field_id($1)
if display
work_package.custom_value_display(custom_value)
else
custom_field.cast_value custom_value.try(:value)
end
end
else
work_packages.map do |work_package|
# Note: Doing as_json here because if we just take the value.attributes then we can't get any methods later.
# Name and subject are the default properties that the front end currently looks for to summarize an object.
value = work_package.send(column_name)
value.is_a?(ActiveRecord::Base) ? value.as_json( only: "id", methods: [:name, :subject] ) : value
end
end
end
def column_should_be_summed_up?(column_name)
# see ::Query::Sums mix in
column_is_numeric?(column_name) && Setting.work_package_list_summable_columns.include?(column_name.to_s)
end
def column_is_numeric?(column_name)
# TODO RS: We want to leave out ids even though they are numeric
[:int, :float].include? column_type(column_name)
end
def column_type(column_name)
if column_name =~ /cf_(.*)/
CustomField.find($1).field_format.to_sym
else
column = WorkPackage.columns_hash[column_name]
column.nil? ? :none : column.type
end
end
end
end
end

@ -46,8 +46,8 @@ class WorkPackagesController < ApplicationController
end
include QueriesHelper
include SortHelper
include PaginationHelper
include SortHelper
include OpenProject::Concerns::Preview
accept_key_auth :index, :show, :create, :update
@ -56,7 +56,6 @@ class WorkPackagesController < ApplicationController
before_filter :not_found_unless_work_package,
:project,
:authorize, :except => [:index, :preview, :column_data, :column_sums]
before_filter :find_optional_project,
:protect_from_unauthorized_export, :only => [:index, :all, :preview]
before_filter :load_query, :only => :index
@ -201,48 +200,26 @@ class WorkPackagesController < ApplicationController
end
def index
sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria)
sort_update(@query.sortable_columns)
results = @query.results(:include => [:assigned_to, :type, :priority, :category, :fixed_version],
:order => sort_clause)
work_packages = if @query.valid?
results.work_packages.page(page_param)
.per_page(per_page_param)
.all
else
[]
end
respond_to do |format|
format.html do
# push work packages to client as JSON
# TODO pull work packages via AJAX
push_filter_operators_and_labels
push_query_and_results_via_gon results, work_packages
render :index, :locals => { :query => @query,
:work_packages => work_packages,
:results => results,
:project => @project },
:layout => !request.xhr?
end
format.json do
render json: get_results_as_json(results, work_packages)
end
format.csv do
serialized_work_packages = WorkPackage::Exporter.csv(work_packages, @project)
load_work_packages
serialized_work_packages = WorkPackage::Exporter.csv(@work_packages, @project)
charset = "charset=#{l(:general_csv_encoding).downcase}"
send_data(serialized_work_packages, :type => "text/csv; #{charset}; header=present",
:filename => 'export.csv')
end
format.pdf do
serialized_work_packages = WorkPackage::Exporter.pdf(work_packages,
load_work_packages
serialized_work_packages = WorkPackage::Exporter.pdf(@work_packages,
@project,
@query,
results,
@results,
:show_descriptions => params[:show_descriptions])
send_data(serialized_work_packages,
@ -250,7 +227,8 @@ class WorkPackagesController < ApplicationController
:filename => 'export.pdf')
end
format.atom do
render_feed(work_packages,
load_work_packages
render_feed(@work_packages,
:title => "#{@project || Setting.app_title}: #{l(:label_work_package_plural)}")
end
end
@ -258,79 +236,6 @@ class WorkPackagesController < ApplicationController
render_404
end
# ------------------- Custom API method -------------------
# TODO Move to API
def column_data
raise 'API Error: No IDs' unless params[:ids]
raise 'API Error: No column names' unless params[:column_names]
column_names = params[:column_names]
ids = params[:ids].map(&:to_i)
work_packages = Array.wrap(WorkPackage.visible.find(*ids)).sort {|a,b| ids.index(a.id) <=> ids.index(b.id)}
render json: fetch_columns_data(column_names, work_packages)
end
def column_sums
# TODO RS: Needs to work for groups, what's the deal?
raise 'API Error' unless params[:column_names]
column_names = params[:column_names]
project = Project.find_visible(current_user, params[:id])
work_packages = project.work_packages
sums = column_names.map do |column_name|
fetch_column_data(column_name, work_packages).map{|c| c.nil? ? 0 : c}.compact.sum if column_should_be_summed_up?(column_name)
end
render json: sums
end
def fetch_columns_data(column_names, work_packages)
column_names.map do |column_name|
fetch_column_data(column_name, work_packages)
end
end
def fetch_column_data(column_name, work_packages)
if column_name =~ /cf_(.*)/
custom_field = CustomField.find($1)
work_packages.map do |work_package|
custom_value = work_package.custom_values.find_by_custom_field_id($1)
custom_field.cast_value custom_value.try(:value)
end
else
work_packages.map do |work_package|
# Note: Doing as_json here because if we just take the value.attributes then we can't get any methods later.
# Name and subject are the default properties that the front end currently looks for to summarize an object.
value = work_package.send(column_name)
value.is_a?(ActiveRecord::Base) ? value.as_json( only: "id", methods: [:name, :subject] ) : value
end
end
end
def column_should_be_summed_up?(column_name)
# see ::Query::Sums mix in
column_is_numeric?(column_name) && Setting.work_package_list_summable_columns.include?(column_name.to_s)
end
def column_is_numeric?(column_name)
# TODO RS: We want to leave out ids even though they are numeric
[:int, :float].include? column_type(column_name)
end
def column_type(column_name)
if column_name =~ /cf_(.*)/
CustomField.find($1).field_format.to_sym
else
column = WorkPackage.columns_hash[column_name]
column.nil? ? :none : column.type
end
end
# ---------------------------------------------------------
def quoted
text, author = if params[:journal_id]
journal = work_package.journals.find(params[:journal_id])
@ -529,149 +434,19 @@ class WorkPackagesController < ApplicationController
private
# ------------------- Form JSON reponse for angular -------------------
# TODO provide data in API
def push_filter_operators_and_labels
gon.operators_and_labels_by_filter_type = get_operators_and_labels_by_filter_type
end
def push_query_and_results_via_gon(results, work_packages)
get_query_and_results_as_json(results, work_packages).each_pair do |name, value|
gon.send "#{name}=", value
end
# TODO later versions of gon support gon.push {Hash} - on the other hand they make it harder to deliver data to gon inside views
end
# filter information
def get_operators_and_labels_by_filter_type
Queries::Filter.operators_by_filter_type.inject({}) do |hash, (type, operators)|
hash.merge type => get_operators_to_label_hash(operators)
end
end
def get_operators_to_label_hash(operators)
operators.inject({}) do |operators_with_labels, operator|
operators_with_labels.merge(operator => I18n.t(Queries::Filter.operators[operator]))
end
end
# query
def get_query_and_results_as_json(results, work_packages)
get_results_as_json(results, work_packages).merge(
project_identifier: @project.to_param,
query: get_query_as_json(@query),
columns: get_columns_for_json(@query.columns),
available_columns: get_columns_for_json(@query.available_columns),
sort_criteria: @sort_criteria.to_param
)
end
def get_results_as_json(results, work_packages)
{
work_package_count_by_group: results.work_package_count_by_group,
work_packages: get_work_packages_as_json(work_packages, @query.columns),
sums: results.column_total_sums,
group_sums: results.column_group_sums,
page: page_param,
per_page: per_page_param,
per_page_options: Setting.per_page_options_array,
total_entries: work_packages.total_entries
}
end
def get_query_as_json(query)
query.as_json only: [:id, :group_by, :display_sums, :filters],
methods: [:available_work_package_filters]
end
def get_columns_for_json(columns)
columns.map do |column|
{ name: column.name,
title: column.caption,
sortable: column.sortable,
groupable: column.groupable,
custom_field: column.is_a?(QueryCustomFieldColumn) &&
column.custom_field.as_json(only: [:id, :field_format], methods: [:name_locale]),
meta_data: get_column_meta(column)
}
end
end
def get_column_meta(column)
# This is where we want to add column specific behaviour to instruct the front end how to deal with it
# Needs to be things like user link,project link, datetime
{
data_type: column_data_type(column),
link: !!(link_meta[column.name]) ? link_meta()[column.name] : { display: false }
}
end
def link_meta
{
subject: { display: true, model_type: "work_package" },
type: { display: false },
status: { display: false },
priority: { display: false },
parent: { display: true, model_type: "user" },
assigned_to: { display: true, model_type: "user" },
responsible: { display: true, model_type: "user" },
author: { display: true, model_type: "user" },
project: { display: true, model_type: "project" },
fixed_version: { display: true, model_type: "version" }
}
end
def load_work_packages
sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria)
sort_update(@query.sortable_columns)
def column_data_type(column)
if column.is_a?(QueryCustomFieldColumn)
return column.custom_field.field_format
elsif (c = WorkPackage.columns_hash[column.name.to_s] and !c.nil?)
return c.type.to_s
elsif (c = WorkPackage.columns_hash[column.name.to_s + "_id"] and !c.nil?)
return "object"
@results = @query.results(:include => [:assigned_to, :type, :priority, :category, :fixed_version],
:order => sort_clause)
@work_packages = if @query.valid?
@results.work_packages.page(page_param)
.per_page(per_page_param)
.all
else
return "default"
end
end
# work packages
def get_work_packages_as_json(work_packages, selected_columns=[])
attributes_to_be_displayed = default_work_package_attributes +
(WorkPackage.attribute_names.map(&:to_sym) & selected_columns.map(&:name))
work_packages.as_json only: attributes_to_be_displayed,
methods: [:leaf?, :overdue?],
include: get_column_includes(selected_columns)
end
def get_column_includes(selected_columns=[])
selected_associations = {
assigned_to: { only: :id, methods: :name },
author: { only: :id, methods: :name },
category: { only: :name },
priority: { only: :name },
project: { only: [:name, :identifier] },
responsible: { only: :id, methods: :name },
status: { only: :name },
type: { only: :name },
parent: { only: :subject },
fixed_version: { only: [:name, :id] }
}.slice(*selected_columns.map(&:name))
selected_associations.merge!(custom_values: { only: [:custom_field_id, :value] }) if selected_columns.any? {|c| c.is_a? QueryCustomFieldColumn}
# TODO retrieve custom values in a single query like this and extend the work_packages inside the JSON:
# WorkPackage.includes(:custom_values).where(['work_packages.id in (?) AND custom_values.custom_field_id in (?)', @query.results.map(&:id), custom_field_columns.map(&:id)])
selected_associations
[]
end
def default_work_package_attributes
%i(id parent_id)
end
def parse_preview_data

@ -98,7 +98,7 @@ module QueriesHelper
else
if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
# Give it a name, required to be valid
@query = Query.new({name: "_"}, initialize_with_default_filter: true)
@query = Query.new({name: "_"})
@query.project = @project
if params[:fields] || params[:f]
add_filter_from_params

@ -29,6 +29,7 @@
class Queries::Filter
include ActiveModel::Validations
include ActiveModel::Serialization
class_attribute :filter_types_by_field, instance_writer: false
@ -91,6 +92,7 @@ class Queries::Filter
end
end
# (de-)serialization
def self.from_hash(filter_hash)
filter_hash.keys.map {|field| new(field, filter_hash[field]) }
end
@ -99,6 +101,12 @@ class Queries::Filter
{ field => attributes_hash }
end
alias_method :name, :field
def attributes
{ name: name, operator: operator, values: values }
end
def field=(field)
@field = field.try :to_sym
end

@ -34,6 +34,6 @@ module Queries::FilterSerializer
end
def self.dump(filters)
YAML.dump (filters || []).map(&:to_hash).reduce(:merge).stringify_keys
YAML.dump ((filters || []).map(&:to_hash).reduce(:merge) || {}).stringify_keys
end
end

@ -48,7 +48,6 @@ class Query < ActiveRecord::Base
validates_length_of :name, :maximum => 255
validate :validate_work_package_filters
validates :filters, presence: true
after_initialize :remember_project_scope
@ -116,7 +115,7 @@ class Query < ActiveRecord::Base
def add_filter(field, operator, values)
return unless values && values.is_a?(Array) && work_package_filter_available?(field)
return unless work_package_filter_available?(field)
if filter = filter_for(field)
filter.operator = operator
@ -134,6 +133,8 @@ class Query < ActiveRecord::Base
# Add multiple filters using +add_filter+
def add_filters(fields, operators, values)
values ||= {}
if fields.is_a?(Array) && operators.is_a?(Hash) && values.is_a?(Hash)
fields.each do |field|
add_filter(field, operators[field], values[field])
@ -318,10 +319,8 @@ class Query < ActiveRecord::Base
field = filter.field.to_s
next if field == "subproject_id"
values = filter.values.clone
next if values.blank?
operator = filter.operator
values = filter.values ? filter.values.clone : [''] # HACK - some operators don't require values, but they are needed for building the statement
# "me" value subsitution
if @@user_filters.include? field

@ -641,14 +641,12 @@ class User < Principal
return true if admin?
initialize_allowance_evaluators
# authorize if user has at least one membership granting this permission
candidates_for_global_allowance.any? do |candidate|
denied = @registered_allowance_evaluators.any? do |evaluator|
evaluator.denied_for_global? candidate, action, options
end
!denied && @registered_allowance_evaluators.any? do |evaluator|
evaluator.granted_for_global? candidate, action, options
end

@ -713,6 +713,30 @@ class WorkPackage < ActiveRecord::Base
return allowed
end
# Begin Custom Value Display Helper Methods
# TODO RS: This probably isn't the right place for display helpers. It's convenient though to have
# the method on the model so that it can be used in the rabl template.
def get_custom_value_display_data(custom_field)
custom_value_display(custom_values.find_by_custom_field_id(custom_field.id))
end
def custom_values_display_data(field_names)
field_names.map do |field_name|
custom_value_display(custom_values.find_by_custom_field_id(field_name.to_s.gsub('cf_','')))
end
end
def custom_value_display(custom_value)
if !custom_value.nil?
{
custom_field_id: custom_value.custom_field.id,
field_format: custom_value.custom_field.field_format,
value: custom_value.value
}
end
end
# End Custom Value Display Helper Methods
protected
def recalculate_attributes_for(work_package_id)

@ -31,6 +31,7 @@ class UserSearchService
attr_accessor :params
SEARCH_SCOPES = [
'project_id',
'ids',
'group_id',
'status',
@ -42,7 +43,8 @@ class UserSearchService
end
def search
scope = User
scope = params[:project_id] ? Project.find(params[:project_id]).users : User
params[:ids].present? ? ids_search(scope) : query_search(scope)
end

@ -0,0 +1,4 @@
collection @groups => :groups
attributes :id,
:name

@ -0,0 +1,36 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 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.
#++
collection @available_columns => :available_columns
node(:name) { |c| c[:name] }
node(:title) { |c| c[:title] }
node(:sortable) { |c| c[:sortable] }
node(:groupable) { |c| c[:groupable] }
node(:custom_field) { |c| c[:custom_field] }
node(:meta_data) { |c| c[:meta_data] }

@ -0,0 +1,4 @@
collection @roles => :roles
attributes :id,
:name

@ -0,0 +1,4 @@
collection @versions => :versions
attributes :id,
:name

@ -0,0 +1,33 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 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.
#++
object false
node(:columns_data) { @columns_data }
node(:columns_meta) { @columns_meta }

@ -0,0 +1,31 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 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.
#++
object false
node(:column_sums) { @column_sums }

@ -0,0 +1,62 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 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.
#++
object false
child @work_packages => :work_packages do
@column_names.each do |column_name|
node(column_name, :if => lambda{ |wp| wp.respond_to?(column_name) }) do |wp|
case wp.send(column_name)
when Category
wp.send(column_name).as_json(only: [:id, :name])
when Project
wp.send(column_name).as_json(only: [:id, :name])
when IssuePriority
wp.send(column_name).as_json(only: [:id, :name])
when Status
wp.send(column_name).as_json(only: [:id, :name])
when User
wp.send(column_name).as_json(only: [:id, :firstname], methods: :name)
when Version
wp.send(column_name).as_json(only: [:id, :name])
when WorkPackage
wp.send(column_name).as_json(only: [:id, :name])
else
wp.send(column_name)
end
end
end
node(:custom_values) do |wp|
wp.custom_values_display_data @custom_field_column_names
end
end
if @display_meta
node(:meta) { @work_packages_meta_data }
end

@ -26,13 +26,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<%= include_gon %>
<%= form_tag({}) do -%>
<%= hidden_field_tag 'back_url', url_for(params) %>
<div class="autoscroll">
<work-packages-table project-identifier="projectIdentifier"
<work-packages-table ng-if="rows && columns"
project-identifier="projectIdentifier"
columns="columns"
rows="rows"
query="query"
@ -47,11 +47,10 @@ See doc/COPYRIGHT.rdoc for more details.
with-loading="withLoading">
</work-packages-table>
<table-pagination pagination-options="paginationOptions"
per-page-options="perPageOptions"
total-entries="totalEntries"
<table-pagination total-entries="totalEntries"
update-results="updateResults()">
</table-pagination>
<work-packages-loading>
</work-packages-loading>

@ -27,6 +27,9 @@ See doc/COPYRIGHT.rdoc for more details.
++#%>
<%= include_gon %>
<% breadcrumb_paths(l(:label_work_package_plural)) %>
<% if !query.new_record? && query.editable_by?(User.current) %>
<% content_for :action_menu_specific do %>
@ -75,9 +78,7 @@ See doc/COPYRIGHT.rdoc for more details.
</div><!-- .title-bar -->
<% if query.valid? %>
<%= render :partial => 'work_packages/list', :locals => { :work_packages => work_packages,
:query => query,
:results => results } %>
<%= render :partial => 'work_packages/list', :locals => { :query => query } %>
<%= other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => { :project_id => project, :query_id => (query.new_record? ? nil : query), :key => User.current.rss_key } %>
@ -91,7 +92,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% end %>
</div>
<%= call_hook(:view_work_packages_index_bottom, { :issues => work_packages, :project => project, :query => query }) %>
<%= call_hook(:view_work_packages_index_bottom, { :project => project, :query => query }) %>
<% content_for :sidebar do %>
<%= render :partial => 'sidebar' %>

@ -4,6 +4,7 @@ de:
hide: "Verbergen"
loading: "Lädt ..."
button_check_all: "Alles auswählen"
button_delete: "Löschen"
button_uncheck_all: "Alles abwählen"
description_available_columns: "Verfügbare Spalten"
description_select_work_package: "Arbeitspaket auswählen"
@ -25,6 +26,7 @@ de:
label_expand: "Aufklappen"
label_expanded: "aufgeklappt"
label_expand_all: "Alle aufklappen"
label_me: "ich"
label_menu_collapse: "ausblenden"
label_menu_expand: "einblenden"
label_no_data: "Nichts anzuzeigen"

@ -4,6 +4,7 @@ en:
hide: "Hide"
loading: "Loading ..."
button_check_all: "Check all"
button_delete: "Delete"
button_uncheck_all: "Uncheck all"
description_available_columns: "Available Columns"
description_select_work_package: "Select work package"
@ -25,6 +26,7 @@ en:
label_expand: "Expand"
label_expanded: "expanded"
label_expand_all: "Expand all"
label_me: "me"
label_menu_collapse: "collapse"
label_menu_expand: "expand"
label_no_data: "No data to display"

@ -93,6 +93,7 @@ OpenProject::Application.routes.draw do
get :available_projects, :on => :collection
end
resources :statuses, :only => [:index, :show]
resources :users, only: [:index]
member do
get :planning_element_custom_fields
@ -115,6 +116,28 @@ OpenProject::Application.routes.draw do
end
end
namespace :v3 do
resources :work_packages, only: [:index] do
get :column_data, on: :collection
end
resources :queries, only: [:show] do
get :available_columns, on: :collection
end
resources :projects, only: [:show] do
resources :work_packages, only: [:index] do
get :column_sums, on: :collection
end
resources :queries, only: [:show] do
get :available_columns, on: :collection
end
resources :versions, only: [:index]
end
resources :groups, only: [:index]
resources :roles, only: [:index]
end
end
match '/roles/workflow/:id/:role_id/:type_id' => 'roles#workflow'

@ -91,6 +91,9 @@ Redmine::AccessControl.map do |map|
:copy_projects => [:copy, :copy_project],
:members => [:paginate_users]
}, :require => :member
map.permission :load_column_data, {
:work_packages => [ :column_data ]
}
map.project_module :work_package_tracking do |map|
# Issue categories
@ -101,8 +104,8 @@ Redmine::AccessControl.map do |map|
:context_menus => [:issues],
:versions => [:index, :show, :status_by],
:journals => [:index, :diff],
:queries => :index,
:work_packages => [:show, :index, :column_data], # TODO move column_data to API
:queries => [:index, :available_columns],
:work_packages => [:show, :index],
:'work_packages/reports' => [:report, :report_details],
:planning_elements => [:index, :all, :show, :recycle_bin],
:planning_element_journals => [:index]}

@ -31,6 +31,8 @@
<script src="../app/assets/javascripts/angular/helpers/components/i18n.js"></script>
<script src="../app/assets/javascripts/angular/helpers/components/custom-field-helper.js"></script>
<script src="../app/assets/javascripts/angular/config/work-packages-config.js"></script>
<script src="../app/assets/javascripts/angular/models/filter.js"></script>
<script src="../app/assets/javascripts/angular/models/query.js"></script>
<script src="../app/assets/javascripts/angular/models/sortation.js"></script>

@ -1,3 +1,3 @@
<span class="icon-context icon-button icon-{{iconName}}">
<span class="hidden-for-sighted"></span>
<span class="icon-context icon-button icon-{{iconName}}" title="{{title}}">
<span class="hidden-for-sighted">{{title}}</span>
</span>

@ -25,7 +25,7 @@
<span class="per_page_options">
Per page:
<span ng-repeat="perPageOption in perPageOptions">
<span ng-repeat="perPageOption in paginationOptions.perPageOptions">
<span ng-if="perPageOption != paginationOptions.perPage">
<a href="" ng-click="selectPerPage(perPageOption)">{{ perPageOption }}</a>
</span>

@ -1,15 +1,17 @@
<div>
<select ng-show="!isMultiselect"
<select filter-value-select
ng-show="!isMultiselect"
name="v[{{name}}][]"
ng-model="values"
id="values-{{name}}"
class="select-small"
style="vertical-align: top;"
require>
<option ng-repeat="value in availableFilterValues" value="{{ value[1] }}" ng-selected="values.indexOf(value[1]) >= 0">{{ value[0] }}</option>
<option ng-repeat="value in availableOptions" value="{{ value[1] }}" ng-selected="isSelected(value[1])">{{ value[0] }}</option>
</select>
<select multiple
filter-value-select
ng-show="isMultiselect"
name="v[{{name}}][]"
ng-model="values"
@ -17,11 +19,11 @@
class="select-small"
style="vertical-align: top;"
require>
<option ng-repeat="value in availableFilterValues" value="{{ value[1] }}" ng-selected="values.indexOf(value[1]) >= 0">{{ value[0] }}</option>
<option ng-repeat="value in availableOptions" value="{{ value[1] }}" ng-selected="isSelected(value[1])">{{ value[0] }}</option>
</select>
<a alt="Toggle multiselect" href="#" style="vertical-align: bottom;" title="Toggle multiselect" ng-click="toggleMultiselect()">
<img alt="Bullet_toggle_plus" src="/assets/bullet_toggle_plus.png"/>
<span class="hidden-for-sighted">{{ I18n.t('js.work_packages.label_enable_multi_select') }}</span>
<a href="#" class="no-decoration-on-hover" title="{{I18n.t('js.work_packages.label_enable_multi_select')}}" ng-click="toggleMultiselect()">
<icon-wrapper icon-name="plus"
icon-title="{{I18n.t('js.work_packages.label_enable_multi_select')}}"/>
</a>
</div>

@ -44,7 +44,7 @@
ng-options="operator as label for (operator, label) in operatorsAndLabelsByFilterType[query.getFilterType(filter.name)]"
ng-model="filter.operator"
style="vertical-align: top;"
ng-disabled="disableFilters">
ng-disabled="isLoading">
</select>
</td>
@ -64,7 +64,7 @@
size="30"
type="text"
value=""
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
<label ng-switch-when="string"
for="values_{{name}}"
class="hidden-for-sighted">
@ -81,7 +81,7 @@
size="30"
type="text"
value=""
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
<label ng-switch-when="'text'"for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.description_enter_text') }}
</label>
@ -95,7 +95,7 @@
size="3"
type="text"
value=""
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
<label ng-switch-when="'integer'" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.description_enter_text') }}
</label>
@ -108,7 +108,7 @@
name="v_{{filter.name}}"
size="3"
type="text"
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
<label ng-switch-when="'date'" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.time_relative.days') }}
</label>
@ -121,7 +121,7 @@
name="v_{{filter.name}}"
size="3"
type="text"
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
<label ng-switch-when="'date'" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.time_relative.days') }}
</label>
@ -130,11 +130,11 @@
<div ng-if="showValueOptionsAsSelect"
ng-show="showValuesInput">
<toggled-multiselect available-filter-values="query.getAvailableFilterValues(filter.name)"
<toggled-multiselect available-options="availableFilterValueOptions"
name="filter.name"
values="filter.values"
is-multiselect="false"
ng-disabled="disableFilters"/>
ng-disabled="isLoading"/>
</div>
</td>
@ -142,7 +142,7 @@
<!-- Delete filter -->
<td>
<icon-wrapper icon-name="delete2"
icon-title="'delete'"
icon-title="{{I18n.t('js.button_delete')}}"
ng-click="query.deactivateFilter(filter, loading)"/>
<!-- TODO I18n -->
</td>
@ -159,12 +159,10 @@
<label for="add_filter_select">{{ I18n.t('js.work_packages.label_filter_add') }}</label>:
<select class="select-small"
id="add_filter_select"
ng-change="add_filter()"
ng-model="filterToBeAdded"
ng-options="filterName as filterOptions.name || filterName
for (filterName, filterOptions)
in (query.available_work_package_filters | subtractActiveFilters:query.filters)"
ng-disabled="disableFilters"/>
in (query.available_work_package_filters | subtractActiveFilters:query.filters)" />
</select>
<!-- TODO options | orderObjectBy: 'order' -->
</td>

@ -1,4 +1,4 @@
<span title="{{ fullTitle }}">
<span title="{{ fullTitle }}" class="sort-header">
<a ng-if="sortable"
ng-class="[currentSortDirection && 'sort', currentSortDirection]"
ng-click="performSort()"

@ -1,4 +1,4 @@
<div ng-if="loading"
<div ng-if="isLoading"
id="ajax-indicator">
<span>Loading...</span>
</div>

@ -24,8 +24,7 @@
header-name="column.name"
header-title="column.title"
sortable="column.sortable"
query="query"
update-results="updateResults()"/>
query="query"/>
</tr>
</thead>
@ -135,8 +134,8 @@
{{ I18n.t('js.label_sum_for') }}
<span work-package-column work-package="row.object" column="groupByColumn"/>
</td>
<td ng-repeat="sum in sums track by $index">
{{ sum }}
<td ng-repeat="column in columns">
{{ column.group_sums[row.groupName] }}
</td>
</tr>
@ -146,8 +145,8 @@
ng-if="displaySums"
class="sum group all issue work_package">
<td colspan="2">{{ I18n.t('js.label_sum_for') }} {{ I18n.t('js.label_all_work_packages') }}</td>
<td ng-repeat="sum in sums track by $index">
{{ sum }}
<td ng-repeat="column in columns">
{{ column.total_sum }}
</td>
</tr>

@ -101,6 +101,21 @@ describe Api::V2::UsersController do
end
end
describe 'within a project' do
include_context "As a normal user"
let(:project) { FactoryGirl.create :project }
let!(:member) { FactoryGirl.create :user, member_in_project: project }
let!(:non_member) { FactoryGirl.create :user }
before { get 'index', project_id: project.to_param, format: :json }
it_behaves_like "valid user API call" do
let(:user_count) { 1 }
end
end
describe 'search for ids' do
include_context "As an admin"

@ -57,7 +57,7 @@ describe Query do
expect(query.errors[:name].first).to include(I18n.t('activerecord.errors.messages.blank'))
end
context 'with a missing value' do
context 'with a missing value and an operator that requires values' do
before do
query.add_filter('due_date', 't-', [''])
end
@ -72,9 +72,8 @@ describe Query do
let(:status) { FactoryGirl.create :status }
let(:query) { FactoryGirl.build(:query).tap {|q| q.filters = []} }
it 'is not valid and creates an error' do
expect(query.valid?).to be_false
expect(query.errors[:filters]).to include(I18n.t('activerecord.errors.messages.blank'))
it 'is valid' do
expect(query.valid?).to be_true
end
end

@ -0,0 +1,59 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/groups/index.api.rabl' do
before do
params[:format] = 'json'
assign(:groups, groups)
render
end
subject { response.body }
describe 'with no groups available' do
let(:groups) { [] }
it { should have_json_path('groups') }
it { should have_json_size(0).at_path('groups') }
end
describe 'with 2 groups available' do
let(:groups) { [
FactoryGirl.build(:group), FactoryGirl.build(:group)
] }
it { should have_json_path('groups') }
it { should have_json_size(2).at_path('groups') }
it { should have_json_type(Object).at_path('groups/1') }
it { should have_json_path('groups/1/name') }
end
end

@ -0,0 +1,89 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/queries/available_columns.api.rabl' do
before do
params[:format] = 'json'
assign(:available_columns, available_columns)
render
end
subject { response.body }
describe 'with no available columns' do
let(:available_columns) { [] }
it { should have_json_path('available_columns') }
it { should have_json_size(0).at_path('available_columns') }
end
describe 'with 2 available columns' do
let(:available_columns) {
[
{
name: "project",
title: "Project",
sortable: "projects.name",
groupable:"project",
custom_field: false,
meta_data: {
data_type: "object",
link: {
display: true,
model_type: "project"
}
}
}, {
name: "status",
title: "Status",
sortable: "statuses.name",
groupable:"status",
custom_field: false,
meta_data: {
data_type: "object",
link: {
display: false,
model_type: "project"
}
}
}
]
}
it { should have_json_path('available_columns') }
it { should have_json_size(2).at_path('available_columns') }
it { should have_json_type(FalseClass).at_path('available_columns/1/custom_field') }
it { should have_json_type(Object).at_path('available_columns/1/meta_data') }
it { should have_json_type(String).at_path('available_columns/1/meta_data/link/model_type') }
end
end

@ -0,0 +1,59 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/roles/index.api.rabl' do
before do
params[:format] = 'json'
assign(:roles, roles)
render
end
subject { response.body }
describe 'with no roles available' do
let(:roles) { [] }
it { should have_json_path('roles') }
it { should have_json_size(0).at_path('roles') }
end
describe 'with 2 roles available' do
let(:roles) { [
FactoryGirl.build(:role), FactoryGirl.build(:role)
] }
it { should have_json_path('roles') }
it { should have_json_size(2).at_path('roles') }
it { should have_json_type(Object).at_path('roles/1') }
it { should have_json_path('roles/1/name') }
end
end

@ -0,0 +1,59 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/versions/index.api.rabl' do
before do
params[:format] = 'json'
assign(:versions, versions)
render
end
subject { response.body }
describe 'with no versions available' do
let(:versions) { [] }
it { should have_json_path('versions') }
it { should have_json_size(0).at_path('versions') }
end
describe 'with 2 versions available' do
let(:versions) { [
FactoryGirl.build(:version), FactoryGirl.build(:version)
] }
it { should have_json_path('versions') }
it { should have_json_size(2).at_path('versions') }
it { should have_json_type(Object).at_path('versions/1') }
it { should have_json_path('versions/1/name') }
end
end

@ -0,0 +1,56 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/work_packages/column_data.api.rabl' do
before do
params[:format] = 'json'
assign(:columns_data, columns_data)
render
end
subject { response.body }
describe 'with no column data' do
let(:columns_data) { [] }
it { should have_json_path('columns_data') }
it { should have_json_size(0).at_path('columns_data') }
end
describe 'with column data' do
let(:columns_data) { [[{ id: 1, name: 'Dairy Queen' }, { id: 2, name: 'Baskin Robbins' }]] }
it { should have_json_path('columns_data') }
it { should have_json_type(Array).at_path('columns_data') }
it { should have_json_type(Array).at_path('columns_data/0') }
it { should have_json_type(Object).at_path('columns_data/0/0') }
end
end

@ -0,0 +1,57 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/work_packages/column_sums.api.rabl' do
before do
params[:format] = 'json'
assign(:column_sums, column_sums)
render
end
subject { response.body }
describe 'with no summed columns' do
let(:column_sums) { [] }
it { should have_json_path('column_sums') }
it { should have_json_size(0).at_path('column_sums') }
end
describe 'with 4 summed columns' do
let(:column_sums) { [45, 67, 12.99, 44444444444] }
it { should have_json_path('column_sums') }
it { should have_json_size(4).at_path('column_sums') }
it { should have_json_type(Float).at_path('column_sums/2') }
it { should have_json_type(Integer).at_path('column_sums/3') }
end
end

@ -0,0 +1,83 @@
#-- 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.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v3/work_packages/index.api.rabl' do
before do
params[:format] = 'json'
assign(:work_packages, work_packages)
assign(:column_names, column_names)
assign(:custom_field_column_names, custom_field_column_names)
render
end
subject { response.body }
describe 'with no work packages available' do
let(:work_packages) { [] }
let(:column_names) { [] }
let(:custom_field_column_names) { [] }
it { should have_json_path('work_packages') }
it { should have_json_size(0).at_path('work_packages') }
end
describe 'with 3 work packages but no columns' do
let(:work_packages) { [
FactoryGirl.build(:work_package),
FactoryGirl.build(:work_package),
FactoryGirl.build(:work_package)
] }
let(:column_names) { [] }
let(:custom_field_column_names) { [] }
it { should have_json_path('work_packages') }
it { should have_json_size(3).at_path('work_packages') }
it { should have_json_type(Object).at_path('work_packages/2') }
end
describe 'with 2 work packages and columns' do
let(:work_packages) { [
FactoryGirl.build(:work_package),
FactoryGirl.build(:work_package)
] }
let(:column_names) { %w(subject description due_date) }
let(:custom_field_column_names) { [] }
it { should have_json_path('work_packages') }
it { should have_json_size(2).at_path('work_packages') }
it { should have_json_type(Object).at_path('work_packages/1') }
it { should have_json_path('work_packages/1/subject') }
it { should have_json_path('work_packages/1/description') }
it { should have_json_path('work_packages/1/due_date') }
end
end
Loading…
Cancel
Save