active_scaffold_export 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27bb01b27b1106e740763ee7c02e9d3deb1df2afb70a8ecccded8fa87c229496
4
- data.tar.gz: 37cb223e2a416d8560f5727d03884f29591d8200b7bbde0fbb0147fe5038cab4
3
+ metadata.gz: 1b39cbb961c15eaa44301788a0fde3bdd54615acc8547d8c74604a5629f1768d
4
+ data.tar.gz: 62806e6733c7562294d7ef265be602e085e3bae56d0a6d4738e4336a21c340dd
5
5
  SHA512:
6
- metadata.gz: c30862703c29a5703f994b8793eadc49b4a8a6d21f05618679a31bc0f3f7e3a870c1d5fa2f38a72c3c56fd78d3be7ec42029099ad975cae935761accf56c39a0
7
- data.tar.gz: 00f36259a4cf5876a678638560105991e139e5d289f3e4b9d5e00a65aaa0ebd50a00b41b92e3d19cc4ab8a3aa9b8d086b753aa8a7892137a9e88a9dc79a1e7a2
6
+ metadata.gz: 864b39ba6cb5855e0437b34dd211fb87e0317cc493c6e887ba7a6e523d1f48040e5e476cbeddf646a84de54846dcf43aa74879354f091d60758cbdd5180da756
7
+ data.tar.gz: 67f530f45b91f63eaa04bd31ad88022edf86e709caaf232bb96c57ab1f5f613e746ac08dc42a013b3dce3169a40c37ba78cbdc5062604751790f8abfc0a409f9
@@ -12,7 +12,7 @@
12
12
  csv << fcsv_options[:headers] unless params[:skip_header] == 'true'
13
13
  @records.each do |record|
14
14
  csv << @export_columns.collect { |column|
15
- get_export_column_value(record, column)
15
+ get_export_column_value(record, column, :csv)
16
16
  }
17
17
  end
18
18
  end
@@ -53,41 +53,42 @@ module ActiveScaffold::Actions
53
53
  Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
54
54
  end
55
55
 
56
- respond_to do |format|
57
- format.csv do
58
- response.headers['Content-type'] = 'text/csv'
59
- # start streaming output
60
- self.response_body = Enumerator.new do |y|
61
- find_items_for_export do |records|
62
- @records = records
63
- str = render_to_string :partial => 'export', :layout => false, :formats => [:csv]
64
- y << str
65
- params[:skip_header] = 'true' # skip header on the next run
66
- end
67
- end
56
+ respond_to_action(:export)
57
+ end
58
+
59
+ protected
60
+
61
+ def export_respond_to_csv
62
+ response.headers['Content-type'] = 'text/csv'
63
+ # start streaming output
64
+ self.response_body = Enumerator.new do |y|
65
+ find_items_for_export do |records|
66
+ @records = records
67
+ str = render_to_string :partial => 'export', :layout => false, :formats => [:csv]
68
+ y << str
69
+ params[:skip_header] = 'true' # skip header on the next run
68
70
  end
