- own representer for property schema - two subclasses for either linked or embedded allowed values - no special subclasses per represented typepull/2536/head
parent
8debd27c32
commit
777566a0b8
@ -1,85 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- 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. |
||||
#++ |
||||
|
||||
require 'roar/decorator' |
||||
require 'roar/json/hal' |
||||
|
||||
module API |
||||
module Decorators |
||||
class AllowedReferenceLinkRepresenter < Roar::Decorator |
||||
include Roar::JSON::HAL |
||||
|
||||
def initialize(link, type, title, required, writable) |
||||
@link = link |
||||
@type = type |
||||
@name = title |
||||
@required = required |
||||
@writable = writable |
||||
|
||||
super(link) |
||||
end |
||||
|
||||
self.as_strategy = ::API::Utilities::CamelCasingStrategy.new |
||||
|
||||
property :_links, |
||||
exec_context: :decorator, |
||||
getter: -> (*) { link } do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
self.as_strategy = ::API::Utilities::CamelCasingStrategy.new |
||||
|
||||
property :allowed_values, |
||||
getter: -> (*) { |
||||
{ href: represented } |
||||
}, |
||||
exec_context: :decorator |
||||
end |
||||
|
||||
property :type, |
||||
exec_context: :decorator |
||||
|
||||
property :name, |
||||
exec_context: :decorator |
||||
|
||||
property :required, |
||||
exec_context: :decorator |
||||
|
||||
property :writable, |
||||
exec_context: :decorator |
||||
|
||||
private |
||||
|
||||
attr_reader :link, |
||||
:type, |
||||
:name, |
||||
:required, |
||||
:writable |
||||
end |
||||
end |
||||
end |
@ -1,86 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- 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. |
||||
#++ |
||||
|
||||
require 'roar/decorator' |
||||
require 'roar/json/hal' |
||||
|
||||
module API |
||||
module Decorators |
||||
class SchemaAllowedValuesRepresenter < Single |
||||
def initialize(model, type, name, required, writable, context = {}) |
||||
@type = type |
||||
@name = name |
||||
@required = required |
||||
@writable = writable |
||||
|
||||
super(model, context) |
||||
end |
||||
|
||||
property :links, |
||||
as: :_links, |
||||
exec_context: :decorator |
||||
|
||||
property :type, |
||||
exec_context: :decorator |
||||
|
||||
property :name, |
||||
exec_context: :decorator |
||||
|
||||
property :required, |
||||
exec_context: :decorator |
||||
|
||||
property :writable, |
||||
exec_context: :decorator |
||||
|
||||
collection :allowed_values, |
||||
exec_context: :decorator, |
||||
embedded: true |
||||
|
||||
private |
||||
|
||||
class_attribute :value_representer, |
||||
:links_factory |
||||
|
||||
attr_reader :type, |
||||
:name, |
||||
:required, |
||||
:writable |
||||
|
||||
def links |
||||
AllowedLinksRepresenter.new(represented, links_factory) |
||||
end |
||||
|
||||
def allowed_values |
||||
represented.map do |object| |
||||
value_representer.new(object, current_user: context[:current_user]) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,58 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- 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. |
||||
#++ |
||||
|
||||
require 'roar/decorator' |
||||
require 'roar/json/hal' |
||||
|
||||
module API |
||||
module V3 |
||||
module WorkPackages |
||||
module Schema |
||||
class SchemaAllowedPrioritiesRepresenter < Decorators::SchemaAllowedValuesRepresenter |
||||
def initialize(model, context = {}) |
||||
super(model, |
||||
'Priority', |
||||
I18n.t('activerecord.attributes.work_package.priority'), |
||||
true, |
||||
true, |
||||
context) |
||||
end |
||||
|
||||
self.value_representer = Priorities::PriorityRepresenter |
||||
|
||||
self.links_factory = -> (priority) do |
||||
extend API::V3::Utilities::PathHelper |
||||
|
||||
{ href: api_v3_paths.priority(priority.id), title: priority.name } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue