提交 2c52f2f1 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

support child custom fields

上级 517c608b
......@@ -47,8 +47,11 @@ func GenerateForDefinition(total int, fieldsToExport string, out string, table s
func GenerateForField(field *model.Field, total int) []string {
values := make([]string, 0)
if field.Type == "custom" && field.Range != "" { // load customized from file
LoadDefinitionFromFile(constant.ResDir + field.Range)
if field.Type == "custom" {
if field.Range != "" { // specific custom file
LoadDefinitionFromFile(constant.ResDir + field.Range)
}
referField := constant.LoadedFields[field.Name]
values = GenerateFieldItemsFromDefinition(&referField, total)
......
......@@ -5,6 +5,7 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
logUtils "github.com/easysoft/zendata/src/utils/log"
"io/ioutil"
"os"
"strconv"
"strings"
)
......@@ -86,6 +87,10 @@ func GenerateFieldValuesFromList(field *model.Field, fieldValue *model.FieldValu
fieldValue.Values = append(fieldValue.Values, items...)
index = index + len(items)
}
if len(fieldValue.Values) == 0 {
fieldValue.Values = append(fieldValue.Values, "N/A")
}
}
func GenerateFieldValuesFromText(field *model.Field, fieldValue *model.FieldValue, level int) {
......@@ -98,10 +103,19 @@ func GenerateFieldValuesFromText(field *model.Field, fieldValue *model.FieldValu
// read from file
list := make([]string, 0)
content, err := ioutil.ReadFile(constant.ResDir + file)
relaPath := constant.ResDir + file
content, err := ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + file)
return
logUtils.Screen("fail to read " + relaPath)
relaPath = "conf" + string(os.PathSeparator) + file
content, err = ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + relaPath)
fieldValue.Values = append(fieldValue.Values, "N/A")
return
}
}
str := string(content)
str = strings.Replace(str, "\\r\\n", "\\n", -1)
......@@ -132,6 +146,10 @@ func GenerateFieldValuesFromText(field *model.Field, fieldValue *model.FieldValu
fieldValue.Values = append(fieldValue.Values, item)
index = index + 1
}
if len(fieldValue.Values) == 0 {
fieldValue.Values = append(fieldValue.Values, "N/A")
}
}
func CheckRangeType(startStr string, endStr string, stepStr string) (string, interface{}, int, bool) {
......
......@@ -46,10 +46,16 @@ fields:
type: list
range: list.txt:R
- name: custom_field
note: 从文件读定义
type: custom
range: custom.yaml
- name: field3.2
note: 从文件读数据
fields:
- name: custom_field
note: 从文件读定义
type: custom
range: custom.yaml
- name: domain
note: 域名
type: custom
- name: field4
note: 引用。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册