Project

General

Profile

Feature #16207 » feature-16207-r21769.patch

Go MAEDA, 2022-08-12 07:24

View differences:

app/controllers/issues_controller.rb
74 74
        format.csv do
75 75
          @issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
76 76
          send_data(query_to_csv(@issues, @query, params[:csv]),
77
                    :type => 'text/csv; header=present', :filename => 'issues.csv')
77
                    :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'issues')}.csv")
78 78
        end
79 79
        format.pdf do
80 80
          @issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
81
          send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf'
81
          send_file_headers! :type => 'application/pdf', :filename => "#{filename_for_export(@query, 'issues')}.pdf"
82 82
        end
83 83
      end
84 84
    else
app/controllers/timelog_controller.rb
67 67
      format.csv do
68 68
        # Export all entries
69 69
        @entries = scope.to_a
70
        send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
70
        send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'timelog')}.csv")
71 71
      end
72 72
    end
73 73
  end
app/helpers/queries_helper.rb
329 329
    end
330 330
  end
331 331

  
332
  def filename_for_export(query, default_name)
333
    query_name = params[:query_name].presence || query.name
334
    query_name = default_name if query_name == '_' || query_name.blank?
335

  
336
    # Convert file names using the same rules as Wiki titles
337
    filename_for_content_disposition(Wiki.titleize(query_name).downcase)
338
  end
339

  
332 340
  # Retrieve query from session or build a new query
333 341
  def retrieve_query(klass=IssueQuery, use_session=true, options={})
334 342
    session_key = klass.name.underscore.to_sym
app/views/issues/index.html.erb
43 43
  <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
44 44
  <%= form_tag(_project_issues_path(@project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
45 45
  <%= query_as_hidden_field_tags(@query) %>
46
  <%= hidden_field_tag('query_name', @query.name) %>
46 47
  <p>
47 48
    <label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
48 49
    <label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
app/views/timelog/index.html.erb
36 36
  <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
37 37
  <%= form_tag(_time_entries_path(@project, nil, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
38 38
  <%= query_as_hidden_field_tags @query %>
39
  <%= hidden_field_tag('query_name', @query.name) %>
39 40
  <p>
40 41
    <label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
41 42
    <label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
test/functional/issues_controller_test.rb
850 850
    assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
851 851
  end
852 852

  
853

  
854
  def test_index_csv_filename_without_query_name_param
855
    get :index, :params => {:format => 'csv'}
856
    assert_response :success
857
    assert_match /issues.csv/, @response.headers['Content-Disposition']
858
  end
859

  
860
  def test_index_csv_filename_with_query_name_param
861
    get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
862
    assert_response :success
863
    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
864
  end
865

  
853 866
  def test_index_csv_with_project
854 867
    get(
855 868
      :index,
......
1182 1195
    assert_equal 'application/pdf', @response.media_type
1183 1196
  end
1184 1197

  
1198
  def test_index_pdf_filename_without_query
1199
    get :index, :params => {:format => 'pdf'}
1200
    assert_response :success
1201
    assert_match /issues.pdf/, @response.headers['Content-Disposition']
1202
  end
1203

  
1204
  def test_index_pdf_filename_with_query
1205
    query = IssueQuery.create!(:name => 'My Query Name', :visibility => IssueQuery::VISIBILITY_PUBLIC)
1206
    get :index, :params => {:query_id => query.id, :format => 'pdf'}
1207

  
1208
    assert_response :success
1209
    assert_match /my_query_name\.pdf/, @response.headers['Content-Disposition']
1210
  end
1211

  
1185 1212
  def test_index_atom
1186 1213
    get(
1187 1214
      :index,
test/functional/timelog_controller_test.rb
1690 1690
    end
1691 1691
  end
1692 1692

  
1693
  def test_index_csv_filename_query_name_param
1694
    get :index, :params => {:format => 'csv'}
1695
    assert_response :success
1696
    assert_match /timelog.csv/, @response.headers['Content-Disposition']
1697
  end
1698

  
1699
  def test_index_csv_filename_with_query_name_param
1700
    get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
1701
    assert_response :success
1702
    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
1703
  end
1704

  
1693 1705
  def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
1694 1706
    issue = Issue.find(1)
1695 1707
    entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
(6-6/6)