Parcourir la source

Add field separator option to CSV export dialog (#37621).

Patch by Karel Pičman.


git-svn-id: https://svn.redmine.org/redmine/trunk@22359 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/5.1.0
Go MAEDA il y a 6 mois
Parent
révision
6a7f2536b5

+ 17
- 0
app/helpers/application_helper.rb Voir le fichier

@@ -1805,6 +1805,23 @@ module ApplicationHelper
end
end

def export_csv_separator_select_tag
options = [[l(:label_comma_char), ','], [l(:label_semi_colon_char), ';']]
# Add the separator from translations if it is missing
general_csv_separator = l(:general_csv_separator)
unless options.index { |option| option.last == general_csv_separator }
options << Array.new(2, general_csv_separator)
end
content_tag(:p) do
concat(
content_tag(:label) do
concat l(:label_fields_separator) + ' '
concat select_tag('field_separator', options_for_select(options, general_csv_separator))
end
)
end
end

# Returns an array of error messages for bulk edited items (issues, time entries)
def bulk_edit_error_messages(items)
messages = {}

+ 1
- 1
app/helpers/queries_helper.rb Voir le fichier

@@ -323,7 +323,7 @@ module QueriesHelper
def query_to_csv(items, query, options={})
columns = query.columns

Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
Redmine::Export::CSV.generate(encoding: params[:encoding], field_separator: params[:field_separator]) do |csv|
# csv header fields
csv << columns.map {|c| c.caption.to_s}
# csv lines

+ 1
- 0
app/views/issues/index.html.erb Voir le fichier

@@ -59,6 +59,7 @@
</fieldset>
<% end %>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_select_tag %>
<% if @issue_count > Setting.issues_export_limit.to_i %>
<p class="icon icon-warning">
<%= l(:setting_issues_export_limit) %>: <%= Setting.issues_export_limit.to_i %>

+ 1
- 0
app/views/projects/_list.html.erb Voir le fichier

@@ -66,6 +66,7 @@
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
</p>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_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);" %>

+ 1
- 0
app/views/reports/_details.html.erb Voir le fichier

@@ -32,6 +32,7 @@
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
<%= form_tag(project_issues_report_details_path(@project, :detail => params[:detail], :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_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);' %>

+ 1
- 0
app/views/roles/permissions.html.erb Voir le fichier

@@ -92,6 +92,7 @@
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
<%= form_tag(permissions_roles_path(:format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_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);' %>

+ 1
- 0
app/views/timelog/index.html.erb Voir le fichier

@@ -52,6 +52,7 @@
</fieldset>
<% end %>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_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);" %>

+ 1
- 0
app/views/timelog/report.html.erb Voir le fichier

@@ -72,6 +72,7 @@
<div id="csv-export-options" style="display: none;">
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_select_tag %>
<p class="buttons">
<%= submit_tag l(:button_export), :name => nil, :id => 'csv-export-button' %>
<%= submit_tag l(:button_cancel), :name => nil, :onclick => 'hideModal(this);', :type => 'button' %>

+ 1
- 0
app/views/users/index.html.erb Voir le fichier

@@ -45,6 +45,7 @@
</fieldset>
<% end %>
<%= export_csv_encoding_select_tag %>
<%= export_csv_separator_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);" %>

+ 1
- 1
lib/redmine/export/csv.rb Voir le fichier

@@ -31,7 +31,7 @@ module Redmine

class << self
def generate(options = {}, &block)
col_sep = l(:general_csv_separator)
col_sep = (options[:field_separator].presence || l(:general_csv_separator))
encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding))

str =

+ 14
- 0
test/helpers/application_helper_test.rb Voir le fichier

@@ -2244,6 +2244,20 @@ class ApplicationHelperTest < Redmine::HelperTest
end
end

def test_export_csv_separator_select_tag
with_locale 'en' do
result = export_csv_separator_select_tag
assert_equal ',', l(:general_csv_separator)
assert_select_in result, 'option[value=?][selected=selected]', ',', text: 'Comma'
assert_select_in result, 'option[value=?]', ';', text: 'Semicolon'
end
with_locale 'fr' do
result = export_csv_separator_select_tag
assert_equal ';', l(:general_csv_separator)
assert_select_in result, 'option[value=?][selected=selected]', ';'
end
end

private

def wiki_links_with_special_characters

+ 16
- 0
test/unit/lib/redmine/export/csv_test.rb Voir le fichier

@@ -44,4 +44,20 @@ class CsvTest < ActiveSupport::TestCase
assert_equal l(:general_csv_encoding), string.encoding.name
end
end

def test_generate_should_use_general_csv_separator_by_default
with_locale 'fr' do
string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)}
assert_equal ';', l(:general_csv_separator)
assert 'Foo;Bar', string
end
end

def test_generate_should_use_given_separator
with_locale 'fr' do
string = Redmine::Export::CSV.generate({field_separator: ','}) {|csv| csv << %w(Foo Bar)}
assert_equal ';', l(:general_csv_separator)
assert 'Foo,Bar', string
end
end
end

Chargement…
Annuler
Enregistrer