query custom_fields and output them for planning_elements and projects

pull/523/head
Markus Kahl 11 years ago
parent 78cd9bd675
commit 642e9c16c6
  1. 27
      app/controllers/api/v2/custom_fields_controller.rb
  2. 3
      app/helpers/planning_elements_helper.rb
  3. 26
      app/views/api/v2/custom_fields/_custom_field.api.rsb
  4. 5
      app/views/api/v2/custom_fields/_custom_field_value.api.rsb
  5. 6
      app/views/api/v2/custom_fields/_custom_field_values.api.rsb
  6. 5
      app/views/api/v2/custom_fields/index.api.rsb
  7. 1
      app/views/api/v2/custom_fields/show.api.rsb
  8. 2
      config/routes.rb

@ -0,0 +1,27 @@
module Api
module V2
class CustomFieldsController < ApplicationController
include ::Api::V2::ApiController
def index
@custom_fields = CustomField.find :all,
:offset => params[:offset],
:limit => params[:limit]
respond_to do |format|
format.api
end
end
def show
@custom_field = CustomField.find params[:id]
respond_to do |format|
format.api
end
end
end
end
end

@ -79,6 +79,9 @@ module PlanningElementsHelper
api.created_at(planning_element.created_at.utc) if planning_element.created_at
api.updated_at(planning_element.updated_at.utc) if planning_element.updated_at
render :partial => '/api/v2/custom_fields/custom_field_values.api',
:locals => {:custom_field_values => planning_element.custom_field_values}
end
end

@ -0,0 +1,26 @@
api.custom_field do
api.id custom_field.id
api.name custom_field.name
api.customized_type custom_field.type.gsub(/CustomField$/, '').underscore
api.field_format custom_field.field_format
api.regexp custom_field.regexp
api.min_length custom_field.min_length
api.max_length custom_field.max_length
api.is_required custom_field.is_required
api.is_filter custom_field.is_filter
api.searchable custom_field.searchable
api.is_for_all custom_field.is_for_all
api.position custom_field.position
api.editable custom_field.editable
api.visible custom_field.visible
if custom_field.field_format == 'list' && !custom_field.possible_values.empty?
api.array :possible_values, api_meta(:size => custom_field.possible_values.size) do
custom_field.possible_values.each do |possible_value|
api.possible_value do
api.value possible_value
end
end
end
end
end

@ -0,0 +1,5 @@
api.custom_field do
api.name custom_field_value.custom_field.name
api.value custom_field_value.value
api.id custom_field_value.custom_field.id
end

@ -0,0 +1,6 @@
api.array :custom_fields, api_meta(:size => custom_field_values.size) do
custom_field_values.each do |custom_field_value|
render :partial => '/api/v2/custom_fields/custom_field_value.api',
:locals => {:custom_field_value => custom_field_value}
end
end

@ -0,0 +1,5 @@
api.array :custom_fields, api_meta(:size => @custom_fields.size) do
@custom_fields.each do |custom_field|
render :partial => '/api/v2/custom_fields/custom_field.api', :object => custom_field
end
end

@ -0,0 +1 @@
render :partial => '/api/v2/custom_fields/custom_field.api', :object => @custom_field

@ -81,6 +81,7 @@ OpenProject::Application.routes.draw do
resources :statuses, :only => [:index, :show]
end
resources :custom_fields
namespace :pagination, :as => 'paginate' do
[:users,
@ -93,6 +94,7 @@ OpenProject::Application.routes.draw do
resources model, :only => [:index]
end
end
end
end

Loading…
Cancel
Save