diff options
author | Go MAEDA <maeda@farend.jp> | 2023-10-21 06:19:13 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2023-10-21 06:19:13 +0000 |
commit | 6a7f2536b5562128f00ce0513d00350137986ad5 (patch) | |
tree | 2c6d91f22aecead424bf711e898644582209545e | |
parent | a69b43d5803f578a5dc8d6eda2dfd27f99d9863e (diff) | |
download | redmine-6a7f2536b5562128f00ce0513d00350137986ad5.tar.gz redmine-6a7f2536b5562128f00ce0513d00350137986ad5.zip |
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
-rw-r--r-- | app/helpers/application_helper.rb | 17 | ||||
-rw-r--r-- | app/helpers/queries_helper.rb | 2 | ||||
-rw-r--r-- | app/views/issues/index.html.erb | 1 | ||||
-rw-r--r-- | app/views/projects/_list.html.erb | 1 | ||||
-rw-r--r-- | app/views/reports/_details.html.erb | 1 | ||||
-rw-r--r-- | app/views/roles/permissions.html.erb | 1 | ||||
-rw-r--r-- | app/views/timelog/index.html.erb | 1 | ||||
-rw-r--r-- | app/views/timelog/report.html.erb | 1 | ||||
-rw-r--r-- | app/views/users/index.html.erb | 1 | ||||
-rw-r--r-- | lib/redmine/export/csv.rb | 2 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 14 | ||||
-rw-r--r-- | test/unit/lib/redmine/export/csv_test.rb | 16 |
12 files changed, 56 insertions, 2 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3177d0eb7..a1d989e25 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 = {} diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 662e22ee8..b90f86457 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -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 diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 3e0d0cfe8..997a64e55 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -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 %> diff --git a/app/views/projects/_list.html.erb b/app/views/projects/_list.html.erb index 4c592247c..1bc8d4687 100644 --- a/app/views/projects/_list.html.erb +++ b/app/views/projects/_list.html.erb @@ -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);" %> diff --git a/app/views/reports/_details.html.erb b/app/views/reports/_details.html.erb index 0bfb0f8f2..ab660bc16 100644 --- a/app/views/reports/_details.html.erb +++ b/app/views/reports/_details.html.erb @@ -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);' %> diff --git a/app/views/roles/permissions.html.erb b/app/views/roles/permissions.html.erb index d91dd933d..b70e2109b 100644 --- a/app/views/roles/permissions.html.erb +++ b/app/views/roles/permissions.html.erb @@ -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);' %> diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index e957b41b3..a045e4743 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -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);" %> diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb index ee6f0f83b..e0e80cd0e 100644 --- a/app/views/timelog/report.html.erb +++ b/app/views/timelog/report.html.erb @@ -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' %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index f5c8a1cd1..d609bfd78 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -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);" %> diff --git a/lib/redmine/export/csv.rb b/lib/redmine/export/csv.rb index 785698657..c55546347 100644 --- a/lib/redmine/export/csv.rb +++ b/lib/redmine/export/csv.rb @@ -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 = diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index a9e3b3a74..180066b17 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -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 diff --git a/test/unit/lib/redmine/export/csv_test.rb b/test/unit/lib/redmine/export/csv_test.rb index cebcb2db3..bdb0e38fc 100644 --- a/test/unit/lib/redmine/export/csv_test.rb +++ b/test/unit/lib/redmine/export/csv_test.rb @@ -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 |