add custom field values to api.

pull/863/head
Nils Kenneweg 11 years ago committed by Martin Czuchra
parent a2d8c266d6
commit bcc206aa09
  1. 18
      app/controllers/api/v2/planning_elements_controller.rb
  2. 4
      app/models/timeline.rb
  3. 6
      app/views/api/v2/planning_elements/index.api.rabl

@ -200,8 +200,22 @@ module Api
end
def convert_object_to_struct(model)
OpenStruct.new(model.attributes)
end
def convert_wp_object_to_struct(model)
result = convert_object_to_struct(model)
result.custom_values = model.custom_values.select{|cv| cv.value != ""}.map do |model|
convert_object_to_struct(model)
end
result
end
def convert_to_struct(collection)
collection.map{|model| OpenStruct.new(model.attributes)}
collection.map do |model|
convert_wp_object_to_struct(model)
end
end
def planning_comparison?
@ -223,7 +237,7 @@ module Api
def current_work_packages(projects)
work_packages = WorkPackage.for_projects(projects)
.changed_since(@since)
.includes(:status, :project, :type)
.includes(:status, :project, :type, :custom_values)
if params[:f]
#we need a project to make project-specific custom fields work

@ -180,6 +180,10 @@ class Timeline < ActiveRecord::Base
json.html_safe
end
def custom_field_columns
project.all_work_package_custom_fields.map { |a| {name: a.name, id: "cf_#{a.id}"}}
end
def available_columns
@@available_columns
end

@ -50,4 +50,8 @@ node :due_date, :if => lambda{|pe| pe.due_date.present?} {|pe| pe.due_date.to_fo
node :created_at, if: lambda{|pe| pe.created_at.present?} {|pe| pe.created_at.utc}
node :updated_at, if: lambda{|pe| pe.updated_at.present?} {|pe| pe.updated_at.utc}
node do |element|
element.custom_values.each do |ele|
node(:"cf_#{ele.custom_field_id}") { ele.value }
end
end
Loading…
Cancel
Save