diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-11-02 07:22:45 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-11-02 07:22:45 +0000 |
commit | 501111708657d54eccefaa6d82b465d471b65ef9 (patch) | |
tree | c74c3f122bbe3bc791dac40d9e2c1c9df88e4dd4 | |
parent | f1f913afc655e66a2b5a4a7b42e1059b0d874ddb (diff) | |
download | redmine-501111708657d54eccefaa6d82b465d471b65ef9.tar.gz redmine-501111708657d54eccefaa6d82b465d471b65ef9.zip |
Fix CSV export of projects (#29482).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@18888 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/helpers/projects_queries_helper.rb | 11 | ||||
-rw-r--r-- | app/views/projects/_list.html.erb | 16 | ||||
-rw-r--r-- | app/views/projects/index.html.erb | 3 | ||||
-rw-r--r-- | test/functional/projects_controller_test.rb | 49 | ||||
-rw-r--r-- | test/helpers/projects_queries_helper_test.rb | 35 |
5 files changed, 109 insertions, 5 deletions
diff --git a/app/helpers/projects_queries_helper.rb b/app/helpers/projects_queries_helper.rb index b5de291c0..9a97cc861 100644 --- a/app/helpers/projects_queries_helper.rb +++ b/app/helpers/projects_queries_helper.rb @@ -38,16 +38,17 @@ module ProjectsQueriesHelper end end - def csv_content(column, item) - if item.is_a?(Project) + def csv_value(column, object, value) + if object.is_a?(Project) case column.name when :status - get_project_status_label[column.value_object(item)] + get_project_status_label[column.value_object(object)] when :parent_id - return item.parent.name unless item.parent.nil? + object.parent.name unless object.parent.nil? + else + super end end - super end private diff --git a/app/views/projects/_list.html.erb b/app/views/projects/_list.html.erb index 298ec8ca7..8f1f6d974 100644 --- a/app/views/projects/_list.html.erb +++ b/app/views/projects/_list.html.erb @@ -34,3 +34,19 @@ </table> </div> <span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span> + +<div id="csv-export-options" style="display:none;"> + <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3> + <%= form_tag(projects_path(:format => 'csv'), :method => :get, :id => 'csv-export-form') do %> + <%= query_as_hidden_field_tags(@query) %> + <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> + </p> + <%= export_csv_encoding_select_tag %> + <p class="buttons"> + <%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);", :data => { :disable_with => false } %> + <%= link_to_function l(:button_cancel), "hideModal(this);" %> + </p> + <% end %> +</div> diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 59fc4e6e2..4afb5de19 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -29,6 +29,9 @@ <% end %> <% other_formats_links do |f| %> + <% if @query.display_type == 'list' %> + <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '350px'); return false;" %> + <% end %> <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <% end %> diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 460752148..34c25d930 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -160,6 +160,55 @@ class ProjectsControllerTest < Redmine::ControllerTest assert_equal ['Name', 'Description', 'Status'], columns_in_list end + def test_index_as_board_should_not_include_csv_export + @request.session[:user_id] = 1 + + get :index + + assert_response :success + assert_select 'p.other-formats a.csv', 0 + assert_select '#csv-export-options', 0 + end + + def test_index_as_list_should_include_csv_export + @request.session[:user_id] = 1 + + get :index, :params => { + :display_type => 'list', + :f => ['parent_id'], + :op => {'parent_id' => '='}, + :v => {'parent_id' => ['1']} + } + assert_response :success + + # Assert CSV export link + assert_select 'p.other-formats a.csv' + + # Assert export modal + assert_select '#csv-export-options' do + assert_select 'form[action=?][method=get]', '/projects.csv' do + # filter + assert_select 'input[name=?][value=?]', 'f[]', 'parent_id' + assert_select 'input[name=?][value=?]', 'op[parent_id]', '=' + assert_select 'input[name=?][value=?]', 'v[parent_id][]', '1' + # columns + assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'name' + assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'identifier' + assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'short_description' + assert_select 'input[name=?][type=hidden]', 'c[]', 3 + assert_select 'input[name=?][value=?]', 'c[]', 'all_inline' + end + end + end + + def test_index_csv + with_settings :date_format => '%m/%d/%Y' do + get :index, :params => {:format => 'csv'} + assert_response :success + assert_equal 'text/csv', response.content_type + end + end + def test_autocomplete_js get :autocomplete, :params => { :format => 'js', diff --git a/test/helpers/projects_queries_helper_test.rb b/test/helpers/projects_queries_helper_test.rb new file mode 100644 index 000000000..e70471fe2 --- /dev/null +++ b/test/helpers/projects_queries_helper_test.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2019 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class ProjectsQueriesHelperTest < Redmine::HelperTest + include ProjectsQueriesHelper + + fixtures :projects, :enabled_modules, + :custom_fields, :custom_values + + def test_csv_value + c_status = QueryColumn.new(:status) + c_parent_id = QueryColumn.new(:parent_id) + + assert_equal "active", csv_value(c_status, Project.find(1), 1) + assert_equal "eCookbook", csv_value(c_parent_id, Project.find(4), 1) + end +end |