##// END OF EJS Templates
Fixed: invalid format parameter returns a DoubleRenderError on issues index (#4737)....
Jean-Philippe Lang -
r3252:cfe4d0e7db5c
parent child
Show More
@@ -1,572 +1,574
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 default_search_scope :issues
20 default_search_scope :issues
21
21
22 before_filter :find_issue, :only => [:show, :edit, :reply]
22 before_filter :find_issue, :only => [:show, :edit, :reply]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
26 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
26 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
27 accept_key_auth :index, :show, :changes
27 accept_key_auth :index, :show, :changes
28
28
29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30
30
31 helper :journals
31 helper :journals
32 helper :projects
32 helper :projects
33 include ProjectsHelper
33 include ProjectsHelper
34 helper :custom_fields
34 helper :custom_fields
35 include CustomFieldsHelper
35 include CustomFieldsHelper
36 helper :issue_relations
36 helper :issue_relations
37 include IssueRelationsHelper
37 include IssueRelationsHelper
38 helper :watchers
38 helper :watchers
39 include WatchersHelper
39 include WatchersHelper
40 helper :attachments
40 helper :attachments
41 include AttachmentsHelper
41 include AttachmentsHelper
42 helper :queries
42 helper :queries
43 include QueriesHelper
43 include QueriesHelper
44 helper :sort
44 helper :sort
45 include SortHelper
45 include SortHelper
46 include IssuesHelper
46 include IssuesHelper
47 helper :timelog
47 helper :timelog
48 include Redmine::Export::PDF
48 include Redmine::Export::PDF
49
49
50 verify :method => [:post, :delete],
50 verify :method => [:post, :delete],
51 :only => :destroy,
51 :only => :destroy,
52 :render => { :nothing => true, :status => :method_not_allowed }
52 :render => { :nothing => true, :status => :method_not_allowed }
53
53
54 def index
54 def index
55 retrieve_query
55 retrieve_query
56 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
56 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
57 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
58
58
59 if @query.valid?
59 if @query.valid?
60 limit = per_page_option
60 limit = case params[:format]
61 respond_to do |format|
61 when 'csv', 'pdf'
62 format.html { }
62 Setting.issues_export_limit.to_i
63 format.xml { }
63 when 'atom'
64 format.atom { limit = Setting.feeds_limit.to_i }
64 Setting.feeds_limit.to_i
65 format.csv { limit = Setting.issues_export_limit.to_i }
65 else
66 format.pdf { limit = Setting.issues_export_limit.to_i }
66 per_page_option
67 end
67 end
68
68
69 @issue_count = @query.issue_count
69 @issue_count = @query.issue_count
70 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
70 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
71 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
71 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
72 :order => sort_clause,
72 :order => sort_clause,
73 :offset => @issue_pages.current.offset,
73 :offset => @issue_pages.current.offset,
74 :limit => limit)
74 :limit => limit)
75 @issue_count_by_group = @query.issue_count_by_group
75 @issue_count_by_group = @query.issue_count_by_group
76
76
77 respond_to do |format|
77 respond_to do |format|
78 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
78 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
79 format.xml { render :layout => false }
79 format.xml { render :layout => false }
80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
81 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
81 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
82 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
82 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
83 end
83 end
84 else
84 else
85 # Send html if the query is not valid
85 # Send html if the query is not valid
86 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
86 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
87 end
87 end
88 rescue ActiveRecord::RecordNotFound
88 rescue ActiveRecord::RecordNotFound
89 render_404
89 render_404
90 end
90 end
91
91
92 def changes
92 def changes
93 retrieve_query
93 retrieve_query
94 sort_init 'id', 'desc'
94 sort_init 'id', 'desc'
95 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
95 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
96
96
97 if @query.valid?
97 if @query.valid?
98 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
98 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
99 :limit => 25)
99 :limit => 25)
100 end
100 end
101 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
101 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
102 render :layout => false, :content_type => 'application/atom+xml'
102 render :layout => false, :content_type => 'application/atom+xml'
103 rescue ActiveRecord::RecordNotFound
103 rescue ActiveRecord::RecordNotFound
104 render_404
104 render_404
105 end
105 end
106
106
107 def show
107 def show
108 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
108 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
109 @journals.each_with_index {|j,i| j.indice = i+1}
109 @journals.each_with_index {|j,i| j.indice = i+1}
110 @journals.reverse! if User.current.wants_comments_in_reverse_order?
110 @journals.reverse! if User.current.wants_comments_in_reverse_order?
111 @changesets = @issue.changesets.visible.all
111 @changesets = @issue.changesets.visible.all
112 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
112 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
113 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
113 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
114 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
114 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
115 @priorities = IssuePriority.all
115 @priorities = IssuePriority.all
116 @time_entry = TimeEntry.new
116 @time_entry = TimeEntry.new
117 respond_to do |format|
117 respond_to do |format|
118 format.html { render :template => 'issues/show.rhtml' }
118 format.html { render :template => 'issues/show.rhtml' }
119 format.xml { render :layout => false }
119 format.xml { render :layout => false }
120 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
120 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
122 end
122 end
123 end
123 end
124
124
125 # Add a new issue
125 # Add a new issue
126 # The new issue will be created from an existing one if copy_from parameter is given
126 # The new issue will be created from an existing one if copy_from parameter is given
127 def new
127 def new
128 @issue = Issue.new
128 @issue = Issue.new
129 @issue.copy_from(params[:copy_from]) if params[:copy_from]
129 @issue.copy_from(params[:copy_from]) if params[:copy_from]
130 @issue.project = @project
130 @issue.project = @project
131 # Tracker must be set before custom field values
131 # Tracker must be set before custom field values
132 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
132 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
133 if @issue.tracker.nil?
133 if @issue.tracker.nil?
134 render_error l(:error_no_tracker_in_project)
134 render_error l(:error_no_tracker_in_project)
135 return
135 return
136 end
136 end
137 if params[:issue].is_a?(Hash)
137 if params[:issue].is_a?(Hash)
138 @issue.safe_attributes = params[:issue]
138 @issue.safe_attributes = params[:issue]
139 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
139 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
140 end
140 end
141 @issue.author = User.current
141 @issue.author = User.current
142
142
143 default_status = IssueStatus.default
143 default_status = IssueStatus.default
144 unless default_status
144 unless default_status
145 render_error l(:error_no_default_issue_status)
145 render_error l(:error_no_default_issue_status)
146 return
146 return
147 end
147 end
148 @issue.status = default_status
148 @issue.status = default_status
149 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
149 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
150
150
151 if request.get? || request.xhr?
151 if request.get? || request.xhr?
152 @issue.start_date ||= Date.today
152 @issue.start_date ||= Date.today
153 else
153 else
154 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
154 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
155 # Check that the user is allowed to apply the requested status
155 # Check that the user is allowed to apply the requested status
156 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
156 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
157 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
157 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
158 if @issue.save
158 if @issue.save
159 attach_files(@issue, params[:attachments])
159 attach_files(@issue, params[:attachments])
160 flash[:notice] = l(:notice_successful_create)
161 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
160 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
162 respond_to do |format|
161 respond_to do |format|
163 format.html {
162 format.html {
163 # Displays a link to the newly created issue in the flash message
164 link = @template.link_to("##{@issue.id}", {:controller => 'issues', :action => 'show', :id => @issue})
165 flash[:notice] = l(:notice_issue_created, :value => link)
164 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
166 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
165 { :action => 'show', :id => @issue })
167 { :action => 'show', :id => @issue })
166 }
168 }
167 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
169 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
168 end
170 end
169 return
171 return
170 else
172 else
171 respond_to do |format|
173 respond_to do |format|
172 format.html { }
174 format.html { }
173 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
175 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
174 end
176 end
175 end
177 end
176 end
178 end
177 @priorities = IssuePriority.all
179 @priorities = IssuePriority.all
178 render :layout => !request.xhr?
180 render :layout => !request.xhr?
179 end
181 end
180
182
181 # Attributes that can be updated on workflow transition (without :edit permission)
183 # Attributes that can be updated on workflow transition (without :edit permission)
182 # TODO: make it configurable (at least per role)
184 # TODO: make it configurable (at least per role)
183 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
185 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
184
186
185 def edit
187 def edit
186 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
188 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
187 @priorities = IssuePriority.all
189 @priorities = IssuePriority.all
188 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
190 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
189 @time_entry = TimeEntry.new
191 @time_entry = TimeEntry.new
190
192
191 @notes = params[:notes]
193 @notes = params[:notes]
192 journal = @issue.init_journal(User.current, @notes)
194 journal = @issue.init_journal(User.current, @notes)
193 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
195 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
194 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
196 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
195 attrs = params[:issue].dup
197 attrs = params[:issue].dup
196 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
198 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
197 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
199 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
198 @issue.safe_attributes = attrs
200 @issue.safe_attributes = attrs
199 end
201 end
200
202
201 if request.get?
203 if request.get?
202 # nop
204 # nop
203 else
205 else
204 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
206 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
205 @time_entry.attributes = params[:time_entry]
207 @time_entry.attributes = params[:time_entry]
206 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid?
208 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid?
207 attachments = attach_files(@issue, params[:attachments])
209 attachments = attach_files(@issue, params[:attachments])
208 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
210 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
209 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
211 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
210 if @issue.save
212 if @issue.save
211 # Log spend time
213 # Log spend time
212 if User.current.allowed_to?(:log_time, @project)
214 if User.current.allowed_to?(:log_time, @project)
213 @time_entry.save
215 @time_entry.save
214 end
216 end
215 if !journal.new_record?
217 if !journal.new_record?
216 # Only send notification if something was actually changed
218 # Only send notification if something was actually changed
217 flash[:notice] = l(:notice_successful_update)
219 flash[:notice] = l(:notice_successful_update)
218 end
220 end
219 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
221 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
220 respond_to do |format|
222 respond_to do |format|
221 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
223 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
222 format.xml { head :ok }
224 format.xml { head :ok }
223 end
225 end
224 return
226 return
225 end
227 end
226 end
228 end
227 # failure
229 # failure
228 respond_to do |format|
230 respond_to do |format|
229 format.html { }
231 format.html { }
230 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
232 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
231 end
233 end
232 end
234 end
233 rescue ActiveRecord::StaleObjectError
235 rescue ActiveRecord::StaleObjectError
234 # Optimistic locking exception
236 # Optimistic locking exception
235 flash.now[:error] = l(:notice_locking_conflict)
237 flash.now[:error] = l(:notice_locking_conflict)
236 # Remove the previously added attachments if issue was not updated
238 # Remove the previously added attachments if issue was not updated
237 attachments.each(&:destroy)
239 attachments.each(&:destroy)
238 end
240 end
239
241
240 def reply
242 def reply
241 journal = Journal.find(params[:journal_id]) if params[:journal_id]
243 journal = Journal.find(params[:journal_id]) if params[:journal_id]
242 if journal
244 if journal
243 user = journal.user
245 user = journal.user
244 text = journal.notes
246 text = journal.notes
245 else
247 else
246 user = @issue.author
248 user = @issue.author
247 text = @issue.description
249 text = @issue.description
248 end
250 end
249 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
251 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
250 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
252 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
251 render(:update) { |page|
253 render(:update) { |page|
252 page.<< "$('notes').value = \"#{content}\";"
254 page.<< "$('notes').value = \"#{content}\";"
253 page.show 'update'
255 page.show 'update'
254 page << "Form.Element.focus('notes');"
256 page << "Form.Element.focus('notes');"
255 page << "Element.scrollTo('update');"
257 page << "Element.scrollTo('update');"
256 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
258 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
257 }
259 }
258 end
260 end
259
261
260 # Bulk edit a set of issues
262 # Bulk edit a set of issues
261 def bulk_edit
263 def bulk_edit
262 if request.post?
264 if request.post?
263 tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
265 tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
264 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
266 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
265 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
267 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
266 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
268 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
267 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
269 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
268 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id])
270 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id])
269 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
271 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
270
272
271 unsaved_issue_ids = []
273 unsaved_issue_ids = []
272 @issues.each do |issue|
274 @issues.each do |issue|
273 journal = issue.init_journal(User.current, params[:notes])
275 journal = issue.init_journal(User.current, params[:notes])
274 issue.tracker = tracker if tracker
276 issue.tracker = tracker if tracker
275 issue.priority = priority if priority
277 issue.priority = priority if priority
276 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
278 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
277 issue.category = category if category || params[:category_id] == 'none'
279 issue.category = category if category || params[:category_id] == 'none'
278 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
280 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
279 issue.start_date = params[:start_date] unless params[:start_date].blank?
281 issue.start_date = params[:start_date] unless params[:start_date].blank?
280 issue.due_date = params[:due_date] unless params[:due_date].blank?
282 issue.due_date = params[:due_date] unless params[:due_date].blank?
281 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
283 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
282 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
284 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
283 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
285 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
284 # Don't save any change to the issue if the user is not authorized to apply the requested status
286 # Don't save any change to the issue if the user is not authorized to apply the requested status
285 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
287 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
286 # Keep unsaved issue ids to display them in flash error
288 # Keep unsaved issue ids to display them in flash error
287 unsaved_issue_ids << issue.id
289 unsaved_issue_ids << issue.id
288 end
290 end
289 end
291 end
290 if unsaved_issue_ids.empty?
292 if unsaved_issue_ids.empty?
291 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
293 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
292 else
294 else
293 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
295 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
294 :total => @issues.size,
296 :total => @issues.size,
295 :ids => '#' + unsaved_issue_ids.join(', #'))
297 :ids => '#' + unsaved_issue_ids.join(', #'))
296 end
298 end
297 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
299 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
298 return
300 return
299 end
301 end
300 @available_statuses = Workflow.available_statuses(@project)
302 @available_statuses = Workflow.available_statuses(@project)
301 @custom_fields = @project.all_issue_custom_fields
303 @custom_fields = @project.all_issue_custom_fields
302 end
304 end
303
305
304 def move
306 def move
305 @copy = params[:copy_options] && params[:copy_options][:copy]
307 @copy = params[:copy_options] && params[:copy_options][:copy]
306 @allowed_projects = []
308 @allowed_projects = []
307 # find projects to which the user is allowed to move the issue
309 # find projects to which the user is allowed to move the issue
308 if User.current.admin?
310 if User.current.admin?
309 # admin is allowed to move issues to any active (visible) project
311 # admin is allowed to move issues to any active (visible) project
310 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
312 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
311 else
313 else
312 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
314 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
313 end
315 end
314 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
316 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
315 @target_project ||= @project
317 @target_project ||= @project
316 @trackers = @target_project.trackers
318 @trackers = @target_project.trackers
317 @available_statuses = Workflow.available_statuses(@project)
319 @available_statuses = Workflow.available_statuses(@project)
318 if request.post?
320 if request.post?
319 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
321 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
320 unsaved_issue_ids = []
322 unsaved_issue_ids = []
321 moved_issues = []
323 moved_issues = []
322 @issues.each do |issue|
324 @issues.each do |issue|
323 changed_attributes = {}
325 changed_attributes = {}
324 [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
326 [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
325 unless params[valid_attribute].blank?
327 unless params[valid_attribute].blank?
326 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
328 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
327 end
329 end
328 end
330 end
329 issue.init_journal(User.current)
331 issue.init_journal(User.current)
330 if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
332 if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
331 moved_issues << r
333 moved_issues << r
332 else
334 else
333 unsaved_issue_ids << issue.id
335 unsaved_issue_ids << issue.id
334 end
336 end
335 end
337 end
336 if unsaved_issue_ids.empty?
338 if unsaved_issue_ids.empty?
337 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
339 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
338 else
340 else
339 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
341 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
340 :total => @issues.size,
342 :total => @issues.size,
341 :ids => '#' + unsaved_issue_ids.join(', #'))
343 :ids => '#' + unsaved_issue_ids.join(', #'))
342 end
344 end
343 if params[:follow]
345 if params[:follow]
344 if @issues.size == 1 && moved_issues.size == 1
346 if @issues.size == 1 && moved_issues.size == 1
345 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
347 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
346 else
348 else
347 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
349 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
348 end
350 end
349 else
351 else
350 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
352 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
351 end
353 end
352 return
354 return
353 end
355 end
354 render :layout => false if request.xhr?
356 render :layout => false if request.xhr?
355 end
357 end
356
358
357 def destroy
359 def destroy
358 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
360 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
359 if @hours > 0
361 if @hours > 0
360 case params[:todo]
362 case params[:todo]
361 when 'destroy'
363 when 'destroy'
362 # nothing to do
364 # nothing to do
363 when 'nullify'
365 when 'nullify'
364 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
366 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
365 when 'reassign'
367 when 'reassign'
366 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
368 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
367 if reassign_to.nil?
369 if reassign_to.nil?
368 flash.now[:error] = l(:error_issue_not_found_in_project)
370 flash.now[:error] = l(:error_issue_not_found_in_project)
369 return
371 return
370 else
372 else
371 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
373 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
372 end
374 end
373 else
375 else
374 unless params[:format] == 'xml'
376 unless params[:format] == 'xml'
375 # display the destroy form if it's a user request
377 # display the destroy form if it's a user request
376 return
378 return
377 end
379 end
378 end
380 end
379 end
381 end
380 @issues.each(&:destroy)
382 @issues.each(&:destroy)
381 respond_to do |format|
383 respond_to do |format|
382 format.html { redirect_to :action => 'index', :project_id => @project }
384 format.html { redirect_to :action => 'index', :project_id => @project }
383 format.xml { head :ok }
385 format.xml { head :ok }
384 end
386 end
385 end
387 end
386
388
387 def gantt
389 def gantt
388 @gantt = Redmine::Helpers::Gantt.new(params)
390 @gantt = Redmine::Helpers::Gantt.new(params)
389 retrieve_query
391 retrieve_query
390 if @query.valid?
392 if @query.valid?
391 events = []
393 events = []
392 # Issues that have start and due dates
394 # Issues that have start and due dates
393 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
395 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
394 :order => "start_date, due_date",
396 :order => "start_date, due_date",
395 :conditions => ["(((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]
397 :conditions => ["(((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]
396 )
398 )
397 # Issues that don't have a due date but that are assigned to a version with a date
399 # Issues that don't have a due date but that are assigned to a version with a date
398 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
400 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
399 :order => "start_date, effective_date",
401 :order => "start_date, effective_date",
400 :conditions => ["(((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]
402 :conditions => ["(((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]
401 )
403 )
402 # Versions
404 # Versions
403 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
405 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
404
406
405 @gantt.events = events
407 @gantt.events = events
406 end
408 end
407
409
408 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
410 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
409
411
410 respond_to do |format|
412 respond_to do |format|
411 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
413 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
412 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
414 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
413 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
415 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
414 end
416 end
415 end
417 end
416
418
417 def calendar
419 def calendar
418 if params[:year] and params[:year].to_i > 1900
420 if params[:year] and params[:year].to_i > 1900
419 @year = params[:year].to_i
421 @year = params[:year].to_i
420 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
422 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
421 @month = params[:month].to_i
423 @month = params[:month].to_i
422 end
424 end
423 end
425 end
424 @year ||= Date.today.year
426 @year ||= Date.today.year
425 @month ||= Date.today.month
427 @month ||= Date.today.month
426
428
427 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
429 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
428 retrieve_query
430 retrieve_query
429 if @query.valid?
431 if @query.valid?
430 events = []
432 events = []
431 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
433 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
432 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
434 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
433 )
435 )
434 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
436 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
435
437
436 @calendar.events = events
438 @calendar.events = events
437 end
439 end
438
440
439 render :layout => false if request.xhr?
441 render :layout => false if request.xhr?
440 end
442 end
441
443
442 def context_menu
444 def context_menu
443 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
445 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
444 if (@issues.size == 1)
446 if (@issues.size == 1)
445 @issue = @issues.first
447 @issue = @issues.first
446 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
448 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
447 end
449 end
448 projects = @issues.collect(&:project).compact.uniq
450 projects = @issues.collect(&:project).compact.uniq
449 @project = projects.first if projects.size == 1
451 @project = projects.first if projects.size == 1
450
452
451 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
453 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
452 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
454 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
453 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
455 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
454 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
456 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
455 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
457 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
456 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
458 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
457 }
459 }
458 if @project
460 if @project
459 @assignables = @project.assignable_users
461 @assignables = @project.assignable_users
460 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
462 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
461 @trackers = @project.trackers
463 @trackers = @project.trackers
462 end
464 end
463
465
464 @priorities = IssuePriority.all.reverse
466 @priorities = IssuePriority.all.reverse
465 @statuses = IssueStatus.find(:all, :order => 'position')
467 @statuses = IssueStatus.find(:all, :order => 'position')
466 @back = params[:back_url] || request.env['HTTP_REFERER']
468 @back = params[:back_url] || request.env['HTTP_REFERER']
467
469
468 render :layout => false
470 render :layout => false
469 end
471 end
470
472
471 def update_form
473 def update_form
472 if params[:id].blank?
474 if params[:id].blank?
473 @issue = Issue.new
475 @issue = Issue.new
474 @issue.project = @project
476 @issue.project = @project
475 else
477 else
476 @issue = @project.issues.visible.find(params[:id])
478 @issue = @project.issues.visible.find(params[:id])
477 end
479 end
478 @issue.attributes = params[:issue]
480 @issue.attributes = params[:issue]
479 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
481 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
480 @priorities = IssuePriority.all
482 @priorities = IssuePriority.all
481
483
482 render :partial => 'attributes'
484 render :partial => 'attributes'
483 end
485 end
484
486
485 def preview
487 def preview
486 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
488 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
487 @attachements = @issue.attachments if @issue
489 @attachements = @issue.attachments if @issue
488 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
490 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
489 render :partial => 'common/preview'
491 render :partial => 'common/preview'
490 end
492 end
491
493
492 private
494 private
493 def find_issue
495 def find_issue
494 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
496 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
495 @project = @issue.project
497 @project = @issue.project
496 rescue ActiveRecord::RecordNotFound
498 rescue ActiveRecord::RecordNotFound
497 render_404
499 render_404
498 end
500 end
499
501
500 # Filter for bulk operations
502 # Filter for bulk operations
501 def find_issues
503 def find_issues
502 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
504 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
503 raise ActiveRecord::RecordNotFound if @issues.empty?
505 raise ActiveRecord::RecordNotFound if @issues.empty?
504 projects = @issues.collect(&:project).compact.uniq
506 projects = @issues.collect(&:project).compact.uniq
505 if projects.size == 1
507 if projects.size == 1
506 @project = projects.first
508 @project = projects.first
507 else
509 else
508 # TODO: let users bulk edit/move/destroy issues from different projects
510 # TODO: let users bulk edit/move/destroy issues from different projects
509 render_error 'Can not bulk edit/move/destroy issues from different projects'
511 render_error 'Can not bulk edit/move/destroy issues from different projects'
510 return false
512 return false
511 end
513 end
512 rescue ActiveRecord::RecordNotFound
514 rescue ActiveRecord::RecordNotFound
513 render_404
515 render_404
514 end
516 end
515
517
516 def find_project
518 def find_project
517 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
519 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
518 @project = Project.find(project_id)
520 @project = Project.find(project_id)
519 rescue ActiveRecord::RecordNotFound
521 rescue ActiveRecord::RecordNotFound
520 render_404
522 render_404
521 end
523 end
522
524
523 def find_optional_project
525 def find_optional_project
524 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
526 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
525 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
527 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
526 allowed ? true : deny_access
528 allowed ? true : deny_access
527 rescue ActiveRecord::RecordNotFound
529 rescue ActiveRecord::RecordNotFound
528 render_404
530 render_404
529 end
531 end
530
532
531 # Retrieve query from session or build a new query
533 # Retrieve query from session or build a new query
532 def retrieve_query
534 def retrieve_query
533 if !params[:query_id].blank?
535 if !params[:query_id].blank?
534 cond = "project_id IS NULL"
536 cond = "project_id IS NULL"
535 cond << " OR project_id = #{@project.id}" if @project
537 cond << " OR project_id = #{@project.id}" if @project
536 @query = Query.find(params[:query_id], :conditions => cond)
538 @query = Query.find(params[:query_id], :conditions => cond)
537 @query.project = @project
539 @query.project = @project
538 session[:query] = {:id => @query.id, :project_id => @query.project_id}
540 session[:query] = {:id => @query.id, :project_id => @query.project_id}
539 sort_clear
541 sort_clear
540 else
542 else
541 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
543 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
542 # Give it a name, required to be valid
544 # Give it a name, required to be valid
543 @query = Query.new(:name => "_")
545 @query = Query.new(:name => "_")
544 @query.project = @project
546 @query.project = @project
545 if params[:fields] and params[:fields].is_a? Array
547 if params[:fields] and params[:fields].is_a? Array
546 params[:fields].each do |field|
548 params[:fields].each do |field|
547 @query.add_filter(field, params[:operators][field], params[:values][field])
549 @query.add_filter(field, params[:operators][field], params[:values][field])
548 end
550 end
549 else
551 else
550 @query.available_filters.keys.each do |field|
552 @query.available_filters.keys.each do |field|
551 @query.add_short_filter(field, params[field]) if params[field]
553 @query.add_short_filter(field, params[field]) if params[field]
552 end
554 end
553 end
555 end
554 @query.group_by = params[:group_by]
556 @query.group_by = params[:group_by]
555 @query.column_names = params[:query] && params[:query][:column_names]
557 @query.column_names = params[:query] && params[:query][:column_names]
556 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
558 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
557 else
559 else
558 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
560 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
559 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
561 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
560 @query.project = @project
562 @query.project = @project
561 end
563 end
562 end
564 end
563 end
565 end
564
566
565 # Rescues an invalid query statement. Just in case...
567 # Rescues an invalid query statement. Just in case...
566 def query_statement_invalid(exception)
568 def query_statement_invalid(exception)
567 logger.error "Query::StatementInvalid: #{exception.message}" if logger
569 logger.error "Query::StatementInvalid: #{exception.message}" if logger
568 session.delete(:query)
570 session.delete(:query)
569 sort_clear
571 sort_clear
570 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
572 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
571 end
573 end
572 end
574 end
General Comments 0
You need to be logged in to leave comments. Login now