From f97d23b1b7eda8a3b3ef19cec471805a6d530665 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 15 Oct 2015 18:12:27 +0000 Subject: [PATCH] Isolates csv options for a hash param (#1159). git-svn-id: http://svn.redmine.org/redmine/trunk@14674 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 2 +- app/helpers/queries_helper.rb | 1 + app/views/issues/index.html.erb | 6 +++--- test/functional/issues_controller_test.rb | 10 +++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 4238215eb..e8e1e3c05 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -79,7 +79,7 @@ class IssuesController < ApplicationController Issue.load_visible_relations(@issues) if include_in_api_response?('relations') } format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } - format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') } + format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') } format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' } end else diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index f817265dd..865b950f8 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -184,6 +184,7 @@ module QueriesHelper end def query_to_csv(items, query, options={}) + options ||= {} columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) query.available_block_columns.each do |column| if options[column.name].present? diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index f08f76d65..de87c5ee2 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -79,11 +79,11 @@

<%= l(:label_export_options, :export_format => 'CSV') %>

<%= form_tag(params.merge({:format => 'csv',:page=>nil}), :method => :get, :id => 'csv-export-form') do %>

-
- +
+

- +

<% if @issue_count > Setting.issues_export_limit.to_i %>

diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 390da19a3..b2e496534 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -449,7 +449,7 @@ class IssuesControllerTest < ActionController::TestCase Issue.generate!(:description => 'test_index_csv_with_description') with_settings :default_language => 'en' do - get :index, :format => 'csv', :description => '1' + get :index, :format => 'csv', :csv => {:description => '1'} assert_response :success assert_not_nil assigns(:issues) end @@ -472,7 +472,7 @@ class IssuesControllerTest < ActionController::TestCase end def test_index_csv_with_all_columns - get :index, :format => 'csv', :columns => 'all' + get :index, :format => 'csv', :csv => {:columns => 'all'} assert_response :success assert_not_nil assigns(:issues) assert_equal 'text/csv; header=present', @response.content_type @@ -487,7 +487,7 @@ class IssuesControllerTest < ActionController::TestCase issue.custom_field_values = {1 => ['MySQL', 'Oracle']} issue.save! - get :index, :format => 'csv', :columns => 'all' + get :index, :format => 'csv', :csv => {:columns => 'all'} assert_response :success lines = @response.body.chomp.split("\n") assert lines.detect {|line| line.include?('"MySQL, Oracle"')} @@ -498,14 +498,14 @@ class IssuesControllerTest < ActionController::TestCase issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'}) with_settings :default_language => 'fr' do - get :index, :format => 'csv', :columns => 'all' + get :index, :format => 'csv', :csv => {:columns => 'all'} assert_response :success issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s} assert_include '185,60', issue_line end with_settings :default_language => 'en' do - get :index, :format => 'csv', :columns => 'all' + get :index, :format => 'csv', :csv => {:columns => 'all'} assert_response :success issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s} assert_include '185.60', issue_line -- 2.39.5