Feature #16207 » feature-16207.patch
app/controllers/issues_controller.rb | ||
---|---|---|
66 | 66 |
} |
67 | 67 |
format.csv { |
68 | 68 |
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i) |
69 |
send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') |
|
69 |
send_data(query_to_csv(@issues, @query, params[:csv]), |
|
70 |
:type => 'text/csv; header=present', |
|
71 |
:filename => "#{exported_query_filename(@query, 'issues')}.csv") |
|
70 | 72 |
} |
71 | 73 |
format.pdf { |
72 | 74 |
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i) |
73 |
send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf'
|
|
75 |
send_file_headers! :type => 'application/pdf', :filename => "#{exported_query_filename(@query, 'issues')}.pdf"
|
|
74 | 76 |
} |
75 | 77 |
end |
76 | 78 |
else |
app/controllers/timelog_controller.rb | ||
---|---|---|
68 | 68 |
format.csv { |
69 | 69 |
# Export all entries |
70 | 70 |
@entries = scope.to_a |
71 |
send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
|
71 |
send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => "#{exported_query_filename(@query, 'timelog')}.csv")
|
|
72 | 72 |
} |
73 | 73 |
end |
74 | 74 |
end |
app/helpers/queries_helper.rb | ||
---|---|---|
287 | 287 |
end |
288 | 288 |
end |
289 | 289 | |
290 |
def exported_query_filename(query, default_name) |
|
291 |
query_name = params[:query_name].presence || query.name |
|
292 |
query_name = default_name if query_name == '_' || query_name.blank? |
|
293 | ||
294 |
# Convert file names using the same rules as Wiki titles |
|
295 |
filename_for_content_disposition(Wiki.titleize(query_name).downcase) |
|
296 |
end |
|
297 | ||
290 | 298 |
# Retrieve query from session or build a new query |
291 | 299 |
def retrieve_query(klass=IssueQuery, use_session=true, options={}) |
292 | 300 |
session_key = klass.name.underscore.to_sym |
app/views/issues/index.html.erb | ||
---|---|---|
42 | 42 |
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3> |
43 | 43 |
<%= form_tag(_project_issues_path(@project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %> |
44 | 44 |
<%= query_as_hidden_field_tags(@query) %> |
45 |
<%= hidden_field_tag('query_name', @query.name) %> |
|
45 | 46 |
<p> |
46 | 47 |
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br /> |
47 | 48 |
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label> |
app/views/timelog/index.html.erb | ||
---|---|---|
30 | 30 |
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3> |
31 | 31 |
<%= form_tag(_time_entries_path(@project, nil, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %> |
32 | 32 |
<%= query_as_hidden_field_tags @query %> |
33 |
<%= hidden_field_tag('query_name', @query.name) %> |
|
33 | 34 |
<p> |
34 | 35 |
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br /> |
35 | 36 |
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label> |
test/functional/issues_controller_test.rb | ||
---|---|---|
670 | 670 |
assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size |
671 | 671 |
end |
672 | 672 | |
673 | ||
674 |
def test_index_csv_filename_without_query_name_param |
|
675 |
get :index, :params => {:format => 'csv'} |
|
676 |
assert_response :success |
|
677 |
assert_match /issues.csv/, @response.headers['Content-Disposition'] |
|
678 |
end |
|
679 | ||
680 |
def test_index_csv_filename_with_query_name_param |
|
681 |
get :index, :params => {:query_name => 'My Query Name', :format => 'csv'} |
|
682 |
assert_response :success |
|
683 |
assert_match /my_query_name\.csv/, @response.headers['Content-Disposition'] |
|
684 |
end |
|
685 | ||
673 | 686 |
def test_index_csv_with_project |
674 | 687 |
get :index, :params => { |
675 | 688 |
:project_id => 1, |
... | ... | |
935 | 948 |
assert_equal 'application/pdf', @response.content_type |
936 | 949 |
end |
937 | 950 | |
951 |
def test_index_pdf_filename_without_query |
|
952 |
get :index, :params => {:format => 'pdf'} |
|
953 |
assert_response :success |
|
954 |
assert_match /issues.pdf/, @response.headers['Content-Disposition'] |
|
955 |
end |
|
956 | ||
957 |
def test_index_pdf_filename_with_query |
|
958 |
query = IssueQuery.create!(:name => 'My Query Name', :visibility => IssueQuery::VISIBILITY_PUBLIC) |
|
959 |
get :index, :params => {:query_id => query.id, :format => 'pdf'} |
|
960 | ||
961 |
assert_response :success |
|
962 |
assert_match /my_query_name\.pdf/, @response.headers['Content-Disposition'] |
|
963 |
end |
|
964 | ||
938 | 965 |
def test_index_atom |
939 | 966 |
get :index, :params => { |
940 | 967 |
:project_id => 'ecookbook', |
test/functional/timelog_controller_test.rb | ||
---|---|---|
1362 | 1362 |
end |
1363 | 1363 |
end |
1364 | 1364 | |
1365 |
def test_index_csv_filename_query_name_param |
|
1366 |
get :index, :params => {:format => 'csv'} |
|
1367 |
assert_response :success |
|
1368 |
assert_match /timelog.csv/, @response.headers['Content-Disposition'] |
|
1369 |
end |
|
1370 | ||
1371 |
def test_index_csv_filename_with_query_name_param |
|
1372 |
get :index, :params => {:query_name => 'My Query Name', :format => 'csv'} |
|
1373 |
assert_response :success |
|
1374 |
assert_match /my_query_name\.csv/, @response.headers['Content-Disposition'] |
|
1375 |
end |
|
1376 | ||
1365 | 1377 |
def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject |
1366 | 1378 |
issue = Issue.find(1) |
1367 | 1379 |
entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test") |