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