diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-01-14 20:00:17 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-01-14 20:00:17 +0000 |
commit | 68a4cd38f54316e6d93ce69b6e25afc329652013 (patch) | |
tree | d2adb8c4aa3fceb2d088c0b31a5913ef60aaa31c /app | |
parent | 64f4b50139a7ef9e33fc7df00caf4fab028e1cef (diff) | |
download | redmine-68a4cd38f54316e6d93ce69b6e25afc329652013.tar.gz redmine-68a4cd38f54316e6d93ce69b6e25afc329652013.zip |
XML REST API for Projects (#296).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3313 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 56 | ||||
-rw-r--r-- | app/views/projects/index.xml.builder | 18 | ||||
-rw-r--r-- | app/views/projects/show.xml.builder | 16 |
4 files changed, 81 insertions, 10 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d696955c3..9f3169a4b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,6 +22,7 @@ class ApplicationController < ActionController::Base include Redmine::I18n layout 'base' + exempt_from_layout 'builder' # Remove broken cookie after upgrade from 0.8.x (#4292) # See https://rails.lighthouseapp.com/projects/8994/tickets/3360 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e908388ee..bd2e2a8dc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -53,6 +53,9 @@ class ProjectsController < ApplicationController format.html { @projects = Project.visible.find(:all, :order => 'lft') } + format.xml { + @projects = Project.visible.find(:all, :order => 'lft') + } format.atom { projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i) @@ -81,8 +84,18 @@ class ProjectsController < ApplicationController m = Member.new(:user => User.current, :roles => [r]) @project.members << m end - flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'settings', :id => @project + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'projects', :action => 'settings', :id => @project + } + format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } + end + else + respond_to do |format| + format.html + format.xml { render :xml => @project.errors, :status => :unprocessable_entity } + end end end end @@ -147,6 +160,11 @@ class ProjectsController < ApplicationController :conditions => cond).to_f end @key = User.current.rss_key + + respond_to do |format| + format.html + format.xml + end end def settings @@ -160,15 +178,26 @@ class ProjectsController < ApplicationController # Edit @project def edit - if request.post? + if request.get? + else @project.attributes = params[:project] if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'settings', :id => @project + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to :action => 'settings', :id => @project + } + format.xml { head :ok } + end else - settings - render :action => 'settings' + respond_to do |format| + format.html { + settings + render :action => 'settings' + } + format.xml { render :xml => @project.errors, :status => :unprocessable_entity } + end end end end @@ -195,9 +224,16 @@ class ProjectsController < ApplicationController # Delete @project def destroy @project_to_destroy = @project - if request.post? and params[:confirm] - @project_to_destroy.destroy - redirect_to :controller => 'admin', :action => 'projects' + if request.get? + # display confirmation view + else + if params[:format] == 'xml' || params[:confirm] + @project_to_destroy.destroy + respond_to do |format| + format.html { redirect_to :controller => 'admin', :action => 'projects' } + format.xml { head :ok } + end + end end # hide project in layout @project = nil diff --git a/app/views/projects/index.xml.builder b/app/views/projects/index.xml.builder new file mode 100644 index 000000000..637ae7ef6 --- /dev/null +++ b/app/views/projects/index.xml.builder @@ -0,0 +1,18 @@ +xml.instruct! +xml.projects :type => 'array' do + @projects.each do |project| + xml.project :id => project.id do + xml.name project.name + xml.identifier project.identifier + xml.description project.description + xml.parent(:id => project.parent_id, :name => project.parent.name) unless project.parent.nil? + xml.custom_fields do + project.custom_field_values.each do |custom_value| + xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name + end + end unless project.custom_field_values.empty? + xml.created_on project.created_on + xml.updated_on project.updated_on + end + end +end diff --git a/app/views/projects/show.xml.builder b/app/views/projects/show.xml.builder new file mode 100644 index 000000000..3c4241d4c --- /dev/null +++ b/app/views/projects/show.xml.builder @@ -0,0 +1,16 @@ +xml.instruct! +xml.project :id => @project.id do + xml.name @project.name + xml.identifier @project.identifier + xml.description @project.description + xml.homepage @project.homepage + + xml.custom_fields do + @project.custom_field_values.each do |custom_value| + xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name + end + end unless @project.custom_field_values.empty? + + xml.created_on @project.created_on + xml.updated_on @project.updated_on +end |