mirror of
https://github.com/redmine/redmine.git
synced 2025-11-02 19:36:00 +01:00
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
This commit is contained in:
@@ -74,11 +74,11 @@ class IssuesController < ApplicationController
|
|||||||
format.csv do
|
format.csv do
|
||||||
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
|
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
|
||||||
send_data(query_to_csv(@issues, @query, params[:csv]),
|
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
|
end
|
||||||
format.pdf do
|
format.pdf do
|
||||||
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
|
@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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class TimelogController < ApplicationController
|
|||||||
format.csv do
|
format.csv do
|
||||||
# Export all entries
|
# Export all entries
|
||||||
@entries = scope.to_a
|
@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
|
end
|
||||||
|
|||||||
@@ -329,6 +329,14 @@ module QueriesHelper
|
|||||||
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
|
# Retrieve query from session or build a new query
|
||||||
def retrieve_query(klass=IssueQuery, use_session=true, options={})
|
def retrieve_query(klass=IssueQuery, use_session=true, options={})
|
||||||
session_key = klass.name.underscore.to_sym
|
session_key = klass.name.underscore.to_sym
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
|
<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 %>
|
<%= form_tag(_project_issues_path(@project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
|
||||||
<%= query_as_hidden_field_tags(@query) %>
|
<%= query_as_hidden_field_tags(@query) %>
|
||||||
|
<%= hidden_field_tag('query_name', @query.name) %>
|
||||||
<p>
|
<p>
|
||||||
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
|
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
|
||||||
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
|
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
|
<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 %>
|
<%= form_tag(_time_entries_path(@project, nil, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
|
||||||
<%= query_as_hidden_field_tags @query %>
|
<%= query_as_hidden_field_tags @query %>
|
||||||
|
<%= hidden_field_tag('query_name', @query.name) %>
|
||||||
<p>
|
<p>
|
||||||
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
|
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
|
||||||
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
|
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
|
||||||
|
|||||||
@@ -850,6 +850,18 @@ class IssuesControllerTest < Redmine::ControllerTest
|
|||||||
assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
|
assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
|
||||||
end
|
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
|
def test_index_csv_with_project
|
||||||
get(
|
get(
|
||||||
:index,
|
:index,
|
||||||
@@ -1182,6 +1194,20 @@ class IssuesControllerTest < Redmine::ControllerTest
|
|||||||
assert_equal 'application/pdf', @response.media_type
|
assert_equal 'application/pdf', @response.media_type
|
||||||
end
|
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
|
def test_index_atom
|
||||||
get(
|
get(
|
||||||
:index,
|
:index,
|
||||||
|
|||||||
@@ -1690,6 +1690,18 @@ class TimelogControllerTest < Redmine::ControllerTest
|
|||||||
end
|
end
|
||||||
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
|
def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
|
entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
|
||||||
|
|||||||
Reference in New Issue
Block a user