diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-05 18:38:42 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-05 18:38:42 +0000 |
commit | 8509cf80f009436e900294acc821295f21e3b142 (patch) | |
tree | 37095d100c500b27cb2249dc3b7ece1198434637 /app/controllers | |
parent | 26a1ae4808368128f2cc8b348528506f358dab15 (diff) | |
download | redmine-8509cf80f009436e900294acc821295f21e3b142.tar.gz redmine-8509cf80f009436e900294acc821295f21e3b142.zip |
ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged into IssuesController#index
git-svn-id: http://redmine.rubyforge.org/svn/trunk@887 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/issues_controller.rb | 95 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 142 | ||||
-rw-r--r-- | app/controllers/queries_controller.rb | 4 |
3 files changed, 70 insertions, 171 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 228597931..602d551f3 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -16,9 +16,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class IssuesController < ApplicationController - layout 'base', :except => :export_pdf - before_filter :find_project, :authorize, :except => [:index, :preview] - accept_key_auth :index + layout 'base' + before_filter :find_project, :authorize, :except => [:index, :changes, :preview] + before_filter :find_optional_project, :only => [:index, :changes] + accept_key_auth :index, :changes cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ] @@ -37,37 +38,54 @@ class IssuesController < ApplicationController helper :queries helper :sort include SortHelper + include IssuesHelper def index sort_init "#{Issue.table_name}.id", "desc" sort_update retrieve_query if @query.valid? - @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) - @issue_pages = Paginator.new self, @issue_count, 25, params['page'] + limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25 + @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) + @issue_pages = Paginator.new self, @issue_count, limit, params['page'] @issues = Issue.find :all, :order => sort_clause, :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], :conditions => @query.statement, - :limit => @issue_pages.items_per_page, - :offset => @issue_pages.current.offset + :limit => limit, + :offset => @issue_pages.current.offset + respond_to do |format| + format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } + format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } + format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } + format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } + end + else + # Send html if the query is not valid + render(:template => 'issues/index.rhtml', :layout => !request.xhr?) end - respond_to do |format| - format.html { render :layout => false if request.xhr? } - format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } + end + + def changes + sort_init "#{Issue.table_name}.id", "desc" + sort_update + retrieve_query + if @query.valid? + @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], + :conditions => @query.statement, + :limit => 25, + :order => "#{Journal.table_name}.created_on DESC" end + @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) + render :layout => false, :content_type => 'application/atom+xml' end def show @custom_values = @issue.custom_values.find(:all, :include => :custom_field) @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") - - if params[:format]=='pdf' - @options_for_rfpdf ||= {} - @options_for_rfpdf[:file_name] = "#{@project.identifier}-#{@issue.id}.pdf" - render :template => 'issues/show.rfpdf', :layout => false - else - @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user - render :template => 'issues/show.rhtml' + @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user + respond_to do |format| + format.html { render :template => 'issues/show.rhtml' } + format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } end end @@ -152,7 +170,7 @@ class IssuesController < ApplicationController def destroy @issue.destroy - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project + redirect_to :action => 'index', :project_id => @project end def destroy_attachment @@ -195,23 +213,38 @@ private render_404 end + def find_optional_project + return true unless params[:project_id] + @project = Project.find(params[:project_id]) + authorize + rescue ActiveRecord::RecordNotFound + render_404 + end + # Retrieve query from session or build a new query def retrieve_query - if params[:set_filter] or !session[:query] or session[:query].project_id - # Give it a name, required to be valid - @query = Query.new(:name => "_", :executed_by => logged_in_user) - if params[:fields] and params[:fields].is_a? Array - params[:fields].each do |field| - @query.add_filter(field, params[:operators][field], params[:values][field]) + if params[:query_id] + @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)}) + @query.executed_by = logged_in_user + session[:query] = @query + else + if params[:set_filter] or !session[:query] or session[:query].project != @project + # Give it a name, required to be valid + @query = Query.new(:name => "_", :executed_by => logged_in_user) + @query.project = @project + if params[:fields] and params[:fields].is_a? Array + params[:fields].each do |field| + @query.add_filter(field, params[:operators][field], params[:values][field]) + end + else + @query.available_filters.keys.each do |field| + @query.add_short_filter(field, params[field]) if params[field] + end end + session[:query] = @query else - @query.available_filters.keys.each do |field| - @query.add_short_filter(field, params[field]) if params[field] - end + @query = session[:query] end - session[:query] = @query - else - @query = session[:query] end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ae9c242e0..4356ec774 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -15,8 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require 'csv' - class ProjectsController < ApplicationController layout 'base' before_filter :find_project, :except => [ :index, :list, :add ] @@ -238,118 +236,13 @@ class ProjectsController < ApplicationController end flash[:notice] = l(:notice_successful_create) Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project return end end @priorities = Enumeration::get_values('IPRI') end - # Show filtered/sorted issues list of @project - def list_issues - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - - @results_per_page_options = [ 15, 25, 50, 100 ] - if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i - @results_per_page = params[:per_page].to_i - session[:results_per_page] = @results_per_page - else - @results_per_page = session[:results_per_page] || 25 - end - - if @query.valid? - @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) - @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] - @issues = Issue.find :all, :order => sort_clause, - :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], - :conditions => @query.statement, - :limit => @issue_pages.items_per_page, - :offset => @issue_pages.current.offset - end - - render :layout => false if request.xhr? - end - - # Export filtered/sorted issues list to CSV - def export_issues_csv - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - render :action => 'list_issues' and return unless @query.valid? - - @issues = Issue.find :all, :order => sort_clause, - :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], - :conditions => @query.statement, - :limit => Setting.issues_export_limit.to_i - - ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') - export = StringIO.new - CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| - # csv header fields - headers = [ "#", l(:field_status), - l(:field_project), - l(:field_tracker), - l(:field_priority), - l(:field_subject), - l(:field_assigned_to), - l(:field_author), - l(:field_start_date), - l(:field_due_date), - l(:field_done_ratio), - l(:field_created_on), - l(:field_updated_on) - ] - for custom_field in @project.all_custom_fields - headers << custom_field.name - end - csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } - # csv lines - @issues.each do |issue| - fields = [issue.id, issue.status.name, - issue.project.name, - issue.tracker.name, - issue.priority.name, - issue.subject, - (issue.assigned_to ? issue.assigned_to.name : ""), - issue.author.name, - issue.start_date ? l_date(issue.start_date) : nil, - issue.due_date ? l_date(issue.due_date) : nil, - issue.done_ratio, - l_datetime(issue.created_on), - l_datetime(issue.updated_on) - ] - for custom_field in @project.all_custom_fields - fields << (show_value issue.custom_value_for(custom_field)) - end - csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } - end - end - export.rewind - send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') - end - - # Export filtered/sorted issues to PDF - def export_issues_pdf - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - render :action => 'list_issues' and return unless @query.valid? - - @issues = Issue.find :all, :order => sort_clause, - :include => [ :author, :status, :tracker, :priority, :project ], - :conditions => @query.statement, - :limit => Setting.issues_export_limit.to_i - - @options_for_rfpdf ||= {} - @options_for_rfpdf[:file_name] = "export.pdf" - render :layout => false - end - # Bulk edit issues def bulk_edit_issues if request.post? @@ -383,7 +276,7 @@ class ProjectsController < ApplicationController else flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) end - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project return end if current_role && User.current.allowed_to?(:change_issue_status, @project) @@ -399,7 +292,7 @@ class ProjectsController < ApplicationController def move_issues @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] - redirect_to :action => 'list_issues', :id => @project and return unless @issues + redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues @projects = [] # find projects to which the user is allowed to move the issue User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')} @@ -424,7 +317,7 @@ class ProjectsController < ApplicationController i.save end flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project end end @@ -659,31 +552,4 @@ private @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } end end - - # Retrieve query from session or build a new query - def retrieve_query - if params[:query_id] - @query = @project.queries.find(params[:query_id]) - @query.executed_by = logged_in_user - session[:query] = @query - else - if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id - # Give it a name, required to be valid - @query = Query.new(:name => "_", :executed_by => logged_in_user) - @query.project = @project - if params[:fields] and params[:fields].is_a? Array - params[:fields].each do |field| - @query.add_filter(field, params[:operators][field], params[:values][field]) - end - else - @query.available_filters.keys.each do |field| - @query.add_short_filter(field, params[field]) if params[field] - end - end - session[:query] = @query - else - @query = session[:query] - end - end - end end diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 72819bd68..7feafd35b 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -39,7 +39,7 @@ class QueriesController < ApplicationController if request.post? && params[:confirm] && @query.save flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query + redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query return end render :layout => false if request.xhr? @@ -57,7 +57,7 @@ class QueriesController < ApplicationController if @query.save flash[:notice] = l(:notice_successful_update) - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query + redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query end end end |