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