active_scaffold_export 3.8.1 → 3.10.0

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: a405407d5f6c1a7de0d857efbb777c85e6ef41ae95f15e1733578d2beeacac7e
4
- data.tar.gz: 81603f42c9f23e4229f073ee36ef6fa149ab8b1871483d28aff5e512f95a6daf
3
+ metadata.gz: '028314bd560c02524ab75e89fa886e1e6aa4e547fc2d897586ce8f512a33abb5'
4
+ data.tar.gz: 34b28d3afa5cc307d9728f59ea4a1b9e69ecd4fa66d27f3529d2e81da47801bc
5
5
  SHA512:
6
- metadata.gz: ba855f054a8c886d2c0e8cec19c514acc74d7e2867a546b94d3f672982f74f53a37275c53b74abd399e33cf6f57028e78cf29a534ecb5ac223a557f195c59f2d
7
- data.tar.gz: 359fbfa1916a68976b67acd77b8d9d9c97b4f0b013786161412c02f9e726d440b5c3280567d9b2e294afae6676dafeddb21106f3b66cc9bf9976cdd1064e9f3b
6
+ metadata.gz: f73011a115e19299e76b45eebc6abaa485ac3a86e57db94c3c96902ebe8fbc828f1e506de388a44791a671fc9018c88b6736f904bfe462804734ddff002b1689
7
+ data.tar.gz: d2f05275d642ea686552a01f29484ad108e2e16e18c0e1bb0e7ce66b33b3aee44adb2f2cf4c69d3f56d0b3436cb544ffdb67436cc3d967cf40f91095eda3f3ab
data/README.md CHANGED
@@ -7,21 +7,19 @@ Then, add this to your Gemfile:
7
7
  ```
8
8
  gem 'active_scaffold_export'
9
9
  ```
10
- if you're using REE or Ruby 1.8.7, you need to add backports gem as well as fastercsv since REE lacks ruby 1.9 streaming features and fastercsv is in core in 1.9
11
- ```
12
- gem 'backports'
13
- gem 'fastercsv'
14
- ```
15
- if you want xlsx format, add:
10
+
11
+ If you want xlsx format, add:
16
12
  ```
17
13
  gem 'caxlsx_rails'
18
14
  ```
19
- if that gem is present, XLSX will be used by default.
15
+
16
+ If that gem is present, XLSX will be used by default.
20
17
  You can change this by adding to active scaffold config:
21
18
  ```
22
19
  conf.export.default_file_format = 'csv' # or 'xlsx'
23
20
  ```
24
- read important notes at the bottom about xlsx.
21
+
22
+ Read important notes at the bottom about xlsx.
25
23
 
26
24
  Remember to bundle install.
27
25
  Add to application.css:
@@ -1,14 +1,16 @@
1
1
  <% export_config = active_scaffold_config.export %>
2
2
  <h3><%=as_(:columns_for_export)%></h3>
3
- <% if ActiveScaffold.js_framework == :jquery # TODO: use JS asset instead of inline JS %>
3
+ <%# TODO: use JS asset instead of inline JS %>
4
4
  <%= link_to as_(:select_all), '#', onclick: 'jQuery(".columnCheckbox").prop("checked", true); return false', class: 'active-scaffold-footer' %>
5
5
  |
6
6
  <%= link_to as_(:select_none), '#', onclick: 'jQuery(".columnCheckbox").prop("checked", false); return false', class: 'active-scaffold-footer' %>
7
- <% end %>
8
7
  <div class="columns checkbox-list">
9
- <% export_config.columns.each_column do |column| -%>
8
+ <% export_columns_names(true).each_column do |column| -%>
10
9
  <div class="column checkbox-wrapper">
11
- <%= 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>
12
14
  </div>
13
15
  <% end -%>
14
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,21 +34,22 @@ 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
44
+ @page = find_page(find_options_for_export)
43
45
 
44
46
  # this is required if you want this to work with IE
45
47
  if request.env['HTTP_USER_AGENT'] =~ /msie/i
46
- response.headers['Pragma'] = "public"
47
- response.headers['Cache-Control'] = "no-cache, must-revalidate, post-check=0, pre-check=0"
48
- response.headers['Expires'] = "0"
48
+ response.headers['pragma'] = "public"
49
+ response.headers['cache-control'] = "no-cache, must-revalidate, post-check=0, pre-check=0"
50
+ response.headers['expires'] = "0"
49
51
  end
