diff options
author | Go MAEDA <maeda@farend.jp> | 2022-08-24 13:21:50 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2022-08-24 13:21:50 +0000 |
commit | f8033a069f99fd9947f05c2f4076bd8f0f575f98 (patch) | |
tree | 78d2330db21ecf052a618bf47324047183dc4fb6 | |
parent | 35b2d6a244803a4f0a767a5ff5bcb9137a1d60c4 (diff) | |
download | redmine-f8033a069f99fd9947f05c2f4076bd8f0f575f98.tar.gz redmine-f8033a069f99fd9947f05c2f4076bd8f0f575f98.zip |
Use query name as the file name when exporting queries (#16207).
Patch by Mizuki ISHIKAWA.
git-svn-id: https://svn.redmine.org/redmine/trunk@21773 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/issues_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/timelog_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/queries_helper.rb | 8 | ||||
-rw-r--r-- | app/views/issues/index.html.erb | 1 | ||||
-rw-r--r-- | app/views/timelog/index.html.erb | 1 | ||||
-rw-r--r-- | test/functional/issues_controller_test.rb | 26 | ||||
-rw-r--r-- | test/functional/timelog_controller_test.rb | 12 |
7 files changed, 51 insertions, 3 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 5d67cd8cc..683dbc1e8 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -74,11 +74,11 @@ class IssuesController < ApplicationController 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 diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index c0570c304..d47687f1b 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -67,7 +67,7 @@ class TimelogController < ApplicationController 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 diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index ffd291280..38d72bbc6 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -329,6 +329,14 @@ module QueriesHelper 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 diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 5a4d6b2c4..3e0d0cfe8 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -43,6 +43,7 @@ <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> diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index f6751ebc8..e957b41b3 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -36,6 +36,7 @@ <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> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 9028141f3..859fb2ff7 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -850,6 +850,18 @@ class IssuesControllerTest < Redmine::ControllerTest 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, @@ -1182,6 +1194,20 @@ class IssuesControllerTest < Redmine::ControllerTest 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, diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index deb75a5bb..d36279d13 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -1690,6 +1690,18 @@ class TimelogControllerTest < Redmine::ControllerTest 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") |