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
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -194,6 +194,6 @@ module ProjectsHelper
|
||||
# can't use form tag inside helper
|
||||
content_tag('form',
|
||||
select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
|
||||
:action => url_for(:controller => 'projects', :action => 'add_issue', :id => @project), :method => 'get')
|
||||
:action => url_for(:controller => 'issues', :action => 'new', :project_id => @project), :method => 'get')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<%= error_messages_for 'issue' %>
|
||||
<div class="box">
|
||||
|
||||
<% if @issue.new_record? %>
|
||||
<p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p>
|
||||
<%= observe_field :issue_tracker_id, :url => { :action => :new },
|
||||
:update => :content,
|
||||
:with => "Form.serialize('issue-form')" %>
|
||||
<% end %>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<% if @issue.new_record? %>
|
||||
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% if authorize_for('projects', 'add_issue') && @project.trackers.any? %>
|
||||
<% if authorize_for('issues', 'new') && @project.trackers.any? %>
|
||||
<h3><%= l(:label_issue_new) %></h3>
|
||||
<%= l(:label_tracker) %>: <%= new_issue_selector %>
|
||||
<% end %>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
:selected => @issue.assigned_to.nil?, :disabled => !@can[:assign] %></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><%= context_menu_link l(:button_copy), {:controller => 'projects', :action => 'add_issue', :id => @project, :copy_from => @issue},
|
||||
<li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
|
||||
:class => 'icon-copy', :disabled => !@can[:copy] %></li>
|
||||
<li><%= context_menu_link l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id },
|
||||
:class => 'icon-move', :disabled => !@can[:move] %>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<h2><%=l(:label_issue_new)%>: <%= @issue.tracker %></h2>
|
||||
|
||||
<% labelled_tabular_form_for :issue, @issue,
|
||||
:url => {:action => 'add_issue'},
|
||||
:html => {:multipart => true, :id => 'issue-form'} do |f| %>
|
||||
<%= f.hidden_field :tracker_id %>
|
||||
<%= render :partial => 'issues/form', :locals => {:f => f} %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to_remote l(:label_preview),
|
||||
@@ -3,7 +3,7 @@
|
||||
<%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
|
||||
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
|
||||
<%= watcher_tag(@issue, User.current) %>
|
||||
<%= link_to_if_authorized l(:button_copy), {:controller => 'projects', :action => 'add_issue', :id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
|
||||
<%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
|
||||
<%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
|
||||
<%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
|
||||
</div>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
</div>
|
||||
|
||||
<% content_for :sidebar do %>
|
||||
<% if authorize_for('projects', 'add_issue') && @project.trackers.any? %>
|
||||
<% if authorize_for('issues', 'new') && @project.trackers.any? %>
|
||||
<h3><%= l(:label_issue_new) %></h3>
|
||||
<%= l(:label_tracker) %>: <%= new_issue_selector %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user