tallty_import_export 1.0.22 → 1.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -31
- data/lib/tallty_import_export/export.rb +25 -8
- data/lib/tallty_import_export/import.rb +7 -3
- data/lib/tallty_import_export/version.rb +1 -1
- 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: 97dc753652b3c88b46d47c337cb8efacd3b225d464a9fcedb6ec9addb99a1656
|
4
|
+
data.tar.gz: c918a6587726e31a4855f56384708e6d94235f015c08e68e295870731266fb9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a614d1219e135cbedde925238313c0b5b256166df53e0633151674e3dc50ec4b15552582c11707db24cefcf6e989b9301a562288ae58d87d8df2a2e17caf8208
|
7
|
+
data.tar.gz: 47db4f8d0ca88bac82d5398bd9987ee991393bc9103067754e53995ecc82155e4b52a8b298ce8d85b7568633a0baff6d7524baeb470f097992c28b4291fde143
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tallty_import_export (
|
4
|
+
tallty_import_export (1.0.24)
|
5
5
|
activesupport
|
6
6
|
caxlsx
|
7
7
|
redis
|
@@ -14,33 +14,35 @@ PATH
|
|
14
14
|
GEM
|
15
15
|
remote: https://gems.ruby-china.com/
|
16
16
|
specs:
|
17
|
-
activemodel (6.
|
18
|
-
activesupport (= 6.
|
19
|
-
activesupport (6.
|
17
|
+
activemodel (6.1.4.1)
|
18
|
+
activesupport (= 6.1.4.1)
|
19
|
+
activesupport (6.1.4.1)
|
20
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
-
i18n (>=
|
22
|
-
minitest (
|
23
|
-
tzinfo (~>
|
24
|
-
zeitwerk (~> 2.
|
25
|
-
caxlsx (3.
|
21
|
+
i18n (>= 1.6, < 2)
|
22
|
+
minitest (>= 5.1)
|
23
|
+
tzinfo (~> 2.0)
|
24
|
+
zeitwerk (~> 2.3)
|
25
|
+
caxlsx (3.1.1)
|
26
26
|
htmlentities (~> 4.3, >= 4.3.4)
|
27
|
-
|
27
|
+
marcel (~> 1.0)
|
28
28
|
nokogiri (~> 1.10, >= 1.10.4)
|
29
29
|
rubyzip (>= 1.3.0, < 3)
|
30
|
-
concurrent-ruby (1.1.
|
30
|
+
concurrent-ruby (1.1.9)
|
31
31
|
diff-lcs (1.4.4)
|
32
32
|
htmlentities (4.3.4)
|
33
|
-
i18n (1.8.
|
33
|
+
i18n (1.8.10)
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
|
-
|
36
|
-
mini_portile2 (2.
|
37
|
-
minitest (5.14.
|
38
|
-
nokogiri (1.
|
39
|
-
mini_portile2 (~> 2.
|
35
|
+
marcel (1.0.2)
|
36
|
+
mini_portile2 (2.6.1)
|
37
|
+
minitest (5.14.4)
|
38
|
+
nokogiri (1.12.4)
|
39
|
+
mini_portile2 (~> 2.6.1)
|
40
|
+
racc (~> 1.4)
|
41
|
+
racc (1.5.2)
|
40
42
|
rake (12.3.3)
|
41
|
-
redis (4.
|
42
|
-
redis-objects (1.5.
|
43
|
-
redis (~> 4.
|
43
|
+
redis (4.4.0)
|
44
|
+
redis-objects (1.5.1)
|
45
|
+
redis (~> 4.2)
|
44
46
|
roo (2.8.3)
|
45
47
|
nokogiri (~> 1)
|
46
48
|
rubyzip (>= 1.3.0, < 3.0.0)
|
@@ -62,18 +64,17 @@ GEM
|
|
62
64
|
rspec-support (~> 3.10.0)
|
63
65
|
rspec-support (3.10.0)
|
64
66
|
ruby-ole (1.2.12.2)
|
65
|
-
rubyzip (2.3.
|
66
|
-
spreadsheet (1.
|
67
|
-
ruby-ole
|
68
|
-
tallty_duck_record (1.
|
69
|
-
activemodel (
|
70
|
-
activesupport (
|
67
|
+
rubyzip (2.3.2)
|
68
|
+
spreadsheet (1.3.0)
|
69
|
+
ruby-ole
|
70
|
+
tallty_duck_record (1.1.3)
|
71
|
+
activemodel (>= 5.0)
|
72
|
+
activesupport (>= 5.0)
|
71
73
|
tallty_form (1.0.0)
|
72
74
|
tallty_duck_record
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
zeitwerk (2.4.1)
|
75
|
+
tzinfo (2.0.4)
|
76
|
+
concurrent-ruby (~> 1.0)
|
77
|
+
zeitwerk (2.4.2)
|
77
78
|
zip-zip (0.3)
|
78
79
|
rubyzip (>= 1.0.0)
|
79
80
|
|
@@ -86,4 +87,4 @@ DEPENDENCIES
|
|
86
87
|
tallty_import_export!
|
87
88
|
|
88
89
|
BUNDLED WITH
|
89
|
-
2.
|
90
|
+
2.2.15
|
@@ -27,6 +27,7 @@ module TalltyImportExport
|
|
27
27
|
# index: 数组方式,需要嵌套拿到里面的
|
28
28
|
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
|
29
29
|
# json: model_payload,代表存储在某一个列中
|
30
|
+
# select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
|
30
31
|
|
31
32
|
def export_xlsx records, **options
|
32
33
|
records = with_scope records
|
@@ -79,17 +80,17 @@ module TalltyImportExport
|
|
79
80
|
if respond_to?(:first_header)
|
80
81
|
row_index = Axlsx.col_ref(headers.size - 1)
|
81
82
|
sheet.merge_cells("A1:#{row_index}1")
|
82
|
-
sheet.add_row [first_header], style: title1, height:
|
83
|
+
sheet.add_row [first_header], style: title1, height: 30
|
83
84
|
end
|
84
85
|
|
85
|
-
sheet.add_row headers.map{|header| header[:name]}, style: title2, height:
|
86
|
+
sheet.add_row headers.map{|header| header[:name]}, style: title2, height: 25
|
86
87
|
|
87
88
|
last_row = nil
|
88
89
|
merge_column_hash = {}
|
89
90
|
first_content_row_index = respond_to?(:first_header) ? 2 : 1
|
90
91
|
|
91
|
-
each_method =
|
92
|
-
records.
|
92
|
+
each_method = @each_method || :each
|
93
|
+
records.try_method(each_method).with_index do |record, index|
|
93
94
|
row = []
|
94
95
|
headers.each_with_index do |header, col_index|
|
95
96
|
_data = handle_data(record, header, index)
|
@@ -122,15 +123,21 @@ module TalltyImportExport
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
126
|
+
# 地处整体配置信息
|
127
|
+
def export_options
|
128
|
+
{}
|
129
|
+
end
|
130
|
+
|
125
131
|
def process_options options = {}
|
126
|
-
options = options.with_indifferent_access
|
132
|
+
options = export_options.merge(options).with_indifferent_access
|
127
133
|
|
128
|
-
@row_height ||= options.delete(:row_height) ||
|
134
|
+
@row_height ||= options.delete(:row_height) || 25
|
129
135
|
@width ||= (options.delete(:width) || 20).to_f
|
130
136
|
@filename ||= options.delete(:filename)
|
131
137
|
@group_by ||= options.delete(:group_by)
|
132
138
|
@group_where = "#{@group_by}_eq" if @group_by.present?
|
133
139
|
@headers ||= options.delete(:headers)
|
140
|
+
@each_method ||= options.delete(:each_method)
|
134
141
|
end
|
135
142
|
|
136
143
|
def with_scope records
|
@@ -138,7 +145,7 @@ module TalltyImportExport
|
|
138
145
|
end
|
139
146
|
|
140
147
|
def export_headers_result
|
141
|
-
@headers
|
148
|
+
@headers ||= export_headers&.with_indifferent_access
|
142
149
|
end
|
143
150
|
|
144
151
|
def export_headers **args
|
@@ -159,7 +166,8 @@ module TalltyImportExport
|
|
159
166
|
else
|
160
167
|
try_method(record, header[:key])
|
161
168
|
end
|
162
|
-
|
169
|
+
data = handle_format(data, header)
|
170
|
+
data = handle_select(data, header)
|
163
171
|
rescue
|
164
172
|
''
|
165
173
|
end
|
@@ -186,5 +194,14 @@ module TalltyImportExport
|
|
186
194
|
data
|
187
195
|
end
|
188
196
|
end
|
197
|
+
|
198
|
+
def handle_select data, header
|
199
|
+
if header[:select].present?
|
200
|
+
select_option = header[:select].find { |option| option[:value].to_s == data.to_s }
|
201
|
+
select_option.present? ? select_option[:label] : data
|
202
|
+
else
|
203
|
+
data
|
204
|
+
end
|
205
|
+
end
|
189
206
|
end
|
190
207
|
end
|
@@ -51,7 +51,7 @@ module TalltyImportExport
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def process_options options
|
54
|
-
options = options.with_indifferent_access
|
54
|
+
options = import_options.merge(options).with_indifferent_access
|
55
55
|
@headers = options.delete(:headers) || import_headers
|
56
56
|
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
57
57
|
@params = options
|
@@ -89,7 +89,7 @@ module TalltyImportExport
|
|
89
89
|
h[header[:json]] ||= {}
|
90
90
|
h[header[:json]][k] = val
|
91
91
|
elsif header[:finder]
|
92
|
-
$SAFE = 2
|
92
|
+
# $SAFE = 2
|
93
93
|
h[k.to_sym] = eval header[:finder]
|
94
94
|
else
|
95
95
|
h[k.to_sym] = val
|
@@ -104,7 +104,11 @@ module TalltyImportExport
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def import_headers_result
|
107
|
-
@headers ||= import_headers
|
107
|
+
@headers ||= import_headers&.with_indifferent_access
|
108
|
+
end
|
109
|
+
|
110
|
+
def import_options
|
111
|
+
{}
|
108
112
|
end
|
109
113
|
|
110
114
|
def import_headers **args
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallty_import_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|