50
- response.headers['Content-Disposition'] = "attachment; filename=#{export_file_name}"
52
+ response.headers['content-disposition'] = "attachment; filename=#{export_file_name}"
51
53
 
52
54
  respond_to_action(:export)
53
55
  end
@@ -55,7 +57,8 @@ module ActiveScaffold::Actions
55
57
  protected
56
58
 
57
59
  def export_respond_to_csv
58
- response.headers['Content-type'] = Mime[:csv]
60
+ response.headers['content-type'] = Mime[:csv]
61
+ response.headers['last-modified'] = '0'
59
62
  # start streaming output
60
63
  self.response_body = Enumerator.new do |y|
61
64
  find_items_for_export do |records|
@@ -68,7 +71,8 @@ module ActiveScaffold::Actions
68
71
  end
69
72
 
70
73
  def export_respond_to_xlsx
71
- response.headers['Content-type'] = Mime[:xlsx]
74
+ response.headers['content-type'] = Mime[:xlsx]
75
+ response.headers['last-modified'] = '0'
72
76
  pkg = Axlsx::Package.new
73
77
  pkg.workbook.add_worksheet(name: worksheet_name) do |sheet|
74
78
  styles = @export_columns.collect { |column| view_context.export_column_header_style(column, :xlsx) }
@@ -109,39 +113,47 @@ module ActiveScaffold::Actions
109
113
 
110
114
  def export_columns
111
115
  return @export_columns if defined? @export_columns
112
- @export_columns = active_scaffold_config.export.columns.reject { |col| params[:export_columns][col.to_sym].nil? }
116
+ @export_columns = export_columns_names.reject { |col| params[:export_columns][col.to_sym].nil? }
113
117
  sorting = active_scaffold_config.list.user.sorting || active_scaffold_config.list.sorting
114
118
  sorting_columns = sorting.reject { |col, _| @export_columns.include?(col.name) }.map(&:first)
115
119
  @export_columns.map! { |col| active_scaffold_config.columns[col] }
116
120
  @export_columns += sorting_columns
117
121
  end
118
122
 
119
- # The actual algorithm to do the export
120
- def find_items_for_export(&block)
121
- find_options = { :sorting =>
122
- active_scaffold_config.list.user.sorting.nil? ?
123
- active_scaffold_config.list.sorting : active_scaffold_config.list.user.sorting,
124
- :pagination => true
125
- }
123
+ def export_columns_names(action_columns = false)
124
+ if grouped_search?
125
+ list_columns_names.then do |cols|
126
+ action_columns ? active_scaffold_config.build_action_columns(:export, cols) : cols
127
+ end
128
+ else
129
+ active_scaffold_config.export.columns
130
+ end
131
+ end
132
+
133
+ def find_options_for_export
134
+ find_options = {sorting: active_scaffold_config.list.sorting, pagination: true}
126
135
  do_search rescue nil
127
- params[:segment_id] = session[:segment_id]
128
- do_segment_search rescue nil
129
136
 
130
137
  if params[:full_download] == 'true'
131
- find_options.merge!({
132
- :per_page => 3000,
133
- :page => 1
134
- })
135
- find_page(find_options).pager.each do |page|
138
+ find_options.merge!(per_page: 3000, page: 1)
139
+ else
140
+ find_options.merge!(
141
+ pagination: active_scaffold_config.list.pagination,
142
+ per_page: active_scaffold_config.list.user.per_page,
143
+ page: active_scaffold_config.list.user.page
144
+ )
145
+ end
146
+ find_options
147
+ end
148
+
149
+ # The actual algorithm to do the export
150
+ def find_items_for_export(&block)
151
+ if params[:full_download] == 'true'
152
+ @page.pager.each do |page|
136
153
  yield page.items
137
154
  end
138
155
  else
139
- find_options.merge!({
140
- :pagination => active_scaffold_config.list.pagination,
141
- :per_page => active_scaffold_config.list.user.per_page,
142
- :page => active_scaffold_config.list.user.page
143
- })
144
- yield find_page(find_options).items
156
+ yield @page.items
145
157
  end
146
158
  end
147
159
 
@@ -95,7 +95,7 @@ module ActiveScaffold::Config
95
95
  end
96
96
 
97
97
  def default_deselected_columns
