From 6a7f2536b5562128f00ce0513d00350137986ad5 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 21 Oct 2023 06:19:13 +0000 Subject: [PATCH] Add field separator option to CSV export dialog (#37621). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Karel Pičman. git-svn-id: https://svn.redmine.org/redmine/trunk@22359 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 17 +++++++++++++++++ app/helpers/queries_helper.rb | 2 +- app/views/issues/index.html.erb | 1 + app/views/projects/_list.html.erb | 1 + app/views/reports/_details.html.erb | 1 + app/views/roles/permissions.html.erb | 1 + app/views/timelog/index.html.erb | 1 + app/views/timelog/report.html.erb | 1 + app/views/users/index.html.erb | 1 + lib/redmine/export/csv.rb | 2 +- test/helpers/application_helper_test.rb | 14 ++++++++++++++ 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 @@ <% end %> <%= export_csv_encoding_select_tag %> + <%= export_csv_separator_select_tag %> <% if @issue_count > Setting.issues_export_limit.to_i %>

<%= 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 @@

<%= export_csv_encoding_select_tag %> + <%= export_csv_separator_select_tag %>

<%= 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 @@

<%= l(:label_export_options, :export_format => 'CSV') %>

<%= 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 %>

<%= 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 @@

<%= l(:label_export_options, :export_format => 'CSV') %>

<%= form_tag(permissions_roles_path(:format => 'csv'), :method => :get, :id => 'csv-export-form') do %> <%= export_csv_encoding_select_tag %> + <%= export_csv_separator_select_tag %>

<%= 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 @@ <% end %> <%= export_csv_encoding_select_tag %> + <%= export_csv_separator_select_tag %>

<%= 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 @@