From d10ab869a7433c0e7c6f8ddbc56e23ec2098c97c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 18 Jan 2017 12:51:41 +0000 Subject: [PATCH] Handle csv columns selection in query to preload appropriate associations (#24865). git-svn-id: http://svn.redmine.org/redmine/trunk@16219 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/queries_helper.rb | 14 +++----------- app/models/query.rb | 3 +++ app/views/issues/index.html.erb | 6 +++--- app/views/timelog/index.html.erb | 4 ++-- test/functional/issues_controller_test.rb | 10 +++++----- test/functional/timelog_controller_test.rb | 7 ++++--- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index c1c46f483..458fb70fd 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -231,13 +231,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? - columns << column - end - end + columns = query.columns Redmine::Export::CSV.generate do |csv| # csv header fields @@ -310,10 +304,8 @@ module QueriesHelper else tags << hidden_field_tag("f[]", "", :id => nil) end - if query.column_names.present? - query.column_names.each do |name| - tags << hidden_field_tag("c[]", name, :id => nil) - end + query.columns.each do |column| + tags << hidden_field_tag("c[]", column.name, :id => nil) end if query.totalable_names.present? query.totalable_names.each do |name| diff --git a/app/models/query.rb b/app/models/query.rb index aba3dc854..7c85d7164 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -670,6 +670,9 @@ class Query < ActiveRecord::Base if names names = names.select {|n| n.is_a?(Symbol) || !n.blank? } names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } + if names.delete(:all_inline) + names = available_inline_columns.map(&:name) | names + end # Set column_names to nil if default columns if names == default_columns_names names = nil diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index a9f321c3d..3d456aad1 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -32,11 +32,11 @@ <%= query_as_hidden_field_tags(@query) %> <%= hidden_field_tag 'sort', @sort_criteria.to_param, :id => nil %>

-
- +
+

- +

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

diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index f70f7b8b6..b863ee40f 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -27,8 +27,8 @@ <%= form_tag(_time_entries_path(@project, nil, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %> <%= query_as_hidden_field_tags @query %>

-
- +
+

<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index e01b69f47..2e9a11c42 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -481,7 +481,7 @@ class IssuesControllerTest < Redmine::ControllerTest Issue.generate!(:description => 'test_index_csv_with_description') with_settings :default_language => 'en' do - get :index, :format => 'csv', :csv => {:description => '1'} + get :index, :format => 'csv', :c => [:tracker, :description] assert_response :success end @@ -503,7 +503,7 @@ class IssuesControllerTest < Redmine::ControllerTest end def test_index_csv_with_all_columns - get :index, :format => 'csv', :csv => {:columns => 'all'} + get :index, :format => 'csv', :c => ['all_inline'] assert_response :success assert_equal 'text/csv; header=present', @response.content_type @@ -518,7 +518,7 @@ class IssuesControllerTest < Redmine::ControllerTest issue.custom_field_values = {1 => ['MySQL', 'Oracle']} issue.save! - get :index, :format => 'csv', :csv => {:columns => 'all'} + get :index, :format => 'csv', :c => ['tracker', "cf_1"] assert_response :success lines = @response.body.chomp.split("\n") assert lines.detect {|line| line.include?('"MySQL, Oracle"')} @@ -529,14 +529,14 @@ class IssuesControllerTest < Redmine::ControllerTest 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', :csv => {:columns => 'all'} + get :index, :format => 'csv', :c => ['id', 'tracker', "cf_#{field.id}"] 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', :csv => {:columns => 'all'} + get :index, :format => 'csv', :c => ['id', 'tracker', "cf_#{field.id}"] 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 diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 594fb1e19..baad0c95d 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -985,9 +985,10 @@ class TimelogControllerTest < Redmine::ControllerTest assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' # columns - assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' - assert_select 'input[name=?][value=?]', 'c[]', 'user' - assert_select 'input[name=?]', 'c[]', 2 + assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'spent_on' + assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'user' + assert_select 'input[name=?][type=hidden]', 'c[]', 2 + assert_select 'input[name=?][value=?]', 'c[]', 'all_inline' end end end -- 2.39.5