diff --git a/app/views/admin/reports/_rendering_options.html.haml b/app/views/admin/reports/_rendering_options.html.haml index dc8395f584..9da74a6a11 100644 --- a/app/views/admin/reports/_rendering_options.html.haml +++ b/app/views/admin/reports/_rendering_options.html.haml @@ -17,6 +17,13 @@ = check_box_tag :display_summary_row, true, params[:display_summary_row] = label_tag :display_summary_row, t(".summary_row") +- if @report.available_headers.present? + .row + .alpha.two.columns= label_tag nil, t(:report_hide_columns) + .omega.fourteen.columns + = select_tag(:fields_to_hide, options_for_select(@report.available_headers, params[:fields_to_hide]), + class: "select2 fullwidth", multiple: true) + .row.rendering-options .alpha.two.columns = label_tag :report_format, t(".generate_report") diff --git a/config/locales/en.yml b/config/locales/en.yml index 65f2d94efe..3b9088eb2b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2625,6 +2625,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_payment_totals: 'Payment Totals' report_all: 'all' report_order_cycle: "Order Cycle" + report_hide_columns: Columns to Hide report_enterprises: "Enterprises" report_enterprise_fee: "Fees Names" report_users: "Users" diff --git a/lib/reporting/report_grouper.rb b/lib/reporting/report_grouper.rb index 21cddf3108..4bdd8756c3 100644 --- a/lib/reporting/report_grouper.rb +++ b/lib/reporting/report_grouper.rb @@ -139,9 +139,7 @@ module Reporting end def slice_row_fields(row) - result = row.clone - report.fields_to_hide.each { |field| result.delete_field!(field) } - result + OpenStruct.new(row.to_h.reject { |k, _v| k.in?(report.fields_to_hide) }) end # Compute the query result item into a result row diff --git a/lib/reporting/report_template.rb b/lib/reporting/report_template.rb index 9ba56b9e5b..ff0f8d8b4f 100644 --- a/lib/reporting/report_template.rb +++ b/lib/reporting/report_template.rb @@ -28,11 +28,17 @@ module Reporting Ransack::Search.new(Spree::Order) end + def available_headers + columns.is_a?(Hash) ? columns.keys.map { |key| [translate_header(key), key] } : nil + rescue NotImplementedError + nil + end + # Can be re implemented in subclasses if they not use yet the new syntax # with columns method def table_headers columns.keys.filter{ |key| !key.in?(fields_to_hide) }.map do |key| - custom_headers[key] || I18n.t("report_header_#{key}") + translate_header(key) end end @@ -57,7 +63,11 @@ module Reporting formatted_rules.map { |rule| rule[:fields_used_in_header] }.flatten.reject(&:blank?) else [] - end + end.concat(params_fields_to_hide) + end + + def params_fields_to_hide + params[:fields_to_hide]&.map(&:to_sym) || [] end # Rules for grouping, ordering, and summary rows