Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tallty_import_export
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
tallty_import_export
Commits
f1a33c17
Commit
f1a33c17
authored
Apr 30, 2022
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
todo: 增加export payload
parent
84d0fe6e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
1 deletion
+88
-1
tallty_import_export.rb
lib/tallty_import_export.rb
+1
-0
export_header.rb
lib/tallty_import_export/attr/export_header.rb
+28
-1
export_payload.rb
lib/tallty_import_export/export_payload.rb
+59
-0
No files found.
lib/tallty_import_export.rb
View file @
f1a33c17
...
@@ -17,6 +17,7 @@ module TalltyImportExport
...
@@ -17,6 +17,7 @@ module TalltyImportExport
autoload
:FormConvert
autoload
:FormConvert
autoload
:Excel
autoload
:Excel
autoload
:Attr
autoload
:Attr
autoload
:ExportPayload
class
Error
<
StandardError
;
end
class
Error
<
StandardError
;
end
...
...
lib/tallty_import_export/attr/export_header.rb
View file @
f1a33c17
...
@@ -15,7 +15,22 @@ module TalltyImportExport
...
@@ -15,7 +15,22 @@ module TalltyImportExport
attr_json
:select
,
ActiveModel
::
Type
::
Value
.
new
,
array:
true
attr_json
:select
,
ActiveModel
::
Type
::
Value
.
new
,
array:
true
attr_json
:source
,
:boolean
attr_json
:source
,
:boolean
attr_json
:proc
,
ActiveModel
::
Type
::
Value
.
new
,
array:
true
attr_json
:proc
,
ActiveModel
::
Type
::
Value
.
new
,
array:
true
attr_json
:list
,
self
.
to_type
,
array:
true
attr_json
:children
,
self
.
to_type
,
array:
true
def
depth
children
&
.
count
.
to_i
+
1
end
# 取叶子结点,获取到excel表格的宽度
def
leaves
if
children
.
present?
children
.
flat_map
do
|
child
|
child
.
leaves
end
else
[
self
]
end
end
end
end
class
ExportHeader
class
ExportHeader
...
@@ -23,6 +38,18 @@ module TalltyImportExport
...
@@ -23,6 +38,18 @@ module TalltyImportExport
attr_json_config
(
bad_cast: :as_nil
,
unknown_key: :allow
)
attr_json_config
(
bad_cast: :as_nil
,
unknown_key: :allow
)
attr_json
:items
,
ExportHeaderItem
.
to_type
,
array:
true
attr_json
:items
,
ExportHeaderItem
.
to_type
,
array:
true
def
depth
items
.
map
(
&
:depth
).
max
end
# def height payload
# items.map do |item|
# TalltyImportExport::ExportPayload.new(header: item, payload: payload[item.key])
# end.map do |export_payload|
# export_payload.height
# end.max
# end
end
end
end
end
end
end
lib/tallty_import_export/export_payload.rb
0 → 100644
View file @
f1a33c17
class
TalltyImportExport
::
ExportPayload
# header: 导出时候使用的配置模型
# payload: 对应的单行数据抽取,如果是list属性,则payload是一个array
attr_accessor
:header
,
:payload
,
:children
,
:parent
def
initialize
(
header
:,
payload
:,
parent:
nil
,
children:
[])
@header
=
header
@payload
=
payload
@children
=
[]
@parent
=
parent
# 递归生成
if
header
.
is_a?
(
TalltyImportExport
::
Attr
::
ExportHeader
)
@children
=
header
.
items
.
map
do
|
header_item
|
self
.
class
.
new
(
header:
header_item
,
payload:
payload_value
(
header:
header_item
,
payload:
payload
),
parent:
self
)
end
else
if
header
.
children
.
present?
@children
=
header
.
children
.
map
do
|
header_item
|
self
.
class
.
new
(
header:
header_item
,
payload:
payload_value
(
header:
header_item
,
payload:
payload
),
parent:
self
)
end
end
end
end
def
height
return
0
if
payload
.
blank?
if
header
.
children
.
blank?
# 单属性,如果有值,为1,没有值为0
payload
.
present?
?
1
:
0
else
# list属性,payload是array
# 高度是表格里所有属性的height的最大值
children_height_arr
=
header
.
children
.
map
do
|
header_child
|
Array
(
payload
).
map
do
|
payload_child
|
self
.
class
.
new
(
header:
header_child
,
payload:
payload_value
(
header:
header_child
,
payload:
payload_child
),
).
height
end
.
sum
end
.
max
end
end
# TODO 获取值的方法
def
payload_value
header
:,
payload:
payload
&
.
dig
(
header
.
key
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment