Fetching app wide custom value filters and caching values per project.

pull/1093/head
Richard 11 years ago
parent 602ab976b7
commit b2cfd11b70
  1. 2
      app/assets/javascripts/angular/directives/work_packages/query-filter-directive.js
  2. 10
      app/assets/javascripts/angular/filters/work-packages-filters.js
  3. 3
      app/assets/javascripts/angular/helpers/components/path-helper.js
  4. 6
      app/assets/javascripts/angular/models/query.js
  5. 63
      app/assets/javascripts/angular/services/query-service.js
  6. 6
      app/controllers/api/v3/queries_controller.rb
  7. 1
      config/routes.rb

@ -51,7 +51,7 @@ angular.module('openproject.workPackages.directives')
// Filter updates
scope.$watch('filter.operator', function(operator) {
if(operator) scope.showValuesInput = scope.filter.requiresValues();
if(operator && scope.filter.requiresValues) scope.showValuesInput = scope.filter.requiresValues();
});
scope.$watch('filter', function(filter, oldFilter) {

@ -34,11 +34,13 @@ angular.module('openproject.workPackages.filters')
.filter('subtractActiveFilters', [function() {
return function(availableFilters, selectedFilters) {
var filters = angular.copy(availableFilters);
if(availableFilters){
var filters = angular.copy(availableFilters);
angular.forEach(selectedFilters, function(filter) {
if(!filter.deactivated) delete filters[filter.name];
});
angular.forEach(selectedFilters, function(filter) {
if(!filter.deactivated) delete filters[filter.name];
});
}
return filters;
};

@ -83,6 +83,9 @@ angular.module('openproject.helpers')
apiAvailableColumnsPath: function() {
return PathHelper.apiPrefixV3 + '/queries/available_columns';
},
apiCustomFieldsPath: function() {
return PathHelper.apiPrefixV3 + '/queries/custom_field_filters';
},
apiProjectCustomFieldsPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + '/queries/custom_field_filters';
},

@ -116,7 +116,11 @@ angular.module('openproject.models')
},
getFilterType: function(filterName) {
return this.available_work_package_filters[filterName].type;
if (this.available_work_package_filters && this.available_work_package_filters[filterName]){
return this.available_work_package_filters[filterName].type;
} else {
return 'none';
}
},
getActiveFilters: function() {

@ -31,7 +31,7 @@ angular.module('openproject.services')
.service('QueryService', ['$http', 'PathHelper', '$q', 'AVAILABLE_WORK_PACKAGE_FILTERS', 'StatusService', 'TypeService', 'PriorityService', 'UserService', 'VersionService', 'RoleService', 'GroupService', 'ProjectService',
function($http, PathHelper, $q, AVAILABLE_WORK_PACKAGE_FILTERS, StatusService, TypeService, PriorityService, UserService, VersionService, RoleService, GroupService, ProjectService) {
var availableColumns = [], availableFilterValues = {}, availableFilters = null;
var availableColumns = [], availableFilterValues = {}, availableFilters = {};
var QueryService = {
getAvailableColumns: function(projectIdentifier) {
@ -41,26 +41,55 @@ angular.module('openproject.services')
},
getAvailableFilters: function(projectIdentifier){
if(availableFilters){
return $q.when(availableFilters);
} else{
if (projectIdentifier){
return QueryService.getCustomFieldFilters(projectIdentifier)
.then(function(data){
return QueryService.storeAvailableFilters(angular.extend(AVAILABLE_WORK_PACKAGE_FILTERS, data.custom_field_filters));
});
} else {
return $q.when(AVAILABLE_WORK_PACKAGE_FILTERS);
}
var identifier = 'global';
var getFilters = QueryService.getCustomFieldFilters;
var getFiltersArgs = [];
if(projectIdentifier){
identifier = projectIdentifier;
getFilters = QueryService.getProjectCustomFieldFilters;
getFiltersArgs.push(identifier);
}
if(availableFilters[identifier]){
return $q.when(availableFilters[identifier]);
} else {
return getFilters.apply(this, getFiltersArgs)
.then(function(data){
return QueryService.storeAvailableFilters(identifier, angular.extend(AVAILABLE_WORK_PACKAGE_FILTERS, data.custom_field_filters));
});
}
// if(projectIdentifier){
// if(availableFilters[projectIdentifier]){
// return $q.when(availableFilters[projectIdentifier]);
// } else {
// return QueryService.getProjectCustomFieldFilters(projectIdentifier)
// .then(function(data){
// return QueryService.storeAvailableFilters(projectIdentifier, angular.extend(AVAILABLE_WORK_PACKAGE_FILTERS, data.custom_field_filters));
// });
// }
// } else {
// if(availableFilters['global']){
// return $q.when(availableFilters['global']);
// } else {
// return QueryService.getCustomFieldFilters()
// .then(function(data){
// return QueryService.storeAvailableFilters('global', angular.extend(AVAILABLE_WORK_PACKAGE_FILTERS, data.custom_field_filters));
// });
// }
// }
},
getCustomFieldFilters: function(projectIdentifier) {
getProjectCustomFieldFilters: function(projectIdentifier) {
return QueryService.doQuery(PathHelper.apiProjectCustomFieldsPath(projectIdentifier));
},
getCustomFieldFilters: function() {
return QueryService.doQuery(PathHelper.apiCustomFieldsPath());
},
getAvailableFilterValues: function(filterName, projectIdentifier) {
return QueryService.getAvailableFilters()
return QueryService.getAvailableFilters(projectIdentifier)
.then(function(filters){
var filter = filters[filterName];
var modelName = filter.modelName
@ -125,9 +154,9 @@ angular.module('openproject.services')
return values;
},
storeAvailableFilters: function(filters){
availableFilters = filters;
return availableFilters;
storeAvailableFilters: function(projectIdentifier, filters){
availableFilters[projectIdentifier] = filters;
return availableFilters[projectIdentifier];
},
doQuery: function(url, params) {

@ -50,7 +50,11 @@ module Api::V3
end
def custom_field_filters
custom_fields = @project.all_work_package_custom_fields
custom_fields = if @project
@project.all_work_package_custom_fields
else
WorkPackageCustomField.for_all
end
@custom_field_filters = @query.get_custom_field_options(custom_fields)
respond_to do |format|

@ -123,6 +123,7 @@ OpenProject::Application.routes.draw do
end
resources :queries, only: [:show] do
get :available_columns, on: :collection
get :custom_field_filters, on: :collection
end
resources :projects, only: [:show, :index] do

Loading…
Cancel
Save