format.csv do
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
send_data(query_to_csv(@issues, @query, params[:csv]),
- :type => 'text/csv; header=present', :filename => 'issues.csv')
+ :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'issues')}.csv")
end
format.pdf do
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
- send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf'
+ send_file_headers! :type => 'application/pdf', :filename => "#{filename_for_export(@query, 'issues')}.pdf"
end
end
else
format.csv do
# Export all entries
@entries = scope.to_a
- send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
+ send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'timelog')}.csv")
end
end
end
end
end
+ def filename_for_export(query, default_name)
+ query_name = params[:query_name].presence || query.name
+ query_name = default_name if query_name == '_' || query_name.blank?
+
+ # Convert file names using the same rules as Wiki titles
+ filename_for_content_disposition(Wiki.titleize(query_name).downcase)
+ end
+
# Retrieve query from session or build a new query
def retrieve_query(klass=IssueQuery, use_session=true, options={})
session_key = klass.name.underscore.to_sym
<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('query_name', @query.name) %>
<p>
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
<%= form_tag(_time_entries_path(@project, nil, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
<%= query_as_hidden_field_tags @query %>
+ <%= hidden_field_tag('query_name', @query.name) %>
<p>
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
end
+ def test_index_csv_filename_without_query_name_param
+ get :index, :params => {:format => 'csv'}
+ assert_response :success
+ assert_match /issues.csv/, @response.headers['Content-Disposition']
+ end
+
+ def test_index_csv_filename_with_query_name_param
+ get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
+ assert_response :success
+ assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
+ end
+
def test_index_csv_with_project
get(
:index,
assert_equal 'application/pdf', @response.media_type
end
+ def test_index_pdf_filename_without_query
+ get :index, :params => {:format => 'pdf'}
+ assert_response :success
+ assert_match /issues.pdf/, @response.headers['Content-Disposition']
+ end
+
+ def test_index_pdf_filename_with_query
+ query = IssueQuery.create!(:name => 'My Query Name', :visibility => IssueQuery::VISIBILITY_PUBLIC)
+ get :index, :params => {:query_id => query.id, :format => 'pdf'}
+
+ assert_response :success
+ assert_match /my_query_name\.pdf/, @response.headers['Content-Disposition']
+ end
+
def test_index_atom
get(
:index,
end
end
+ def test_index_csv_filename_query_name_param
+ get :index, :params => {:format => 'csv'}
+ assert_response :success
+ assert_match /timelog.csv/, @response.headers['Content-Disposition']
+ end
+
+ def test_index_csv_filename_with_query_name_param
+ get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
+ assert_response :success
+ assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
+ end
+
def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
issue = Issue.find(1)
entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")