adapt representer

pull/6827/head
Jens Ulferts 8 years ago
parent 19cef1504e
commit f3dd253498
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 4
      lib/api/v3/budgets/budget_representer.rb
  2. 4
      lib/api/v3/cost_entries/aggregated_cost_entry_representer.rb
  3. 10
      lib/api/v3/cost_entries/cost_entry_representer.rb
  4. 13
      lib/api/v3/cost_entries/work_package_costs_by_type_representer.rb
  5. 2
      lib/api/v3/cost_types/cost_type_representer.rb
  6. 10
      lib/open_project/costs/engine.rb

@ -24,7 +24,7 @@ module API
module V3
module Budgets
class BudgetRepresenter < ::API::Decorators::Single
self_link title_getter: -> (*) { represented.subject }
self_link title_getter: ->(*) { represented.subject }
link :staticPath do
{
href: cost_object_path(represented.id)
@ -34,8 +34,6 @@ module API
property :id, render_nil: true
property :subject, render_nil: true
private
def _type
'Budget'
end

@ -36,9 +36,7 @@ module API
property :spent_units,
exec_context: :decorator,
getter: -> (*) { @spent_units }
private
getter: ->(*) { @spent_units }
def _type
'AggregatedCostEntry'

@ -21,27 +21,27 @@ module API
module V3
module CostEntries
class CostEntryRepresenter < ::API::Decorators::Single
self_link title_getter: -> (*) { nil }
self_link title_getter: ->(*) { nil }
linked_property :project, embed_as: ::API::V3::Projects::ProjectRepresenter
linked_property :user, embed_as: ::API::V3::Users::UserRepresenter
linked_property :cost_type, embed_as: ::API::V3::CostTypes::CostTypeRepresenter
# for now not embedded, because work packages are quite large
linked_property :work_package, title_getter: -> (*) { represented.work_package.subject }
linked_property :work_package, title_getter: ->(*) { represented.work_package.subject }
property :id, render_nil: true
property :units, as: :spentUnits
property :spent_on,
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_date(represented.spent_on) }
getter: ->(*) { datetime_formatter.format_date(represented.spent_on) }
property :created_on,
as: 'createdAt',
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.created_on) }
getter: ->(*) { datetime_formatter.format_datetime(represented.created_on) }
property :updated_on,
as: 'updatedAt',
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_on) }
getter: ->(*) { datetime_formatter.format_datetime(represented.updated_on) }
def _type
'CostEntry'

@ -1,4 +1,5 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
@ -40,24 +41,22 @@ module API
property :total,
exec_context: :decorator,
getter: -> (*) { cost_helper.summarized_cost_entries.size }
getter: ->(*) { cost_helper.summarized_cost_entries.size }
property :count,
exec_context: :decorator,
getter: -> (*) { cost_helper.summarized_cost_entries.size }
getter: ->(*) { cost_helper.summarized_cost_entries.size }
collection :elements,
getter: -> (*) {
cost_helper.summarized_cost_entries.map { |kvp|
getter: ->(*) {
cost_helper.summarized_cost_entries.map do |kvp|
type = kvp[0]
units = kvp[1]
::API::V3::CostEntries::AggregatedCostEntryRepresenter.new(type, units)
}
end
},
exec_context: :decorator,
embedded: true
private
def cost_helper
@cost_helper ||= ::OpenProject::Costs::AttributesHelper.new(represented, current_user)
end

@ -29,7 +29,7 @@ module API
property :unit_plural,
render_nil: true
property :is_default,
getter: -> (*) { default }
getter: ->(*) { default }
def _type
'CostType'

@ -217,7 +217,7 @@ module OpenProject::Costs
linked_property :cost_object,
path: :budget,
namespace: :budgets,
show_if: -> (*) { represented.costs_enabled? }
show_if: ->(*) { costs_enabled? }
end
extend_api_response(:v3, :work_packages, :schema, :work_package_schema) do
@ -227,25 +227,25 @@ module OpenProject::Costs
type: 'String',
required: false,
writable: false,
show_if: -> (*) { represented.project && represented.project.costs_enabled? }
show_if: ->(*) { represented.project && represented.project.costs_enabled? }
schema :labor_costs,
type: 'String',
required: false,
writable: false,
show_if: -> (*) { represented.project && represented.project.costs_enabled? }
show_if: ->(*) { represented.project && represented.project.costs_enabled? }
schema :material_costs,
type: 'String',
required: false,
writable: false,
show_if: -> (*) { represented.project && represented.project.costs_enabled? }
show_if: ->(*) { represented.project && represented.project.costs_enabled? }
schema :costs_by_type,
type: 'Collection',
name_source: :spent_units,
required: false,
show_if: -> (*) { represented.project && represented.project.costs_enabled? },
show_if: ->(*) { represented.project && represented.project.costs_enabled? },
writable: false
schema_with_allowed_collection :cost_object,

Loading…
Cancel
Save