98
- self.default_deselected_columns = ActiveScaffold::DataStructures::Set.new if @default_deselected_columns.nil?
98
+ @default_deselected_columns ||= ActiveScaffold::DataStructures::Set.new unless frozen?
99
99
  @default_deselected_columns
100
100
  end
101
101
 
@@ -104,5 +104,21 @@ module ActiveScaffold::Config
104
104
  def multipart?
105
105
  false
106
106
  end
107
+
108
+ UserSettings.class_eval do
109
+ user_attr :show_form, :allow_full_download, :force_quotes, :default_file_format,
110
+ :default_delimiter, :default_skip_header, :default_file_format
111
+
112
+ def default_deselected_columns=(val)
113
+ @default_deselected_columns = ActiveScaffold::DataStructures::Set.new(*val)
114
+ end
115
+
116
+ def default_deselected_columns
117
+ if @default_deselected_columns.nil? && @conf.default_deselected_columns
118
+ return @conf.default_deselected_columns
119
+ end
120
+ @default_deselected_columns ||= ActiveScaffold::DataStructures::Set.new
121
+ end
122
+ end
107
123
  end
108
124
  end
@@ -12,10 +12,12 @@ module ActiveScaffold
12
12
  def get_export_column_value(record, column, format)
13
13
  if (method = export_column_override(column))
14
14
  value, options = send(method, record, format)
15
- [value, options || column.export_options&.dig(format)]
15
+ [value, options || export_column_style(column, format)]
16
16
  elsif column.list_ui && (method = override_export_ui(column.list_ui))
17
17
  value, options = send(method, record, column, format, ui_options: column.list_ui_options || column.options)
18
- [value, options || column.export_options&.dig(format)]
18
+ [value, options || export_column_style(column, format)]
19
+ elsif grouped_search? && column == search_group_column && search_group_function
20
+ [format_grouped_search_column(record[column.name], column.options), export_column_style(column, format)]
19
21
  else
20
22
  raw_value = record.send(column.name)
21
23
 
@@ -29,12 +31,17 @@ module ActiveScaffold
29
31
  format_singular_association_export_column(raw_value, format)
30
32
  end
31
33
  end
32
- [value, column.export_options&.dig(format)]
34
+ [value, export_column_style(column, format)]
33
35
  end
34
36
  end
35
37
 
38
+ def export_column_style(column, format)
39
+ style = column.export_options&.dig(format)
40
+ format = :xlsx && style.frozen? ? style.deep_dup : style
41
+ end
42
+
36
43
  def export_column_override(column)
37
- override_helper column, 'export_column'
44
+ override_helper column, grouped_search? ? 'grouped_export_column' : 'export_column'
38
45
  end
39
46
 
40
47
  # the naming convention for overriding column types with helpers
@@ -76,7 +83,7 @@ module ActiveScaffold
76
83
  ## This helper can be overridden to change the name of the headers
77
84
  # For instance, you might want column.name.to_s.humanize
78
85
  def format_export_column_header_name(column)
79
- column.label
86
+ column_heading_label column
80
87
  end
81
88
 
82
89
  ## This helper can be overridden to change the style of the headers
@@ -1,5 +1,8 @@
1
1
  module ActiveScaffoldExport
2
2
  module Column
3
- attr_accessor :export_options
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ attr_accessor :export_options
6
+ end
4
7
  end
5
8
  end
@@ -15,6 +15,9 @@ module ActiveScaffoldExport
15
15
 
16
16
  initializer 'active_scaffold_export.extensions' do
17
17
  ActiveScaffold::DataStructures::Column.send :include, ActiveScaffoldExport::Column
18
+ if defined? ActiveScaffold::DataStructures::ProxyColumn
19
+ ActiveScaffold::DataStructures::ProxyColumn.send :include, ActiveScaffoldExport::Column
20
+ end
18
21
  end
19
22
  end
20
23
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldExport
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 8
5
- PATCH = 1
4
+ MINOR = 10
5
+ PATCH = 0
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.8.1
4
+ version: 3.10.0
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: 2024-09-18 00:00:00.000000000 Z
13
+ date: 2025-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_scaffold
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 3.7.1
21
+ version: 4.0.0.rc1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 3.7.1
28
+ version: 4.0.0.rc1
29
29
  description: Exporting Records with ActiveScaffold
30
30
  email: activescaffold@googlegroups.com
31
31
  executables: []
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.3
72
+ rubygems_version: 3.5.11
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Ability to export records to CSV/XLSX with ActiveScaffold