mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-26 10:21:14 +00:00
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
This commit is contained in:
parent
f1f913afc6
commit
5011117086
@ -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
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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 %>
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
35
test/helpers/projects_queries_helper_test.rb
Normal file
35
test/helpers/projects_queries_helper_test.rb
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user