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 +4 -4
- data/app/views/active_scaffold_overrides/_export.csv.erb +1 -1
- data/lib/active_scaffold/actions/export.rb +34 -29
- data/lib/active_scaffold/config/export.rb +1 -0
- data/lib/active_scaffold/helpers/export_helpers.rb +9 -12
- data/lib/active_scaffold_export/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b39cbb961c15eaa44301788a0fde3bdd54615acc8547d8c74604a5629f1768d
|
4
|
+
data.tar.gz: 62806e6733c7562294d7ef265be602e085e3bae56d0a6d4738e4336a21c340dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864b39ba6cb5855e0437b34dd211fb87e0317cc493c6e887ba7a6e523d1f48040e5e476cbeddf646a84de54846dcf43aa74879354f091d60758cbdd5180da756
|
7
|
+
data.tar.gz: 67f530f45b91f63eaa04bd31ad88022edf86e709caaf232bb96c57ab1f5f613e746ac08dc42a013b3dce3169a40c37ba78cbdc5062604751790f8abfc0a409f9
|
@@ -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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
@@ -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,
|
13
|
-
if export_column_override
|
14
|
-
send(
|
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
|
-
|
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
|
-
|
31
|
+
override_helper column, 'export_column'
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
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
|
-
|
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)
|
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.
|
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-
|
13
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: active_scaffold
|