Commit e493e4fe by Ivan Lan

Add export_header_result and import_header_result

parent 0802ca29
...@@ -17,7 +17,7 @@ module TalltyImportExport ...@@ -17,7 +17,7 @@ module TalltyImportExport
# { key: 'state', name: '考核状态', method: :state_zh }, # { key: 'state', name: '考核状态', method: :state_zh },
# { key: 'score', name: '考核分' }, # { key: 'score', name: '考核分' },
# ] # ]
# export_headers / headers # export_headers_result / headers
# key: 属性的英文名 # key: 属性的英文名
# name: 属性的中文名 # name: 属性的中文名
# attr_type: 属性的类型 # attr_type: 属性的类型
...@@ -67,7 +67,7 @@ module TalltyImportExport ...@@ -67,7 +67,7 @@ module TalltyImportExport
title1 = workbook.styles.add_style(alignment: alignment, border: border, sz: 12, b: true) 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") 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) 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 _sheet_name = respond_to?(:sheet_name) ? self.sheet_name : nil
...@@ -105,8 +105,8 @@ module TalltyImportExport ...@@ -105,8 +105,8 @@ module TalltyImportExport
records records
end end
def export_headers def export_headers_result
@headers || klass.try(:headers) || klass.try(:model_headers) @headers || klass.try(:export_headers) || klass.try(:headers) || klass.try(:model_headers)
end end
# 处理一个记录的数据 # 处理一个记录的数据
......
...@@ -5,7 +5,7 @@ module TalltyImportExport ...@@ -5,7 +5,7 @@ module TalltyImportExport
def initialize klass def initialize klass
@klass = 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({}) @context = Context.new({})
end end
...@@ -96,14 +96,14 @@ module TalltyImportExport ...@@ -96,14 +96,14 @@ module TalltyImportExport
true true
end end
def import_headers def import_headers_result
klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers')) klass.try(:headers) || klass.try(:import_headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers_result'))
end end
# 只保留 key, name, json, 合并到 import_header # 只保留 key, name, json, 合并到 import_header
def headers= val def headers= val
if val.empty? if val.empty?
@headers = import_headers.map { |header| header.with_indifferent_access } @headers = import_headers_result.map { |header| header.with_indifferent_access }
return return
end end
...@@ -114,7 +114,7 @@ module TalltyImportExport ...@@ -114,7 +114,7 @@ module TalltyImportExport
result = [] result = []
val.map do |header| 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])) result.push(exist_header.merge(name: header[:name], json: header[:json]))
else else
result.push({ key: header[:key], name: header[:name], json: header[:json]}) 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