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
ffce6618
Commit
ffce6618
authored
Dec 18, 2021
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 根据导入和导出的headers,需要保证原来定义的顺序和配置项不被前端覆盖掉
parent
d882700f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
export.rb
lib/tallty_import_export/export.rb
+16
-3
import.rb
lib/tallty_import_export/import.rb
+6
-7
No files found.
lib/tallty_import_export/export.rb
View file @
ffce6618
module
TalltyImportExport
module
TalltyImportExport
class
Export
class
Export
attr_reader
:klass
attr_reader
:klass
,
:context
def
initialize
klass
def
initialize
klass
@klass
=
klass
@klass
=
klass
@context
=
Context
.
new
({})
end
end
# [
# [
...
@@ -150,6 +151,8 @@ module TalltyImportExport
...
@@ -150,6 +151,8 @@ module TalltyImportExport
@group_where
=
"
#{
@group_by
}
_eq"
if
@group_by
.
present?
@group_where
=
"
#{
@group_by
}
_eq"
if
@group_by
.
present?
@headers
||=
options
.
delete
(
:headers
)
@headers
||=
options
.
delete
(
:headers
)
@each_method
||=
options
.
delete
(
:each_method
)
@each_method
||=
options
.
delete
(
:each_method
)
@params
=
options
context
.
params
=
@params
end
end
def
with_scope
records
def
with_scope
records
...
@@ -157,7 +160,17 @@ module TalltyImportExport
...
@@ -157,7 +160,17 @@ module TalltyImportExport
end
end
def
export_headers_result
def
export_headers_result
@headers
||=
export_headers
if
@headers
.
present?
headers_hash
=
@headers
.
to_h
{
|
header
|
[
header
.
with_indifferent_access
[
:key
],
header
]
}.
with_indifferent_access
export_headers
.
select
do
|
_header
|
_header
.
with_indifferent_access
[
:key
].
to_s
.
in?
(
headers_hash
.
keys
)
end
.
map
do
|
_header
|
_header
.
with_indifferent_access!
_header
.
merge
(
headers_hash
[
_header
[
:key
]].
delete_if
{
|
k
,
v
|
v
.
blank?
})
end
else
@headers
=
export_headers
end
end
end
def
export_headers
**
args
def
export_headers
**
args
...
@@ -176,7 +189,7 @@ module TalltyImportExport
...
@@ -176,7 +189,7 @@ module TalltyImportExport
elsif
header
[
:json
]
elsif
header
[
:json
]
record
.
send
(
header
[
:json
])[
header
[
:key
]]
record
.
send
(
header
[
:json
])[
header
[
:key
]]
elsif
header
[
:proc
]
&&
header
[
:proc
].
respond_to?
(
:call
)
elsif
header
[
:proc
]
&&
header
[
:proc
].
respond_to?
(
:call
)
header
[
:proc
].
call
(
record
)
header
[
:proc
].
call
(
record
,
context
)
else
else
try_method
(
record
,
header
[
:key
])
try_method
(
record
,
header
[
:key
])
end
end
...
...
lib/tallty_import_export/import.rb
View file @
ffce6618
...
@@ -136,13 +136,12 @@ module TalltyImportExport
...
@@ -136,13 +136,12 @@ module TalltyImportExport
# 需要合并proc,前端没有办法把proc传过来
# 需要合并proc,前端没有办法把proc传过来
def
import_headers_result
def
import_headers_result
if
@headers
.
present?
if
@headers
.
present?
import_header_hash
=
import_headers
.
to_h
{
|
header
|
[
header
.
with_indifferent_access
[
:key
],
header
]
}.
with_indifferent_access
headers_hash
=
@headers
.
to_h
{
|
header
|
[
header
.
with_indifferent_access
[
:key
],
header
]
}.
with_indifferent_access
@headers
.
map
do
|
header
|
import_headers
.
select
do
|
_header
|
key
=
header
[
:key
]
_header
.
with_indifferent_access
[
:key
].
to_s
.
in?
(
headers_hash
.
keys
)
if
import_header_hash
.
dig
(
key
,
:proc
).
present?
end
.
map
do
|
_header
|
header
[
:proc
]
=
import_header_hash
.
dig
(
key
,
:proc
)
_header
.
with_indifferent_access!
end
_header
.
merge
(
headers_hash
[
_header
[
:key
]].
delete_if
{
|
k
,
v
|
v
.
blank?
})
header
end
end
else
else
@headers
=
import_headers
@headers
=
import_headers
...
...
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