summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-20 11:30:57 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-20 11:30:57 +0000
commit44ac1a0debc802b2ecbaa7cf7f763b373bf0fbb4 (patch)
tree392f95068f7a93f1ddb921dced7bb34815916382 /app/controllers
parent1b002983c31f0936b38d56d2f3d8731f724fc5ef (diff)
downloadredmine-44ac1a0debc802b2ecbaa7cf7f763b373bf0fbb4.tar.gz
redmine-44ac1a0debc802b2ecbaa7cf7f763b373bf0fbb4.zip
ProjectsController#add_issue moved to IssuesController#new.
Tracker can now be changed/selected on the new issue form. This action can be invoked without the tracker_id parameter (the first enabled tracker will be used by default). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1080 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/issues_controller.rb64
-rw-r--r--app/controllers/projects_controller.rb42
2 files changed, 62 insertions, 44 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 11112289e..7a48282c9 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -17,11 +17,13 @@
class IssuesController < ApplicationController
layout 'base'
- before_filter :find_project, :authorize, :except => [:index, :changes, :preview]
+ before_filter :find_issue, :except => [:index, :changes, :preview, :new, :update_form]
+ before_filter :find_project, :only => [:new, :update_form]
+ before_filter :authorize, :except => [:index, :changes, :preview, :update_form]
before_filter :find_optional_project, :only => [:index, :changes]
accept_key_auth :index, :changes
- cache_sweeper :issue_sweeper, :only => [ :edit, :update, :destroy ]
+ cache_sweeper :issue_sweeper, :only => [ :new, :edit, :update, :destroy ]
helper :projects
include ProjectsHelper
@@ -90,6 +92,51 @@ class IssuesController < ApplicationController
end
end
+ # Add a new issue
+ # The new issue will be created from an existing one if copy_from parameter is given
+ def new
+ @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
+ @issue.project = @project
+ @issue.author = User.current
+ @issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
+ if @issue.tracker.nil?
+ flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
+ render :nothing => true, :layout => true
+ return
+ end
+
+ default_status = IssueStatus.default
+ unless default_status
+ flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
+ render :nothing => true, :layout => true
+ return
+ end
+ @issue.status = default_status
+ @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
+
+ if request.get? || request.xhr?
+ @issue.start_date ||= Date.today
+ @custom_values = @issue.custom_values.empty? ?
+ @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
+ @issue.custom_values
+ else
+ requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
+ # Check that the user is allowed to apply the requested status
+ @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
+ @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
+ @issue.custom_values = @custom_values
+ if @issue.save
+ attach_files(@issue, params[:attachments])
+ flash[:notice] = l(:notice_successful_create)
+ Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
+ redirect_to :controller => 'issues', :action => 'index', :project_id => @project
+ return
+ end
+ end
+ @priorities = Enumeration::get_values('IPRI')
+ render :layout => !request.xhr?
+ end
+
def edit
@priorities = Enumeration::get_values('IPRI')
@custom_values = []
@@ -185,6 +232,11 @@ class IssuesController < ApplicationController
render :layout => false
end
+ def update_form
+ @issue = Issue.new(params[:issue])
+ render :action => :new, :layout => false
+ end
+
def preview
issue = Issue.find_by_id(params[:id])
@attachements = issue.attachments if issue
@@ -193,13 +245,19 @@ class IssuesController < ApplicationController
end
private
- def find_project
+ def find_issue
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
@project = @issue.project
rescue ActiveRecord::RecordNotFound
render_404
end
+ def find_project
+ @project = Project.find(params[:project_id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
def find_optional_project
return true unless params[:project_id]
@project = Project.find(params[:project_id])
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index f38ca828e..2342e8074 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -22,7 +22,7 @@ class ProjectsController < ApplicationController
menu_item :roadmap, :only => :roadmap
menu_item :files, :only => [:list_files, :add_file]
menu_item :settings, :only => :settings
- menu_item :issues, :only => [:add_issue, :bulk_edit_issues, :changelog, :move_issues]
+ menu_item :issues, :only => [:bulk_edit_issues, :changelog, :move_issues]
before_filter :find_project, :except => [ :index, :list, :add ]
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
@@ -30,7 +30,6 @@ class ProjectsController < ApplicationController
accept_key_auth :activity, :calendar
cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
- cache_sweeper :issue_sweeper, :only => [ :add_issue ]
cache_sweeper :version_sweeper, :only => [ :add_version ]
helper :sort
@@ -184,45 +183,6 @@ class ProjectsController < ApplicationController
end
end
- # Add a new issue to @project
- # The new issue will be created from an existing one if copy_from parameter is given
- def add_issue
- @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
- @issue.project = @project
- @issue.author = User.current
- @issue.tracker ||= @project.trackers.find(params[:tracker_id])
-
- default_status = IssueStatus.default
- unless default_status
- flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
- render :nothing => true, :layout => true
- return
- end
- @issue.status = default_status
- @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
-
- if request.get?
- @issue.start_date ||= Date.today
- @custom_values = @issue.custom_values.empty? ?
- @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
- @issue.custom_values
- else
- requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
- # Check that the user is allowed to apply the requested status
- @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
- @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
- @issue.custom_values = @custom_values
- if @issue.save
- attach_files(@issue, params[:attachments])
- flash[:notice] = l(:notice_successful_create)
- Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
- redirect_to :controller => 'issues', :action => 'index', :project_id => @project
- return
- end
- end
- @priorities = Enumeration::get_values('IPRI')
- end
-
# Bulk edit issues
def bulk_edit_issues
if request.post?