Commit 248da850 authored by jplang's avatar jplang

Handle csv columns selection in query to preload appropriate associations (#24865).

git-svn-id: https://svn.redmine.org/redmine/trunk@16219 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 48e78478
......@@ -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|
......
......@@ -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
......
......@@ -32,11 +32,11 @@
<%= query_as_hidden_field_tags(@query) %>
<%= hidden_field_tag 'sort', @sort_criteria.to_param, :id => nil %>
<p>
<label><%= radio_button_tag 'csv[columns]', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'csv[columns]', 'all' %> <%= l(:description_all_columns) %></label>
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
</p>
<p>
<label><%= check_box_tag 'csv[description]', '1', @query.has_column?(:description) %> <%= l(:field_description) %></label>
<label><%= check_box_tag 'c[]', 'description', @query.has_column?(:description) %> <%= l(:field_description) %></label>
</p>
<% if @issue_count > Setting.issues_export_limit.to_i %>
<p class="icon icon-warning">
......
......@@ -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 %>
<p>
<label><%= radio_button_tag 'columns', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'columns', 'all' %> <%= l(:description_all_columns) %></label>
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
</p>
<p class="buttons">
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment