Commit e493e4fe by Ivan Lan

Add export_header_result and import_header_result

parent 0802ca29
......@@ -17,7 +17,7 @@ module TalltyImportExport
# { key: 'state', name: '考核状态', method: :state_zh },
# { key: 'score', name: '考核分' },
# ]
# export_headers / headers
# export_headers_result / headers
# key: 属性的英文名
# name: 属性的中文名
# attr_type: 属性的类型
......@@ -67,7 +67,7 @@ module TalltyImportExport
title1 = workbook.styles.add_style(alignment: alignment, border: border, sz: 12, b: true)
title2 = workbook.styles.add_style(alignment: alignment, border: border, bg_color: "2a5caa", sz: 12, fg_color: "fffffb")
title3 = workbook.styles.add_style(alignment: alignment.merge(wrap_text: true), border: border, sz: 10)
headers = export_headers
headers = export_headers_result
_sheet_name = respond_to?(:sheet_name) ? self.sheet_name : nil
......@@ -105,8 +105,8 @@ module TalltyImportExport
records
end
def export_headers
@headers || klass.try(:headers) || klass.try(:model_headers)
def export_headers_result
@headers || klass.try(:export_headers) || klass.try(:headers) || klass.try(:model_headers)
end
# 处理一个记录的数据
......
......@@ -5,7 +5,7 @@ module TalltyImportExport
def initialize klass
@klass = klass
@headers = import_headers.map { |header| header.with_indifferent_access }
@headers = import_headers_result.map { |header| header.with_indifferent_access }
@context = Context.new({})
end
......@@ -96,14 +96,14 @@ module TalltyImportExport
true
end
def import_headers
klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
def import_headers_result
klass.try(:headers) || klass.try(:import_headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers_result'))
end
# 只保留 key, name, json, 合并到 import_header
def headers= val
if val.empty?
@headers = import_headers.map { |header| header.with_indifferent_access }
@headers = import_headers_result.map { |header| header.with_indifferent_access }
return
end
......@@ -114,7 +114,7 @@ module TalltyImportExport
result = []
val.map do |header|
if (exist_header = import_headers.find { |model_header| model_header[:key] === header[:key] })
if (exist_header = import_headers_result.find { |model_header| model_header[:key] === header[:key] })
result.push(exist_header.merge(name: header[:name], json: header[:json]))
else
result.push({ key: header[:key], name: header[:name], json: header[:json]})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment