active_scaffold_export 3.9.3 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17a2384e4ea87f37820137c5a5b4d77263e1c897b286229ed4c1c3da0ee1a5cd
4
- data.tar.gz: 2b37e2b9b189725d3c3735d782d262a9d3df8e8f816a83dfe36a65545147da07
3
+ metadata.gz: 3129ecc7a827c1e0f9d4052d2661751d8ed18124dd041b616694b6b74edfc511
4
+ data.tar.gz: 03d88fa2f813a8b841aa64f5de94439d7c4392e30e729641dc2f46076741d35b
5
5
  SHA512:
6
- metadata.gz: aea5b9dd175581c8d730271cdb0067d7c7721c271ab57593a2c92de7bef9365356c923af7834d43b6d3adbc49b53135f79d5c22121223a560e1e59a1685036ea
7
- data.tar.gz: 07f93b89c04d65fcfbc5630a1bf932e0aab23e0772b90569d3cc495aa19b1304b23fdeb87394a73822080243ee5cdca285d70fe76554b108168211385526a144
6
+ metadata.gz: 50b9a7a2e813c0526da48a17c2dc72ed8ce72cdadc4618e30b832ba48a7913c94e211f34954c5c16e67b1b655a5b96d8b1219fa23d028420bb15b5f34e39d625
7
+ data.tar.gz: b45b8846a4ccae25bea17e4eda5573931f6346b913ff16029b09bac721b82f90c77911085b0e76133584ff6920160d97414be02394c0a191286fdab53623df01
data/README.md CHANGED
@@ -71,5 +71,11 @@ def worksheet_name(options = {})
71
71
  end
72
72
  ```
73
73
 
74
+ ### Grouped search
75
+
76
+ Export supports grouped search from field_search action. When grouped search is used, instead of exporting the normal columns, only the listed columns will be exported, the ones in `conf.list.columns` with calculation, or the ones in `conf.field_search.grouped_columns`. In this case, the normal helper overrides won't be used, and will use `grouped_export_column` suffix instead.
77
+
78
+ ## Contact
79
+
74
80
  For contact, help, support, comments, please use Active Scaffold official mailing list activescaffold@googlegroups.com
75
81
 
@@ -12,7 +12,7 @@
12
12
  csv << fcsv_options[:headers] unless params[:skip_header]
13
13
  @records.each do |record|
14
14
  csv << @export_columns.collect { |column|
15
- get_export_column_value(record, column, :csv).first
15
+ get_export_column_value(record, column, :csv)&.first
16
16
  }
17
17
  end
18
18
  end
@@ -5,9 +5,12 @@
5
5
  |
6
6
  <%= link_to as_(:select_none), '#', onclick: 'jQuery(".columnCheckbox").prop("checked", false); return false', class: 'active-scaffold-footer' %>
7
7
  <div class="columns checkbox-list">
8
- <% export_config.columns.each_column do |column| -%>
8
+ <% export_columns_names(true).each_column do |column| -%>
9
9
  <div class="column checkbox-wrapper">
10
- <%= content_tag(:label, check_box_tag("export_columns[#{column.name}]", 1, !export_config.default_deselected_columns.include?(column.name), :class => 'columnCheckbox') + "&nbsp;#{column.label}".html_safe) %>
10
+ <label>
11
+ <%= check_box_tag("export_columns[#{column.name}]", 1, !export_config.default_deselected_columns.include?(column.name), :class => 'columnCheckbox') %>
12
+ <%= column_heading_label(column) %>
13
+ </label>
11
14
  </div>
12
15
  <% end -%>
13
16
  &nbsp;
@@ -3,6 +3,7 @@ module ActiveScaffold::Actions
3
3
  def self.included(base)
4
4
  base.before_action :export_authorized?, :only => [:export]
5
5
  base.before_action :show_export_authorized?, :only => [:show_export]
6
+ base.helper_method :export_columns_names
6
7
  end
7
8
 
8
9
  # display the customization form or skip directly to export
@@ -23,7 +24,7 @@ module ActiveScaffold::Actions
23
24
  export_config = active_scaffold_config.export
24
25
  if params[:export_columns].nil?
25
26
  export_columns = {}
26
- export_config.columns.each { |col| export_columns[col.to_sym] = 1 }
27
+ export_columns_names.each { |col| export_columns[col.to_sym] = 1 }
27
28
  options = {
28
29
  :export_columns => export_columns,
29
30
  :full_download => export_config.default_full_download.to_s,
@@ -33,14 +34,14 @@ module ActiveScaffold::Actions
33
34
  params.merge!(options)
34
35
  end
35
36
 
36
- set_includes_for_columns(:export)
37
+ set_includes_for_columns(:export) # will call export_columns which will set @export_columns
37
38
  @export_config = export_config
38
39
  # Make sure active_scaffold's find_page is dealing with the same list of
39
40
  # columns. Prevents an invalid SQL query when exporting after filtering
40
41
  # with field_search against a relation column, and that relation column is
41
42
  # not included in the set of export columns.
42
43
  @list_columns = @export_columns
43
- @find_options = find_options_for_export
44
+ @page = find_page(find_options_for_export)
44
45
 
45
46
  # this is required if you want this to work with IE
46
47
  if request.env['HTTP_USER_AGENT'] =~ /msie/i
@@ -60,7 +61,7 @@ module ActiveScaffold::Actions
60
61
  response.headers['last-modified'] = '0'
61
62
  # start streaming output
62
63
  self.response_body = Enumerator.new do |y|
63
- find_items_for_export(@find_options) do |records|
64
+ find_items_for_export do |records|
64
65
  @records = records
65
66
  str = render_to_string :partial => 'export', :layout => false, :formats => [:csv]
66
67
  y << str
@@ -80,7 +81,7 @@ module ActiveScaffold::Actions
80
81
  styles.map! { |style| pkg.workbook.styles.add_style style if style }
81
82
  sheet.add_row(@export_columns.collect { |column| view_context.format_export_column_header_name(column) }, style: styles, widths: widths)
82
83
  end
83
- find_items_for_export(@find_options) do |records|
84
+ find_items_for_export do |records|
84
85
  records.each do |record|
85
86
  row = []
86
87
  styles = []
@@ -112,13 +113,26 @@ module ActiveScaffold::Actions
112
113
 
113
114
  def export_columns
114
115
  return @export_columns if defined? @export_columns
115
- @export_columns = active_scaffold_config.export.columns.reject { |col| params[:export_columns][col.to_sym].nil? }
116
+ @export_columns = export_columns_names.reject do |col|
117
+ params[:export_columns][col.to_sym].nil? ||
118
+ !active_scaffold_config.model.authorized_for?(crud_type: :read, column: col.to_sym)
119
+ end
116
120
  sorting = active_scaffold_config.list.user.sorting || active_scaffold_config.list.sorting
117
121
  sorting_columns = sorting.reject { |col, _| @export_columns.include?(col.name) }.map(&:first)
118
122
  @export_columns.map! { |col| active_scaffold_config.columns[col] }
119
123
  @export_columns += sorting_columns
120
124
  end
121
125
 
126
+ def export_columns_names(action_columns = false)
127
+ if grouped_search?
128
+ list_columns_names.then do |cols|
129
+ action_columns ? active_scaffold_config.build_action_columns(:export, cols) : cols
130
+ end
131
+ else
132
+ active_scaffold_config.export.columns
133
+ end
134
+ end
135
+
122
136
  def find_options_for_export
123
137
  find_options = {sorting: active_scaffold_config.list.sorting, pagination: true}
124
138
  do_search rescue nil
@@ -136,13 +150,13 @@ module ActiveScaffold::Actions
136
150
  end
137
151
 
138
152
  # The actual algorithm to do the export
139
- def find_items_for_export(find_options, &block)
153
+ def find_items_for_export(&block)
140
154
  if params[:full_download] == 'true'
141
- find_page(find_options).pager.each do |page|
155
+ @page.pager.each do |page|
142
156
  yield page.items
143
157
  end
144
158
  else
145
- yield find_page(find_options).items
159
+ yield @page.items
146
160
  end
147
161
  end
148
162
 
@@ -10,12 +10,15 @@ module ActiveScaffold
10
10
  # format_singular_association_export_column(association_record)
11
11
  # format_plural_association_export_column(association_records)
12
12
  def get_export_column_value(record, column, format)
13
+ return unless record.authorized_for?(crud_type: :read, column: column.name)
13
14
  if (method = export_column_override(column))
14
15
  value, options = send(method, record, format)
15
16
  [value, options || export_column_style(column, format)]
16
17
  elsif column.list_ui && (method = override_export_ui(column.list_ui))
17
18
  value, options = send(method, record, column, format, ui_options: column.list_ui_options || column.options)
18
19
  [value, options || export_column_style(column, format)]
20
+ elsif grouped_search? && column == search_group_column && search_group_function
21
+ [format_grouped_search_column(record[column.name], column.options), export_column_style(column, format)]
19
22
  else
20
23
  raw_value = record.send(column.name)
21
24
 
@@ -35,11 +38,11 @@ module ActiveScaffold
35
38
 
36
39
  def export_column_style(column, format)
37
40
  style = column.export_options&.dig(format)
38
- format = :xlsx && style.frozen? ? style.deep_dup : style
41
+ format == :xlsx && style.frozen? ? style.deep_dup : style
39
42
  end
40
43
 
41
44
  def export_column_override(column)
42
- override_helper column, 'export_column'
45
+ override_helper column, grouped_search? ? 'grouped_export_column' : 'export_column'
43
46
  end
44
47
 
45
48
  # the naming convention for overriding column types with helpers
@@ -81,7 +84,7 @@ module ActiveScaffold
81
84
  ## This helper can be overridden to change the name of the headers
82
85
  # For instance, you might want column.name.to_s.humanize
83
86
  def format_export_column_header_name(column)
84
- column.label
87
+ column_heading_label column
85
88
  end
86
89
 
87
90
  ## This helper can be overridden to change the style of the headers
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldExport
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 9
5
- PATCH = 3
4
+ MINOR = 10
5
+ PATCH = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.3
4
+ version: 3.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Hochstein
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-03-12 00:00:00.000000000 Z
13
+ date: 2025-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_scaffold