Project

General

Profile

Feature #16207 » feature-16207-r19982.patch

Go MAEDA, 2020-08-22 08:16

View differences:

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

  
300
  def exported_query_filename(query, default_name)
301
    query_name = params[:query_name].presence || query.name
302
    query_name = default_name if query_name == '_' || query_name.blank?
303

  
304
    # Convert file names using the same rules as Wiki titles
305
    filename_for_content_disposition(Wiki.titleize(query_name).downcase)
306
  end
307

  
300 308
  # Retrieve query from session or build a new query
301 309
  def retrieve_query(klass=IssueQuery, use_session=true, options={})
302 310
    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
805 805
    assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
806 806
  end
807 807

  
808

  
809
  def test_index_csv_filename_without_query_name_param
810
    get :index, :params => {:format => 'csv'}
811
    assert_response :success
812
    assert_match /issues.csv/, @response.headers['Content-Disposition']
813
  end
814

  
815
  def test_index_csv_filename_with_query_name_param
816
    get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
817
    assert_response :success
818
    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
819
  end
820

  
808 821
  def test_index_csv_with_project
809 822
    get(
810 823
      :index,
......
1137 1150
    assert_equal 'application/pdf', @response.media_type
1138 1151
  end
1139 1152

  
1153
  def test_index_pdf_filename_without_query
1154
    get :index, :params => {:format => 'pdf'}
1155
    assert_response :success
1156
    assert_match /issues.pdf/, @response.headers['Content-Disposition']
1157
  end
1158

  
1159
  def test_index_pdf_filename_with_query
1160
    query = IssueQuery.create!(:name => 'My Query Name', :visibility => IssueQuery::VISIBILITY_PUBLIC)
1161
    get :index, :params => {:query_id => query.id, :format => 'pdf'}
1162

  
1163
    assert_response :success
1164
    assert_match /my_query_name\.pdf/, @response.headers['Content-Disposition']
1165
  end
1166

  
1140 1167
  def test_index_atom
1141 1168
    with_settings :protocol => 'https', :host_name => 'example.net' do
1142 1169
      get(
test/functional/timelog_controller_test.rb
1472 1472
    end
1473 1473
  end
1474 1474

  
1475
  def test_index_csv_filename_query_name_param
1476
    get :index, :params => {:format => 'csv'}
1477
    assert_response :success
1478
    assert_match /timelog.csv/, @response.headers['Content-Disposition']
1479
  end
1480

  
1481
  def test_index_csv_filename_with_query_name_param
1482
    get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
1483
    assert_response :success
1484
    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
1485
  end
1486

  
1475 1487
  def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
1476 1488
    issue = Issue.find(1)
1477 1489
    entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
(5-5/6)