69
- format.xlsx do
70
- response.headers['Content-type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
71
- p = Axlsx::Package.new
72
- header = p.workbook.styles.add_style sz: 11, b: true,:bg_color => "69B5EF", :fg_color => "FF", alignment: { horizontal: :center }
73
- p.workbook.add_worksheet(name: active_scaffold_config.label) do |sheet|
74
- sheet.add_row(@export_columns.collect { |column| view_context.format_export_column_header_name(column) }, style: header) unless params[:skip_header]
75
- find_items_for_export do |records|
76
- records.each do |record|
77
- sheet.add_row @export_columns.collect { |column| view_context.get_export_column_value(record, column, false) }
78
- end
79
- end
80
- end
81
- stream = p.to_stream # when adding rows to sheet, they won't pass to this stream if declared before. axlsx issue?
82
- self.response_body = Enumerator.new do |y|
83
- y << stream.read
71
+ end
72
+ end
73
+
74
+ def export_respond_to_xlsx
75
+ response.headers['Content-type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
76
+ pkg = Axlsx::Package.new
77
+ header = pkg.workbook.styles.add_style sz: 11, b: true,:bg_color => "69B5EF", :fg_color => "FF", alignment: { horizontal: :center }
78
+ pkg.workbook.add_worksheet(name: active_scaffold_config.label) do |sheet|
79
+ sheet.add_row(@export_columns.collect { |column| view_context.format_export_column_header_name(column) }, style: header) unless params[:skip_header]
80
+ find_items_for_export do |records|
81
+ records.each do |record|
82
+ sheet.add_row @export_columns.collect { |column| view_context.get_export_column_value(record, column, :xlsx) }
84
83
  end
85
84
  end
86
-
85
+ end
86
+ stream = pkg.to_stream # when adding rows to sheet, they won't pass to this stream if declared before. axlsx issue?
87
+ self.response_body = Enumerator.new do |y|
88
+ y << stream.read
87
89
  end
88
90
  end
89
91
 
90
- protected
91
92
  def export_columns
92
93
  return @export_columns if defined? @export_columns
93
94
  @export_columns = active_scaffold_config.export.columns.reject { |col| params[:export_columns][col.to_sym].nil? }
@@ -154,5 +155,9 @@ module ActiveScaffold::Actions
154
155
  export_authorized?
155
156
  end
156
157
 
158
+ def export_formats
159
+ active_scaffold_config.export.formats
160
+ end
161
+
157
162
  end
158
163
  end
@@ -4,6 +4,7 @@ module ActiveScaffold::Config
4
4
 
5
5
  def initialize(core_config)
6
6
  @core = core_config
7
+ @formats = [:csv, :xlsx]
7
8
  end
8
9
 
9
10
  # global level configuration
@@ -9,14 +9,14 @@ module ActiveScaffold
9
9
  # format_export_column(raw_value)
10
10
  # format_singular_association_export_column(association_record)
11
11
  # format_plural_association_export_column(association_records)
12
- def get_export_column_value(record, column, csv = true)
13
- if export_column_override? column
14
- send(export_column_override(column), record)
12
+ def get_export_column_value(record, column, format)
13
+ if (method = export_column_override(column))
14
+ send(method, record)
15
15
  else
16
16
  raw_value = record.send(column.name)
17
17
 
18
18
  if column.association.nil? or column_empty?(raw_value)
19
- csv ? format_export_column(raw_value) : raw_value # xlsx needs original data type
19
+ format_export_column(raw_value, format)
20
20
  elsif column.association
21
21
  if column.association.collection?
22
22
  format_plural_association_export_column(raw_value)
@@ -28,19 +28,16 @@ module ActiveScaffold
28
28
  end
29
29
 
30
30
  def export_column_override(column)
31
- "#{column.name.to_s.gsub('?', '')}_export_column" # parse out any question marks (see issue 227)
31
+ override_helper column, 'export_column'
32
32
  end
33
33
 
34
- def export_column_override?(column)
35
- respond_to?(export_column_override(column))
36
- end
37
-
38
- def format_export_column(raw_value)
39
- format_value_for_csv(raw_value)
34
+ def format_export_column(raw_value, format)
35
+ method = "format_value_for_#{format}"
36
+ respond_to?(method) ? send(method, raw_value) : raw_value
40
37
  end
41
38
 
42
39
  def format_value_for_csv(column_value)
43
- value = if column_empty?(column_value)
40
+ if column_empty?(column_value)
44
41
  active_scaffold_config.list.empty_field_text
45
42
  elsif column_value.is_a?(Time) || column_value.is_a?(Date)
46
43
  l(column_value, :format => :default)
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldExport
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 5
5
- PATCH = 1
4
+ MINOR = 6
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.5.1
4
+ version: 3.6.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-04-05 00:00:00.000000000 Z
13
+ date: 2024-04-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_scaffold