@query
end
end
+
+ # Returns the query definition as hidden field tags
+ def query_as_hidden_field_tags(query)
+ tags = hidden_field_tag("set_filter", "1", :id => nil)
+
+ if query.filters.present?
+ query.filters.each do |field, filter|
+ tags << hidden_field_tag("f[]", field, :id => nil)
+ tags << hidden_field_tag("op[#{field}]", filter[:operator], :id => nil)
+ filter[:values].each do |value|
+ tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
+ end
+ end
+ end
+ if query.column_names.present?
+ query.column_names.each do |name|
+ tags << hidden_field_tag("c[]", name, :id => nil)
+ end
+ end
+ if query.totalable_names.present?
+ query.totalable_names.each do |name|
+ tags << hidden_field_tag("t[]", name, :id => nil)
+ end
+ end
+ if query.group_by.present?
+ tags << hidden_field_tag("group_by", query.group_by, :id => nil)
+ end
+
+ tags
+ end
end
<% end %>
<div id="csv-export-options" style="display:none;">
- <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
- <%= form_tag(params.merge({:format => 'csv',:page=>nil}), :method => :get, :id => 'csv-export-form') do %>
+ <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
+ <%= form_tag(_project_issues_path(@project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
+ <%= query_as_hidden_field_tags(@query) %>
+ <%= hidden_field_tag 'sort', params[:sort], :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>
end
end
+ def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
+ get :index, :project_id => 1, :set_filter => "1", :tracker_id => "2", :sort => 'status', :c => ["status", "priority"]
+
+ assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
+ assert_select '#csv-export-form[method=?]', 'get'
+
+ assert_select '#csv-export-form' do
+ assert_select 'input[name=?][value=?]', 'set_filter', '1'
+
+ assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
+ assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
+ assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'
+
+ assert_select 'input[name=?][value=?]', 'c[]', 'status'
+ assert_select 'input[name=?][value=?]', 'c[]', 'priority'
+
+ assert_select 'input[name=?][value=?]', 'sort', 'status'
+ end
+ end
+
def test_index_csv
get :index, :format => 'csv'
assert_response :success