##// END OF EJS Templates
Render the project list as a tree on Move form....
Jean-Philippe Lang -
r2313:e944fc74df20
parent child
Show More
@@ -1,489 +1,489
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 menu_item :new_issue, :only => :new
19 menu_item :new_issue, :only => :new
20
20
21 before_filter :find_issue, :only => [:show, :edit, :reply]
21 before_filter :find_issue, :only => [:show, :edit, :reply]
22 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
22 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
23 before_filter :find_project, :only => [:new, :update_form, :preview]
23 before_filter :find_project, :only => [:new, :update_form, :preview]
24 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu]
24 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu]
25 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
25 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
26 accept_key_auth :index, :changes
26 accept_key_auth :index, :changes
27
27
28 helper :journals
28 helper :journals
29 helper :projects
29 helper :projects
30 include ProjectsHelper
30 include ProjectsHelper
31 helper :custom_fields
31 helper :custom_fields
32 include CustomFieldsHelper
32 include CustomFieldsHelper
33 helper :issue_relations
33 helper :issue_relations
34 include IssueRelationsHelper
34 include IssueRelationsHelper
35 helper :watchers
35 helper :watchers
36 include WatchersHelper
36 include WatchersHelper
37 helper :attachments
37 helper :attachments
38 include AttachmentsHelper
38 include AttachmentsHelper
39 helper :queries
39 helper :queries
40 helper :sort
40 helper :sort
41 include SortHelper
41 include SortHelper
42 include IssuesHelper
42 include IssuesHelper
43 helper :timelog
43 helper :timelog
44 include Redmine::Export::PDF
44 include Redmine::Export::PDF
45
45
46 def index
46 def index
47 retrieve_query
47 retrieve_query
48 sort_init 'id', 'desc'
48 sort_init 'id', 'desc'
49 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
49 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
50
50
51 if @query.valid?
51 if @query.valid?
52 limit = per_page_option
52 limit = per_page_option
53 respond_to do |format|
53 respond_to do |format|
54 format.html { }
54 format.html { }
55 format.atom { }
55 format.atom { }
56 format.csv { limit = Setting.issues_export_limit.to_i }
56 format.csv { limit = Setting.issues_export_limit.to_i }
57 format.pdf { limit = Setting.issues_export_limit.to_i }
57 format.pdf { limit = Setting.issues_export_limit.to_i }
58 end
58 end
59 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
59 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
60 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
60 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
61 @issues = Issue.find :all, :order => sort_clause,
61 @issues = Issue.find :all, :order => sort_clause,
62 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
62 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
63 :conditions => @query.statement,
63 :conditions => @query.statement,
64 :limit => limit,
64 :limit => limit,
65 :offset => @issue_pages.current.offset
65 :offset => @issue_pages.current.offset
66 respond_to do |format|
66 respond_to do |format|
67 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
67 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
68 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
68 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
69 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
69 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
70 format.pdf { send_data(issues_to_pdf(@issues, @project), :type => 'application/pdf', :filename => 'export.pdf') }
70 format.pdf { send_data(issues_to_pdf(@issues, @project), :type => 'application/pdf', :filename => 'export.pdf') }
71 end
71 end
72 else
72 else
73 # Send html if the query is not valid
73 # Send html if the query is not valid
74 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
74 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
75 end
75 end
76 rescue ActiveRecord::RecordNotFound
76 rescue ActiveRecord::RecordNotFound
77 render_404
77 render_404
78 end
78 end
79
79
80 def changes
80 def changes
81 retrieve_query
81 retrieve_query
82 sort_init 'id', 'desc'
82 sort_init 'id', 'desc'
83 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
83 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
84
84
85 if @query.valid?
85 if @query.valid?
86 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
86 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
87 :conditions => @query.statement,
87 :conditions => @query.statement,
88 :limit => 25,
88 :limit => 25,
89 :order => "#{Journal.table_name}.created_on DESC"
89 :order => "#{Journal.table_name}.created_on DESC"
90 end
90 end
91 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
91 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
92 render :layout => false, :content_type => 'application/atom+xml'
92 render :layout => false, :content_type => 'application/atom+xml'
93 rescue ActiveRecord::RecordNotFound
93 rescue ActiveRecord::RecordNotFound
94 render_404
94 render_404
95 end
95 end
96
96
97 def show
97 def show
98 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
98 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
99 @journals.each_with_index {|j,i| j.indice = i+1}
99 @journals.each_with_index {|j,i| j.indice = i+1}
100 @journals.reverse! if User.current.wants_comments_in_reverse_order?
100 @journals.reverse! if User.current.wants_comments_in_reverse_order?
101 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
101 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
102 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
102 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
103 @priorities = Enumeration::get_values('IPRI')
103 @priorities = Enumeration::get_values('IPRI')
104 @time_entry = TimeEntry.new
104 @time_entry = TimeEntry.new
105 respond_to do |format|
105 respond_to do |format|
106 format.html { render :template => 'issues/show.rhtml' }
106 format.html { render :template => 'issues/show.rhtml' }
107 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
107 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
108 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
108 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
109 end
109 end
110 end
110 end
111
111
112 # Add a new issue
112 # Add a new issue
113 # The new issue will be created from an existing one if copy_from parameter is given
113 # The new issue will be created from an existing one if copy_from parameter is given
114 def new
114 def new
115 @issue = Issue.new
115 @issue = Issue.new
116 @issue.copy_from(params[:copy_from]) if params[:copy_from]
116 @issue.copy_from(params[:copy_from]) if params[:copy_from]
117 @issue.project = @project
117 @issue.project = @project
118 # Tracker must be set before custom field values
118 # Tracker must be set before custom field values
119 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
119 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
120 if @issue.tracker.nil?
120 if @issue.tracker.nil?
121 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
121 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
122 render :nothing => true, :layout => true
122 render :nothing => true, :layout => true
123 return
123 return
124 end
124 end
125 if params[:issue].is_a?(Hash)
125 if params[:issue].is_a?(Hash)
126 @issue.attributes = params[:issue]
126 @issue.attributes = params[:issue]
127 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
127 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
128 end
128 end
129 @issue.author = User.current
129 @issue.author = User.current
130
130
131 default_status = IssueStatus.default
131 default_status = IssueStatus.default
132 unless default_status
132 unless default_status
133 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
133 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
134 render :nothing => true, :layout => true
134 render :nothing => true, :layout => true
135 return
135 return
136 end
136 end
137 @issue.status = default_status
137 @issue.status = default_status
138 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
138 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
139
139
140 if request.get? || request.xhr?
140 if request.get? || request.xhr?
141 @issue.start_date ||= Date.today
141 @issue.start_date ||= Date.today
142 else
142 else
143 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
143 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
144 # Check that the user is allowed to apply the requested status
144 # Check that the user is allowed to apply the requested status
145 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
145 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
146 if @issue.save
146 if @issue.save
147 attach_files(@issue, params[:attachments])
147 attach_files(@issue, params[:attachments])
148 flash[:notice] = l(:notice_successful_create)
148 flash[:notice] = l(:notice_successful_create)
149 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
149 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
150 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
150 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
151 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
151 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
152 { :action => 'show', :id => @issue })
152 { :action => 'show', :id => @issue })
153 return
153 return
154 end
154 end
155 end
155 end
156 @priorities = Enumeration::get_values('IPRI')
156 @priorities = Enumeration::get_values('IPRI')
157 render :layout => !request.xhr?
157 render :layout => !request.xhr?
158 end
158 end
159
159
160 # Attributes that can be updated on workflow transition (without :edit permission)
160 # Attributes that can be updated on workflow transition (without :edit permission)
161 # TODO: make it configurable (at least per role)
161 # TODO: make it configurable (at least per role)
162 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
162 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
163
163
164 def edit
164 def edit
165 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
165 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
166 @priorities = Enumeration::get_values('IPRI')
166 @priorities = Enumeration::get_values('IPRI')
167 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
167 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
168 @time_entry = TimeEntry.new
168 @time_entry = TimeEntry.new
169
169
170 @notes = params[:notes]
170 @notes = params[:notes]
171 journal = @issue.init_journal(User.current, @notes)
171 journal = @issue.init_journal(User.current, @notes)
172 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
172 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
173 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
173 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
174 attrs = params[:issue].dup
174 attrs = params[:issue].dup
175 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
175 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
176 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
176 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
177 @issue.attributes = attrs
177 @issue.attributes = attrs
178 end
178 end
179
179
180 if request.post?
180 if request.post?
181 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
181 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
182 @time_entry.attributes = params[:time_entry]
182 @time_entry.attributes = params[:time_entry]
183 attachments = attach_files(@issue, params[:attachments])
183 attachments = attach_files(@issue, params[:attachments])
184 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
184 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
185
185
186 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
186 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
187
187
188 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
188 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
189 # Log spend time
189 # Log spend time
190 if current_role.allowed_to?(:log_time)
190 if current_role.allowed_to?(:log_time)
191 @time_entry.save
191 @time_entry.save
192 end
192 end
193 if !journal.new_record?
193 if !journal.new_record?
194 # Only send notification if something was actually changed
194 # Only send notification if something was actually changed
195 flash[:notice] = l(:notice_successful_update)
195 flash[:notice] = l(:notice_successful_update)
196 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
196 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
197 end
197 end
198 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
198 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
199 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
199 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
200 end
200 end
201 end
201 end
202 rescue ActiveRecord::StaleObjectError
202 rescue ActiveRecord::StaleObjectError
203 # Optimistic locking exception
203 # Optimistic locking exception
204 flash.now[:error] = l(:notice_locking_conflict)
204 flash.now[:error] = l(:notice_locking_conflict)
205 end
205 end
206
206
207 def reply
207 def reply
208 journal = Journal.find(params[:journal_id]) if params[:journal_id]
208 journal = Journal.find(params[:journal_id]) if params[:journal_id]
209 if journal
209 if journal
210 user = journal.user
210 user = journal.user
211 text = journal.notes
211 text = journal.notes
212 else
212 else
213 user = @issue.author
213 user = @issue.author
214 text = @issue.description
214 text = @issue.description
215 end
215 end
216 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
216 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
217 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
217 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
218 render(:update) { |page|
218 render(:update) { |page|
219 page.<< "$('notes').value = \"#{content}\";"
219 page.<< "$('notes').value = \"#{content}\";"
220 page.show 'update'
220 page.show 'update'
221 page << "Form.Element.focus('notes');"
221 page << "Form.Element.focus('notes');"
222 page << "Element.scrollTo('update');"
222 page << "Element.scrollTo('update');"
223 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
223 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
224 }
224 }
225 end
225 end
226
226
227 # Bulk edit a set of issues
227 # Bulk edit a set of issues
228 def bulk_edit
228 def bulk_edit
229 if request.post?
229 if request.post?
230 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
230 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
231 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
231 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
232 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
232 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
233 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
233 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
234 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
234 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
235
235
236 unsaved_issue_ids = []
236 unsaved_issue_ids = []
237 @issues.each do |issue|
237 @issues.each do |issue|
238 journal = issue.init_journal(User.current, params[:notes])
238 journal = issue.init_journal(User.current, params[:notes])
239 issue.priority = priority if priority
239 issue.priority = priority if priority
240 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
240 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
241 issue.category = category if category || params[:category_id] == 'none'
241 issue.category = category if category || params[:category_id] == 'none'
242 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
242 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
243 issue.start_date = params[:start_date] unless params[:start_date].blank?
243 issue.start_date = params[:start_date] unless params[:start_date].blank?
244 issue.due_date = params[:due_date] unless params[:due_date].blank?
244 issue.due_date = params[:due_date] unless params[:due_date].blank?
245 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
245 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
246 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
246 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
247 # Don't save any change to the issue if the user is not authorized to apply the requested status
247 # Don't save any change to the issue if the user is not authorized to apply the requested status
248 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
248 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
249 # Send notification for each issue (if changed)
249 # Send notification for each issue (if changed)
250 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
250 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
251 else
251 else
252 # Keep unsaved issue ids to display them in flash error
252 # Keep unsaved issue ids to display them in flash error
253 unsaved_issue_ids << issue.id
253 unsaved_issue_ids << issue.id
254 end
254 end
255 end
255 end
256 if unsaved_issue_ids.empty?
256 if unsaved_issue_ids.empty?
257 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
257 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
258 else
258 else
259 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
259 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
260 end
260 end
261 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
261 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
262 return
262 return
263 end
263 end
264 # Find potential statuses the user could be allowed to switch issues to
264 # Find potential statuses the user could be allowed to switch issues to
265 @available_statuses = Workflow.find(:all, :include => :new_status,
265 @available_statuses = Workflow.find(:all, :include => :new_status,
266 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort
266 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort
267 end
267 end
268
268
269 def move
269 def move
270 @allowed_projects = []
270 @allowed_projects = []
271 # find projects to which the user is allowed to move the issue
271 # find projects to which the user is allowed to move the issue
272 if User.current.admin?
272 if User.current.admin?
273 # admin is allowed to move issues to any active (visible) project
273 # admin is allowed to move issues to any active (visible) project
274 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
274 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
275 else
275 else
276 User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
276 User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
277 end
277 end
278 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
278 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
279 @target_project ||= @project
279 @target_project ||= @project
280 @trackers = @target_project.trackers
280 @trackers = @target_project.trackers
281 if request.post?
281 if request.post?
282 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
282 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
283 unsaved_issue_ids = []
283 unsaved_issue_ids = []
284 @issues.each do |issue|
284 @issues.each do |issue|
285 issue.init_journal(User.current)
285 issue.init_journal(User.current)
286 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker, params[:copy_options])
286 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker, params[:copy_options])
287 end
287 end
288 if unsaved_issue_ids.empty?
288 if unsaved_issue_ids.empty?
289 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
289 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
290 else
290 else
291 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
291 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
292 end
292 end
293 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
293 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
294 return
294 return
295 end
295 end
296 render :layout => false if request.xhr?
296 render :layout => false if request.xhr?
297 end
297 end
298
298
299 def destroy
299 def destroy
300 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
300 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
301 if @hours > 0
301 if @hours > 0
302 case params[:todo]
302 case params[:todo]
303 when 'destroy'
303 when 'destroy'
304 # nothing to do
304 # nothing to do
305 when 'nullify'
305 when 'nullify'
306 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
306 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
307 when 'reassign'
307 when 'reassign'
308 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
308 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
309 if reassign_to.nil?
309 if reassign_to.nil?
310 flash.now[:error] = l(:error_issue_not_found_in_project)
310 flash.now[:error] = l(:error_issue_not_found_in_project)
311 return
311 return
312 else
312 else
313 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
313 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
314 end
314 end
315 else
315 else
316 # display the destroy form
316 # display the destroy form
317 return
317 return
318 end
318 end
319 end
319 end
320 @issues.each(&:destroy)
320 @issues.each(&:destroy)
321 redirect_to :action => 'index', :project_id => @project
321 redirect_to :action => 'index', :project_id => @project
322 end
322 end
323
323
324 def gantt
324 def gantt
325 @gantt = Redmine::Helpers::Gantt.new(params)
325 @gantt = Redmine::Helpers::Gantt.new(params)
326 retrieve_query
326 retrieve_query
327 if @query.valid?
327 if @query.valid?
328 events = []
328 events = []
329 # Issues that have start and due dates
329 # Issues that have start and due dates
330 events += Issue.find(:all,
330 events += Issue.find(:all,
331 :order => "start_date, due_date",
331 :order => "start_date, due_date",
332 :include => [:tracker, :status, :assigned_to, :priority, :project],
332 :include => [:tracker, :status, :assigned_to, :priority, :project],
333 :conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
333 :conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
334 )
334 )
335 # Issues that don't have a due date but that are assigned to a version with a date
335 # Issues that don't have a due date but that are assigned to a version with a date
336 events += Issue.find(:all,
336 events += Issue.find(:all,
337 :order => "start_date, effective_date",
337 :order => "start_date, effective_date",
338 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
338 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
339 :conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
339 :conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
340 )
340 )
341 # Versions
341 # Versions
342 events += Version.find(:all, :include => :project,
342 events += Version.find(:all, :include => :project,
343 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
343 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
344
344
345 @gantt.events = events
345 @gantt.events = events
346 end
346 end
347
347
348 respond_to do |format|
348 respond_to do |format|
349 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
349 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
350 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") } if @gantt.respond_to?('to_image')
350 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") } if @gantt.respond_to?('to_image')
351 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{@project.nil? ? '' : "#{@project.identifier}-" }gantt.pdf") }
351 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{@project.nil? ? '' : "#{@project.identifier}-" }gantt.pdf") }
352 end
352 end
353 end
353 end
354
354
355 def calendar
355 def calendar
356 if params[:year] and params[:year].to_i > 1900
356 if params[:year] and params[:year].to_i > 1900
357 @year = params[:year].to_i
357 @year = params[:year].to_i
358 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
358 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
359 @month = params[:month].to_i
359 @month = params[:month].to_i
360 end
360 end
361 end
361 end
362 @year ||= Date.today.year
362 @year ||= Date.today.year
363 @month ||= Date.today.month
363 @month ||= Date.today.month
364
364
365 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
365 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
366 retrieve_query
366 retrieve_query
367 if @query.valid?
367 if @query.valid?
368 events = []
368 events = []
369 events += Issue.find(:all,
369 events += Issue.find(:all,
370 :include => [:tracker, :status, :assigned_to, :priority, :project],
370 :include => [:tracker, :status, :assigned_to, :priority, :project],
371 :conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
371 :conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
372 )
372 )
373 events += Version.find(:all, :include => :project,
373 events += Version.find(:all, :include => :project,
374 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
374 :conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
375
375
376 @calendar.events = events
376 @calendar.events = events
377 end
377 end
378
378
379 render :layout => false if request.xhr?
379 render :layout => false if request.xhr?
380 end
380 end
381
381
382 def context_menu
382 def context_menu
383 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
383 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
384 if (@issues.size == 1)
384 if (@issues.size == 1)
385 @issue = @issues.first
385 @issue = @issues.first
386 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
386 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
387 end
387 end
388 projects = @issues.collect(&:project).compact.uniq
388 projects = @issues.collect(&:project).compact.uniq
389 @project = projects.first if projects.size == 1
389 @project = projects.first if projects.size == 1
390
390
391 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
391 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
392 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
392 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
393 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
393 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
394 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
394 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
395 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
395 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
396 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
396 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
397 }
397 }
398 if @project
398 if @project
399 @assignables = @project.assignable_users
399 @assignables = @project.assignable_users
400 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
400 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
401 end
401 end
402
402
403 @priorities = Enumeration.get_values('IPRI').reverse
403 @priorities = Enumeration.get_values('IPRI').reverse
404 @statuses = IssueStatus.find(:all, :order => 'position')
404 @statuses = IssueStatus.find(:all, :order => 'position')
405 @back = request.env['HTTP_REFERER']
405 @back = request.env['HTTP_REFERER']
406
406
407 render :layout => false
407 render :layout => false
408 end
408 end
409
409
410 def update_form
410 def update_form
411 @issue = Issue.new(params[:issue])
411 @issue = Issue.new(params[:issue])
412 render :action => :new, :layout => false
412 render :action => :new, :layout => false
413 end
413 end
414
414
415 def preview
415 def preview
416 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
416 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
417 @attachements = @issue.attachments if @issue
417 @attachements = @issue.attachments if @issue
418 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
418 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
419 render :partial => 'common/preview'
419 render :partial => 'common/preview'
420 end
420 end
421
421
422 private
422 private
423 def find_issue
423 def find_issue
424 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
424 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
425 @project = @issue.project
425 @project = @issue.project
426 rescue ActiveRecord::RecordNotFound
426 rescue ActiveRecord::RecordNotFound
427 render_404
427 render_404
428 end
428 end
429
429
430 # Filter for bulk operations
430 # Filter for bulk operations
431 def find_issues
431 def find_issues
432 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
432 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
433 raise ActiveRecord::RecordNotFound if @issues.empty?
433 raise ActiveRecord::RecordNotFound if @issues.empty?
434 projects = @issues.collect(&:project).compact.uniq
434 projects = @issues.collect(&:project).compact.uniq
435 if projects.size == 1
435 if projects.size == 1
436 @project = projects.first
436 @project = projects.first
437 else
437 else
438 # TODO: let users bulk edit/move/destroy issues from different projects
438 # TODO: let users bulk edit/move/destroy issues from different projects
439 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
439 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
440 end
440 end
441 rescue ActiveRecord::RecordNotFound
441 rescue ActiveRecord::RecordNotFound
442 render_404
442 render_404
443 end
443 end
444
444
445 def find_project
445 def find_project
446 @project = Project.find(params[:project_id])
446 @project = Project.find(params[:project_id])
447 rescue ActiveRecord::RecordNotFound
447 rescue ActiveRecord::RecordNotFound
448 render_404
448 render_404
449 end
449 end
450
450
451 def find_optional_project
451 def find_optional_project
452 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
452 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
453 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
453 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
454 allowed ? true : deny_access
454 allowed ? true : deny_access
455 rescue ActiveRecord::RecordNotFound
455 rescue ActiveRecord::RecordNotFound
456 render_404
456 render_404
457 end
457 end
458
458
459 # Retrieve query from session or build a new query
459 # Retrieve query from session or build a new query
460 def retrieve_query
460 def retrieve_query
461 if !params[:query_id].blank?
461 if !params[:query_id].blank?
462 cond = "project_id IS NULL"
462 cond = "project_id IS NULL"
463 cond << " OR project_id = #{@project.id}" if @project
463 cond << " OR project_id = #{@project.id}" if @project
464 @query = Query.find(params[:query_id], :conditions => cond)
464 @query = Query.find(params[:query_id], :conditions => cond)
465 @query.project = @project
465 @query.project = @project
466 session[:query] = {:id => @query.id, :project_id => @query.project_id}
466 session[:query] = {:id => @query.id, :project_id => @query.project_id}
467 else
467 else
468 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
468 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
469 # Give it a name, required to be valid
469 # Give it a name, required to be valid
470 @query = Query.new(:name => "_")
470 @query = Query.new(:name => "_")
471 @query.project = @project
471 @query.project = @project
472 if params[:fields] and params[:fields].is_a? Array
472 if params[:fields] and params[:fields].is_a? Array
473 params[:fields].each do |field|
473 params[:fields].each do |field|
474 @query.add_filter(field, params[:operators][field], params[:values][field])
474 @query.add_filter(field, params[:operators][field], params[:values][field])
475 end
475 end
476 else
476 else
477 @query.available_filters.keys.each do |field|
477 @query.available_filters.keys.each do |field|
478 @query.add_short_filter(field, params[field]) if params[field]
478 @query.add_short_filter(field, params[field]) if params[field]
479 end
479 end
480 end
480 end
481 session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
481 session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
482 else
482 else
483 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
483 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
484 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
484 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
485 @query.project = @project
485 @query.project = @project
486 end
486 end
487 end
487 end
488 end
488 end
489 end
489 end
@@ -1,25 +1,25
1 <h2><%= l(:button_move) %></h2>
1 <h2><%= l(:button_move) %></h2>
2
2
3 <ul><%= @issues.collect {|i| content_tag('li', link_to(h("#{i.tracker} ##{i.id}"), { :action => 'show', :id => i }) + h(": #{i.subject}")) }.join("\n") %></ul>
3 <ul><%= @issues.collect {|i| content_tag('li', link_to(h("#{i.tracker} ##{i.id}"), { :action => 'show', :id => i }) + h(": #{i.subject}")) }.join("\n") %></ul>
4
4
5 <% form_tag({}, :id => 'move_form') do %>
5 <% form_tag({}, :id => 'move_form') do %>
6 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
6 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
7
7
8 <div class="box tabular">
8 <div class="box tabular">
9 <p><label for="new_project_id"><%=l(:field_project)%>:</label>
9 <p><label for="new_project_id"><%=l(:field_project)%>:</label>
10 <%= select_tag "new_project_id",
10 <%= select_tag "new_project_id",
11 options_from_collection_for_select(@allowed_projects, 'id', 'name', @target_project.id),
11 project_tree_options_for_select(@allowed_projects, :selected => @target_project),
12 :onchange => remote_function(:url => { :action => 'move' },
12 :onchange => remote_function(:url => { :action => 'move' },
13 :method => :get,
13 :method => :get,
14 :update => 'content',
14 :update => 'content',
15 :with => "Form.serialize('move_form')") %></p>
15 :with => "Form.serialize('move_form')") %></p>
16
16
17 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
17 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
18 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
18 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
19
19
20 <p><label for="copy_options_copy"><%= l(:button_copy)%></label>
20 <p><label for="copy_options_copy"><%= l(:button_copy)%></label>
21 <%= check_box_tag "copy_options[copy]", "1" %></p>
21 <%= check_box_tag "copy_options[copy]", "1" %></p>
22 </div>
22 </div>
23
23
24 <%= submit_tag l(:button_move) %>
24 <%= submit_tag l(:button_move) %>
25 <% end %>
25 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now