move v3 naming into own module

pull/4159/head
Jens Ulferts 9 years ago
parent 057bebcd99
commit 50af8e50dd
  1. 6
      app/controllers/api/experimental/concerns/column_data.rb
  2. 30
      app/controllers/api/experimental/concerns/query_loading.rb
  3. 79
      app/controllers/api/experimental/concerns/v3_naming.rb
  4. 3
      app/controllers/api/experimental/queries_controller.rb
  5. 22
      app/controllers/api/experimental/work_packages_controller.rb
  6. 7
      frontend/app/components/api/api-work-packages/api-work-packages.service.ts

@ -29,7 +29,7 @@
module Api::Experimental::Concerns::ColumnData
def get_columns_for_json(columns)
columns.map do |column|
{ name: v3_name(column.name),
{ name: internal_to_v3_name(column.name),
title: column.caption,
sortable: column.sortable?,
groupable: column.groupable?,
@ -42,10 +42,6 @@ module Api::Experimental::Concerns::ColumnData
private
def v3_name(string)
API::Utilities::PropertyNameConverter.from_ar_name(string)
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

@ -47,36 +47,6 @@ module Api::Experimental::Concerns::QueryLoading
@query
end
def external_to_internal_name(string, append_id: true)
API::Utilities::PropertyNameConverter.to_ar_name(string, context: WorkPackage.new, refer_to_ids: append_id)
end
def internal_to_external_name(string)
API::Utilities::PropertyNameConverter.from_ar_name(string)
end
def translate_query_params
params[:c] = (params[:c] || []).map { |column|
external_to_internal_name(column, append_id: false)
}
params[:f] = (params[:f] || []).map { |column|
external_to_internal_name(column)
}
params[:op] = (params[:op] || []).each_with_object({}) { |(column, operator), hash|
hash[external_to_internal_name(column)] = operator
}
params[:v] = (params[:v] || []).each_with_object({}) { |(column, value), hash|
hash[external_to_internal_name(column)] = value
}
params[:sort] = begin
(params[:sort] || '').split(',').map { |sort|
criteria = sort.split(':')
"#{external_to_internal_name(criteria.first, append_id: false)}:#{criteria.last}"
}.join(',')
end
end
def prepare_query
# Set the query properties only if a query property string exists in the
# URL. This assumes that if 'accept_empty_query_fields' or 'is_public'

@ -0,0 +1,79 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 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::Experimental::Concerns::V3Naming
def v3_to_internal_name(string, append_id: true)
API::Utilities::PropertyNameConverter.to_ar_name(string,
context: WorkPackage.new,
refer_to_ids: append_id)
end
def internal_to_v3_name(string)
API::Utilities::PropertyNameConverter.from_ar_name(string)
end
def v3_params_as_internal
params[:c] = params[:c].map { |column|
v3_to_internal_name(column, append_id: false)
} if params[:c]
params[:f] = params[:f].map { |column|
v3_to_internal_name(column)
} if params[:f]
params[:op] = params[:op].each_with_object({}) { |(column, operator), hash|
hash[v3_to_internal_name(column)] = operator
} if params[:op]
params[:v] = params[:v].each_with_object({}) { |(column, value), hash|
hash[v3_to_internal_name(column)] = value
} if params[:v]
params[:sort] = begin
(params[:sort] || '').split(',').map { |sort|
criteria = sort.split(':')
"#{v3_to_internal_name(criteria.first, append_id: false)}:#{criteria.last}"
}.join(',')
end if params[:sort]
end
def json_query_as_v3(json_query)
json_query['column_names'] = (json_query['column_names'] || []).map { |column|
internal_to_v3_name(column)
}
json_query['sort_criteria'] = (json_query['sort_criteria'] || []).map { |criteria|
[internal_to_v3_name(criteria.first), criteria.last]
}
json_query['group_by'] = internal_to_v3_name(json_query['group_by'])
json_query['filters'].each do |filter|
filter[:name] = internal_to_v3_name(filter[:name])
end
json_query
end
end

@ -32,13 +32,14 @@ module Api::Experimental
include Api::Experimental::Concerns::GrapeRouting
include Api::Experimental::Concerns::ColumnData
include Api::Experimental::Concerns::QueryLoading
include Api::Experimental::Concerns::V3Naming
include QueriesHelper
include ExtendedHTTP
before_filter :find_optional_project
before_filter :setup_query_for_create, only: [:create]
before_filter :translate_query_params, only: [:create, :update]
before_filter :v3_params_as_internal, only: [:create, :update]
before_filter :setup_existing_query, only: [:update, :destroy]
before_filter :authorize_on_query, only: [:create, :destroy]
before_filter :authorize_update_on_query, only: [:update]

@ -35,6 +35,7 @@ module Api
include ::Api::Experimental::Concerns::GrapeRouting
include ::Api::Experimental::Concerns::ColumnData
include ::Api::Experimental::Concerns::QueryLoading
include ::Api::Experimental::Concerns::V3Naming
include PaginationHelper
include QueriesHelper
@ -42,7 +43,7 @@ module Api
include ExtendedHTTP
before_filter :find_optional_project,
:translate_query_params,
:v3_params_as_internal,
:load_query
def index
@ -88,24 +89,7 @@ module Api
json_query[:_links] = allowed_links_on_query(query, user)
if json_query['column_names']
json_query['column_names'] = json_query['column_names'].map { |column|
internal_to_external_name(column)
}
end
if json_query['sort_criteria']
json_query['sort_criteria'] = json_query['sort_criteria'].map { |criteria|
[internal_to_external_name(criteria.first), criteria.last]
}
end
json_query['group_by'] = internal_to_external_name(json_query['group_by'])
json_query['filters'].each do |filter|
filter[:name] = internal_to_external_name(filter[:name])
end
json_query
json_query_as_v3(json_query)
end
def export_formats

@ -59,8 +59,7 @@ export class ApiWorkPackagesService {
const params = {
offset: offset,
pageSize: pageSize,
filters: [v3Filters],
sortBy: [query.sort_criteria],
filters: [v3Filters]
};
if (query.group_by) {
@ -71,6 +70,10 @@ export class ApiWorkPackagesService {
params['showSums'] = query.display_sums;
}
if (query.sort_criteria) {
params['sortBy'] = [query.sort_criteria];
}
return params;
}
}

Loading…
Cancel
Save