Project

General

Profile

Feature #29482 » 0001-Fix-CSV-export.patch

Marius BĂLTEANU, 2019-10-26 20:58

View differences:

app/helpers/projects_queries_helper.rb
38 38
    end
39 39
  end
40 40

  
41
  def csv_content(column, item)
42
    if item.is_a?(Project)
41
  def csv_value(column, object, value)
42
    if object.is_a?(Project)
43 43
      case column.name
44 44
      when :status
45
        get_project_status_label[column.value_object(item)]
45
        get_project_status_label[column.value_object(object)]
46 46
      when :parent_id
47
        return item.parent.name unless item.parent.nil?
47
        object.parent.name unless object.parent.nil?
48
      else
49
        super
48 50
      end
49 51
    end
50
    super
51 52
  end
52 53

  
53 54
  private
app/views/projects/_list.html.erb
34 34
</table>
35 35
</div>
36 36
<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
37

  
38
<div id="csv-export-options" style="display:none;">
39
  <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
40
  <%= form_tag(projects_path(:format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
41
  <%= query_as_hidden_field_tags(@query) %>
42
  <p>
43
    <label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
44
    <label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
45
  </p>
46
  <%= export_csv_encoding_select_tag %>
47
  <p class="buttons">
48
    <%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);", :data => { :disable_with => false } %>
49
    <%= link_to_function l(:button_cancel), "hideModal(this);" %>
50
  </p>
51
  <% end %>
52
</div>
app/views/projects/index.html.erb
29 29
<% end %>
30 30

  
31 31
<% other_formats_links do |f| %>
32
  <% if @query.display_type == 'list' %>
33
    <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
34
  <% end %>
32 35
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
33 36
<% end %>
34 37

  
test/functional/projects_controller_test.rb
160 160
    assert_equal ['Name', 'Description', 'Status'], columns_in_list
161 161
  end
162 162

  
163
  def test_index_as_board_should_not_include_csv_export
164
    @request.session[:user_id] = 1
165

  
166
    get :index
167

  
168
    assert_response :success
169
    assert_select 'p.other-formats a.csv', 0
170
    assert_select '#csv-export-options', 0
171
  end
172

  
173
  def test_index_as_list_should_include_csv_export
174
    @request.session[:user_id] = 1
175

  
176
    get :index, :params => {
177
      :display_type => 'list',
178
      :f => ['parent_id'],
179
      :op => {'parent_id' => '='},
180
      :v => {'parent_id' => ['1']}
181
    }
182
    assert_response :success
183

  
184
    # Assert CSV export link
185
    assert_select 'p.other-formats a.csv'
186

  
187
    # Assert export modal
188
    assert_select '#csv-export-options' do
189
      assert_select 'form[action=?][method=get]', '/projects.csv' do
190
        # filter
191
        assert_select 'input[name=?][value=?]', 'f[]', 'parent_id'
192
        assert_select 'input[name=?][value=?]', 'op[parent_id]', '='
193
        assert_select 'input[name=?][value=?]', 'v[parent_id][]', '1'
194
        # columns
195
        assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'name'
196
        assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'identifier'
197
        assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'short_description'
198
        assert_select 'input[name=?][type=hidden]', 'c[]', 3
199
        assert_select 'input[name=?][value=?]', 'c[]', 'all_inline'
200
      end
201
    end
202
  end
203

  
204
  def test_index_csv
205
    with_settings :date_format => '%m/%d/%Y' do
206
      get :index, :params => {:format => 'csv'}
207
      assert_response :success
208
      assert_equal 'text/csv', response.content_type
209
    end
210
  end
211

  
163 212
  def test_autocomplete_js
164 213
    get :autocomplete, :params => {
165 214
        :format => 'js',
test/helpers/projects_queries_helper_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-2019  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require File.expand_path('../../test_helper', __FILE__)
21

  
22
class ProjectsQueriesHelperTest < Redmine::HelperTest
23
  include ProjectsQueriesHelper
24

  
25
  fixtures :projects, :enabled_modules,
26
           :custom_fields, :custom_values
27

  
28
  def test_csv_value
29
    c_status = QueryColumn.new(:status)
30
    c_parent_id = QueryColumn.new(:parent_id)
31

  
32
    assert_equal "active", csv_value(c_status, Project.find(1), 1)
33
    assert_equal "eCookbook", csv_value(c_parent_id, Project.find(4), 1)
34
  end
35
end
(16-16/16)