From 26b8c50835d56ef109d0d12dd841b11766e2f943 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 1 Nov 2013 10:27:01 +0000 Subject: [PATCH] render custom_fields in rabl views eagerly load custom field translations --- app/controllers/api/v2/planning_elements_controller.rb | 3 ++- app/controllers/api/v2/projects_controller.rb | 3 ++- app/views/api/v2/planning_elements/_planning_element.api.rabl | 3 +++ app/views/api/v2/projects/_project.api.rabl | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v2/planning_elements_controller.rb b/app/controllers/api/v2/planning_elements_controller.rb index 7fadea1b24..111d2dca44 100644 --- a/app/controllers/api/v2/planning_elements_controller.rb +++ b/app/controllers/api/v2/planning_elements_controller.rb @@ -80,7 +80,8 @@ module Api end def show - @planning_element = @project.work_packages.find(params[:id]) + @planning_element = @project.work_packages.find params[:id], + :include => [{:custom_values => [{:custom_field => :translations}]}] respond_to do |format| format.api diff --git a/app/controllers/api/v2/projects_controller.rb b/app/controllers/api/v2/projects_controller.rb index 77a7083545..b380c21194 100644 --- a/app/controllers/api/v2/projects_controller.rb +++ b/app/controllers/api/v2/projects_controller.rb @@ -80,7 +80,8 @@ module Api protected def find_project - @project = Project.find(params[:id]) + @project = Project.find params[:id], + :include => [{:custom_values => [{:custom_field => :translations}]}] end def build_associations diff --git a/app/views/api/v2/planning_elements/_planning_element.api.rabl b/app/views/api/v2/planning_elements/_planning_element.api.rabl index a1b8a49998..5ad423608d 100644 --- a/app/views/api/v2/planning_elements/_planning_element.api.rabl +++ b/app/views/api/v2/planning_elements/_planning_element.api.rabl @@ -75,6 +75,9 @@ node :assigned_to, if: lambda{|pe| pe.assigned_to.present?} do |pe| end end +node :custom_fields do + partial "api/v2/custom_fields/values", :object => (locals[:object] || @planning_element).custom_values +end node :journals, if: lambda{|pe| include_journals?} do |pe| pe.journals.map do |journal| diff --git a/app/views/api/v2/projects/_project.api.rabl b/app/views/api/v2/projects/_project.api.rabl index e273617511..1004c8831b 100644 --- a/app/views/api/v2/projects/_project.api.rabl +++ b/app/views/api/v2/projects/_project.api.rabl @@ -82,3 +82,6 @@ node :parent, if: lambda{|project| visible_parent_project(project).present?} do { id: parent.id, name: parent.name, identifier: parent.identifier } end +node :custom_fields do + partial "api/v2/custom_fields/values", :object => (locals[:object] || @project).custom_values +end