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