1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 class ProjectsController < ApplicationController
22 before_filter :find_project, :except => [ :index, :list, :add ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 accept_key_auth :activity, :calendar
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
34 include CustomFieldsHelper
42 include RepositoriesHelper
43 include ProjectsHelper
47 render :action => 'list' unless request.xhr?
50 # Lists visible projects
52 projects = Project.find :all,
53 :conditions => Project.visible_by(logged_in_user),
55 @project_tree = projects.group_by {|p| p.parent || p}
56 @project_tree.each_key {|p| @project_tree[p] -= [p]}
61 @custom_fields = IssueCustomField.find(:all)
62 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
63 @project = Project.new(params[:project])
64 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
68 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
69 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
70 @project.custom_values = @custom_values
72 @project.enabled_module_names = params[:enabled_modules]
73 flash[:notice] = l(:notice_successful_create)
74 redirect_to :controller => 'admin', :action => 'projects'
81 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
82 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
83 @subprojects = @project.active_children
84 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
85 @trackers = Tracker.find(:all, :order => 'position')
86 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
87 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
88 @total_hours = @project.time_entries.sum(:hours)
89 @key = User.current.rss_key
93 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
94 @custom_fields = IssueCustomField.find(:all)
95 @issue_category ||= IssueCategory.new
96 @member ||= @project.members.new
97 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
98 @repository ||= @project.repository
99 @wiki ||= @project.wiki
105 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
106 if params[:custom_fields]
107 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
108 @project.custom_values = @custom_values
110 @project.attributes = params[:project]
112 flash[:notice] = l(:notice_successful_update)
113 redirect_to :action => 'settings', :id => @project
116 render :action => 'settings'
122 @project.enabled_module_names = params[:enabled_modules]
123 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
127 @project.archive if request.post? && @project.active?
128 redirect_to :controller => 'admin', :action => 'projects'
132 @project.unarchive if request.post? && !@project.active?
133 redirect_to :controller => 'admin', :action => 'projects'
138 @project_to_destroy = @project
139 if request.post? and params[:confirm]
140 @project_to_destroy.destroy
141 redirect_to :controller => 'admin', :action => 'projects'
143 # hide project in layout
147 # Add a new issue category to @project
148 def add_issue_category
149 @category = @project.issue_categories.build(params[:category])
150 if request.post? and @category.save
151 respond_to do |format|
153 flash[:notice] = l(:notice_successful_create)
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
157 # IE doesn't support the replace_html rjs method for select box options
158 render(:update) {|page| page.replace "issue_category_id",
159 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
166 # Add a new version to @project
168 @version = @project.versions.build(params[:version])
169 if request.post? and @version.save
170 flash[:notice] = l(:notice_successful_create)
171 redirect_to :action => 'settings', :tab => 'versions', :id => @project
175 # Add a new document to @project
177 @document = @project.documents.build(params[:document])
178 if request.post? and @document.save
179 # Save the attachments
180 params[:attachments].each { |a|
181 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
182 } if params[:attachments] and params[:attachments].is_a? Array
183 flash[:notice] = l(:notice_successful_create)
184 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
185 redirect_to :action => 'list_documents', :id => @project
189 # Show documents list of @project
191 @documents = @project.documents.find :all, :include => :category
194 # Add a new issue to @project
196 @tracker = Tracker.find(params[:tracker_id])
197 @priorities = Enumeration::get_values('IPRI')
199 default_status = IssueStatus.default
200 unless default_status
201 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
202 render :nothing => true, :layout => true
205 @issue = Issue.new(:project => @project, :tracker => @tracker)
206 @issue.status = default_status
207 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
209 @issue.start_date = Date.today
210 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
212 @issue.attributes = params[:issue]
214 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
215 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
217 @issue.author_id = self.logged_in_user.id if self.logged_in_user
218 # Multiple file upload
220 params[:attachments].each { |a|
221 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
222 } if params[:attachments] and params[:attachments].is_a? Array
223 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
224 @issue.custom_values = @custom_values
226 @attachments.each(&:save)
227 flash[:notice] = l(:notice_successful_create)
228 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
229 redirect_to :action => 'list_issues', :id => @project
234 # Show filtered/sorted issues list of @project
236 sort_init "#{Issue.table_name}.id", "desc"
241 @results_per_page_options = [ 15, 25, 50, 100 ]
242 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
243 @results_per_page = params[:per_page].to_i
244 session[:results_per_page] = @results_per_page
246 @results_per_page = session[:results_per_page] || 25
250 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
251 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
252 @issues = Issue.find :all, :order => sort_clause,
253 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
254 :conditions => @query.statement,
255 :limit => @issue_pages.items_per_page,
256 :offset => @issue_pages.current.offset
259 render :layout => false if request.xhr?
262 # Export filtered/sorted issues list to CSV
263 def export_issues_csv
264 sort_init "#{Issue.table_name}.id", "desc"
268 render :action => 'list_issues' and return unless @query.valid?
270 @issues = Issue.find :all, :order => sort_clause,
271 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
272 :conditions => @query.statement,
273 :limit => Setting.issues_export_limit.to_i
275 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
276 export = StringIO.new
277 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
279 headers = [ "#", l(:field_status),
284 l(:field_assigned_to),
286 l(:field_start_date),
288 l(:field_done_ratio),
289 l(:field_created_on),
292 for custom_field in @project.all_custom_fields
293 headers << custom_field.name
295 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
297 @issues.each do |issue|
298 fields = [issue.id, issue.status.name,
303 (issue.assigned_to ? issue.assigned_to.name : ""),
305 issue.start_date ? l_date(issue.start_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
308 l_datetime(issue.created_on),
309 l_datetime(issue.updated_on)
311 for custom_field in @project.all_custom_fields
312 fields << (show_value issue.custom_value_for(custom_field))
314 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
321 # Export filtered/sorted issues to PDF
322 def export_issues_pdf
323 sort_init "#{Issue.table_name}.id", "desc"
327 render :action => 'list_issues' and return unless @query.valid?
329 @issues = Issue.find :all, :order => sort_clause,
330 :include => [ :author, :status, :tracker, :priority, :project ],
331 :conditions => @query.statement,
332 :limit => Setting.issues_export_limit.to_i
334 @options_for_rfpdf ||= {}
335 @options_for_rfpdf[:file_name] = "export.pdf"
336 render :layout => false
342 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
343 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
344 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
345 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
346 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
347 issues = @project.issues.find_all_by_id(params[:issue_ids])
348 unsaved_issue_ids = []
349 issues.each do |issue|
350 journal = issue.init_journal(User.current, params[:notes])
351 issue.priority = priority if priority
352 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
353 issue.category = category if category
354 issue.fixed_version = fixed_version if fixed_version
355 issue.start_date = params[:start_date] unless params[:start_date].blank?
356 issue.due_date = params[:due_date] unless params[:due_date].blank?
357 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
358 # Don't save any change to the issue if the user is not authorized to apply the requested status
359 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
360 # Send notification for each issue (if changed)
361 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
363 # Keep unsaved issue ids to display them in flash error
364 unsaved_issue_ids << issue.id
367 if unsaved_issue_ids.empty?
368 flash[:notice] = l(:notice_successful_update) unless issues.empty?
370 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
372 redirect_to :action => 'list_issues', :id => @project
375 if current_role && User.current.allowed_to?(:change_issue_status, @project)
376 # Find potential statuses the user could be allowed to switch issues to
377 @available_statuses = Workflow.find(:all, :include => :new_status,
378 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
380 render :update do |page|
381 page.hide 'query_form'
382 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
387 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
388 redirect_to :action => 'list_issues', :id => @project and return unless @issues
390 # find projects to which the user is allowed to move the issue
391 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
392 # issue can be moved to any tracker
393 @trackers = Tracker.find(:all)
394 if request.post? and params[:new_project_id] and params[:new_tracker_id]
395 new_project = Project.find_by_id(params[:new_project_id])
396 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
398 if new_project && i.project_id != new_project.id
399 # issue is moved to another project
401 i.fixed_version = nil
402 # delete issue relations
403 i.relations_from.clear
405 i.project = new_project
408 i.tracker = new_tracker
412 flash[:notice] = l(:notice_successful_update)
413 redirect_to :action => 'list_issues', :id => @project
417 # Add a news to @project
419 @news = News.new(:project => @project)
421 @news.attributes = params[:news]
422 @news.author_id = self.logged_in_user.id if self.logged_in_user
424 flash[:notice] = l(:notice_successful_create)
425 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
426 redirect_to :action => 'list_news', :id => @project
431 # Show news list of @project
433 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
435 respond_to do |format|
436 format.html { render :layout => false if request.xhr? }
437 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
443 @version = @project.versions.find_by_id(params[:version_id])
444 # Save the attachments
446 params[:attachments].each { |file|
447 next unless file.size > 0
448 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
449 @attachments << a unless a.new_record?
450 } if params[:attachments] and params[:attachments].is_a? Array
451 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
452 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
454 @versions = @project.versions.sort
458 @versions = @project.versions.sort
461 # Show changelog for @project
463 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
464 retrieve_selected_tracker_ids(@trackers)
465 @versions = @project.versions.sort
469 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
470 retrieve_selected_tracker_ids(@trackers)
471 @versions = @project.versions.sort
472 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
476 if params[:year] and params[:year].to_i > 1900
477 @year = params[:year].to_i
478 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
479 @month = params[:month].to_i
482 @year ||= Date.today.year
483 @month ||= Date.today.month
488 @date_from = Date.today - 30
489 @date_to = Date.today + 1
492 @date_from = Date.civil(@year, @month, 1)
493 @date_to = @date_from >> 1
496 @event_types = %w(issues news files documents wiki_pages changesets)
497 @event_types.delete('wiki_pages') unless @project.wiki
498 @event_types.delete('changesets') unless @project.repository
499 # only show what the user is allowed to view
500 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
502 @scope = @event_types.select {|t| params["show_#{t}"]}
503 # default events if none is specified in parameters
504 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
508 if @scope.include?('issues')
509 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
512 if @scope.include?('news')
513 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
516 if @scope.include?('files')
517 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
520 if @scope.include?('documents')
521 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
522 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
525 if @scope.include?('wiki_pages')
526 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
527 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
528 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
529 "#{WikiContent.versioned_table_name}.id"
530 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
531 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
532 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
533 @project.id, @date_from, @date_to]
535 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
538 if @scope.include?('changesets')
539 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
542 @events_by_day = @events.group_by(&:event_date)
544 respond_to do |format|
545 format.html { render :layout => false if request.xhr? }
546 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
551 @trackers = Tracker.find(:all, :order => 'position')
552 retrieve_selected_tracker_ids(@trackers)
554 if params[:year] and params[:year].to_i > 1900
555 @year = params[:year].to_i
556 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
557 @month = params[:month].to_i
560 @year ||= Date.today.year
561 @month ||= Date.today.month
562 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
565 @project.issues_with_subprojects(params[:with_subprojects]) do
566 events += Issue.find(:all,
567 :include => [:tracker, :status, :assigned_to, :priority, :project],
568 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
569 ) unless @selected_tracker_ids.empty?
571 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
572 @calendar.events = events
574 render :layout => false if request.xhr?
578 @trackers = Tracker.find(:all, :order => 'position')
579 retrieve_selected_tracker_ids(@trackers)
581 if params[:year] and params[:year].to_i >0
582 @year_from = params[:year].to_i
583 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
584 @month_from = params[:month].to_i
589 @month_from ||= Date.today.month
590 @year_from ||= Date.today.year
593 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
594 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
595 months = (params[:months] || User.current.pref[:gantt_months]).to_i
596 @months = (months > 0 && months < 25) ? months : 6
598 # Save gantt paramters as user preference (zoom and months count)
599 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
600 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
601 User.current.preference.save
604 @date_from = Date.civil(@year_from, @month_from, 1)
605 @date_to = (@date_from >> @months) - 1
608 @project.issues_with_subprojects(params[:with_subprojects]) do
609 @events += Issue.find(:all,
610 :order => "start_date, due_date",
611 :include => [:tracker, :status, :assigned_to, :priority, :project],
612 :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 and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
613 ) unless @selected_tracker_ids.empty?
615 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
616 @events.sort! {|x,y| x.start_date <=> y.start_date }
618 if params[:format]=='pdf'
619 @options_for_rfpdf ||= {}
620 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
621 render :template => "projects/gantt.rfpdf", :layout => false
622 elsif params[:format]=='png' && respond_to?('gantt_image')
623 image = gantt_image(@events, @date_from, @months, @zoom)
625 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
627 render :template => "projects/gantt.rhtml"
632 # Find project of id params[:id]
633 # if not found, redirect to project list
634 # Used as a before_filter
636 @project = Project.find(params[:id])
637 rescue ActiveRecord::RecordNotFound
641 def retrieve_selected_tracker_ids(selectable_trackers)
642 if ids = params[:tracker_ids]
643 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
645 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
649 # Retrieve query from session or build a new query
652 @query = @project.queries.find(params[:query_id])
653 @query.executed_by = logged_in_user
654 session[:query] = @query
656 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
657 # Give it a name, required to be valid
658 @query = Query.new(:name => "_", :executed_by => logged_in_user)
659 @query.project = @project
660 if params[:fields] and params[:fields].is_a? Array
661 params[:fields].each do |field|
662 @query.add_filter(field, params[:operators][field], params[:values][field])
665 @query.available_filters.keys.each do |field|
666 @query.add_short_filter(field, params[field]) if params[field]
669 session[:query] = @query
671 @query = session[:query]