diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-09-29 10:08:30 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-09-29 10:08:30 +0000 |
commit | 886284b33f1a670be32ff5fd2f93e76089c4d813 (patch) | |
tree | 8aedaabb0fc042b41137516ec9a75936b54f34c9 /app | |
parent | 4a36e09d4947425b41dd4d72f6a1a13146922878 (diff) | |
download | redmine-886284b33f1a670be32ff5fd2f93e76089c4d813.tar.gz redmine-886284b33f1a670be32ff5fd2f93e76089c4d813.zip |
REST API: custom fields definition (#11159).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12165 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/custom_fields_controller.rb | 12 | ||||
-rw-r--r-- | app/models/custom_field.rb | 6 | ||||
-rw-r--r-- | app/views/custom_fields/index.api.rsb | 42 |
3 files changed, 56 insertions, 4 deletions
diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index c20516a1d..95d0d507f 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -21,10 +21,18 @@ class CustomFieldsController < ApplicationController before_filter :require_admin before_filter :build_new_custom_field, :only => [:new, :create] before_filter :find_custom_field, :only => [:edit, :update, :destroy] + accept_api_auth :index def index - @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } - @tab = params[:tab] || 'IssueCustomField' + respond_to do |format| + format.html { + @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } + @tab = params[:tab] || 'IssueCustomField' + } + format.api { + @custom_fields = CustomField.all + } + end end def new diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 937f9f4d0..f482973cf 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -123,8 +123,10 @@ class CustomField < ActiveRecord::Base values.each do |value| value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) end + values + else + [] end - values || [] end end @@ -301,7 +303,7 @@ class CustomField < ActiveRecord::Base def self.customized_class self.name =~ /^(.+)CustomField$/ - begin; $1.constantize; rescue nil; end + $1.constantize rescue nil end # to move in project_custom_field diff --git a/app/views/custom_fields/index.api.rsb b/app/views/custom_fields/index.api.rsb new file mode 100644 index 000000000..e640f3315 --- /dev/null +++ b/app/views/custom_fields/index.api.rsb @@ -0,0 +1,42 @@ +api.array :custom_fields do + @custom_fields.each do |field| + api.custom_field do + api.id field.id + api.name field.name + api.customized_type field.class.customized_class.name.underscore if field.class.customized_class + api.field_format field.field_format + api.regexp field.regexp + api.min_length (field.min_length == 0 ? nil : field.min_length) + api.max_length (field.max_length == 0 ? nil : field.max_length) + api.is_required field.is_required? + api.is_filter field.is_filter? + api.searchable field.searchable + api.multiple field.multiple? + api.default_value field.default_value + api.visible field.visible? + + if field.field_format == 'list' + api.array :possible_values do + field.possible_values.each do |v| + api.possible_value do + api.value v + end + end + end + end + + if field.is_a?(IssueCustomField) + api.trackers do + field.trackers.each do |tracker| + api.tracker :id => tracker.id, :name => tracker.name + end + end + api.roles do + field.roles.each do |role| + api.role :id => role.id, :name => role.name + end + end + end + end + end +end |