parent
057bebcd99
commit
50af8e50dd
@ -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 |
Loading…
Reference in new issue