+ DataSetting API

This commit is contained in:
Max 2022-01-18 12:54:21 +08:00
parent 6b1f3bdf4a
commit 269da4fc94
5 changed files with 75 additions and 35 deletions

View file

@ -228,16 +228,68 @@ func (imp *Importer) MappingPreview(src from.Source) *Mapping {
}
// DataSetting 预览数据表格配置
func (imp *Importer) DataSetting(src from.Source) []map[string]interface{} {
return nil
func (imp *Importer) DataSetting() map[string]interface{} {
columns := map[string]share.Column{}
layoutColumns := []map[string]interface{}{}
for _, column := range imp.Columns {
name := column.Label
layoutColumns = append(layoutColumns, map[string]interface{}{"name": name})
columns[name] = share.Column{
Label: name,
View: share.Render{
Type: "label",
Props: map[string]interface{}{"value": fmt.Sprintf(":%s", column.Field)},
},
}
}
setting := map[string]interface{}{
"columns": columns,
"filters": map[string]interface{}{},
"list": share.Page{
Primary: "id",
Layout: map[string]interface{}{"columns": layoutColumns},
},
"actions": map[string]interface{}{
"pagination": map[string]interface{}{
"props": map[string]interface{}{
"showTotal": true,
},
},
},
"option": map[string]interface{}{
"operation": map[string]interface{}{
"hideView": true,
"hideEdit": true,
"width": 120,
"unfold": true,
"checkbox": map[string]interface{}{
"value": ":__effected",
"visible_label": false,
"status": []map[string]interface{}{
{
"label": "有效",
"value": true,
},
{
"label": "无效",
"value": false,
},
},
},
},
},
}
return setting
}
// MappingSetting 预览映射数据表格配置
func (imp *Importer) MappingSetting(src from.Source) map[string]interface{} {
columns := map[string]share.Column{
"关联字段": {
Label: "关联字段",
"字段名称": {
Label: "字段名称",
View: share.Render{
Type: "label",
Props: map[string]interface{}{"value": ":label"},
@ -281,10 +333,10 @@ func (imp *Importer) MappingSetting(src from.Source) map[string]interface{} {
"columns": columns,
"filters": map[string]interface{}{},
"list": share.Page{
Primary: "field",
Primary: "id",
Layout: map[string]interface{}{
"columns": []map[string]interface{}{
{"name": "字段"},
{"name": "字段名称"},
{"name": "数据源"},
{"name": "清洗规则"},
{"name": "数据示例"},
@ -295,7 +347,6 @@ func (imp *Importer) MappingSetting(src from.Source) map[string]interface{} {
"option": map[string]interface{}{
"operation": map[string]interface{}{"hideView": true, "hideEdit": true, "width": 0},
},
"edit": map[string]interface{}{},
}
return setting
}

View file

@ -147,3 +147,9 @@ func TestMappingSetting(t *testing.T) {
setting := imp.MappingSetting(file)
assert.NotNil(t, setting)
}
func TestDataSetting(t *testing.T) {
imp := Select("order")
setting := imp.DataSetting()
assert.NotNil(t, setting)
}

View file

@ -13,7 +13,6 @@ func init() {
gou.RegisterProcessHandler("xiang.import.DataSetting", ProcessDataSetting)
gou.RegisterProcessHandler("xiang.import.Mapping", ProcessMapping)
gou.RegisterProcessHandler("xiang.import.MappingSetting", ProcessMappingSetting)
gou.RegisterProcessHandler("xiang.import.Rules", ProcessRules)
}
// ProcessRun xiang.import.Run
@ -48,7 +47,10 @@ func ProcessData(process *gou.Process) interface{} {
// ProcessDataSetting xiang.import.DataSetting
// 数据预览表格配置
func ProcessDataSetting(process *gou.Process) interface{} {
return nil
process.ValidateArgNums(1)
name := process.ArgsString(0)
imp := Select(name)
return imp.DataSetting()
}
// ProcessMapping xiang.import.Mapping
@ -75,12 +77,6 @@ func ProcessMappingSetting(process *gou.Process) interface{} {
return imp.MappingSetting(src)
}
// ProcessRules xiang.import.Rules
// 可用处理器下拉列表
func ProcessRules(process *gou.Process) interface{} {
return nil
}
// 转换为映射表
func anyToMapping(v interface{}) *Mapping {
var mapping Mapping

View file

@ -18,9 +18,11 @@ func TestProcessMapping(t *testing.T) {
}
func TestProcessMappingSetting(t *testing.T) {
args := []interface{}{"order"}
simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx")
args := []interface{}{"order", simple}
response := gou.NewProcess("xiang.import.MappingSetting", args...).Run()
assert.Nil(t, response)
_, ok := response.(map[string]interface{})
assert.True(t, ok)
}
func TestProcessData(t *testing.T) {
@ -35,7 +37,8 @@ func TestProcessData(t *testing.T) {
func TestProcessDataSetting(t *testing.T) {
args := []interface{}{"order"}
response := gou.NewProcess("xiang.import.DataSetting", args...).Run()
assert.Nil(t, response)
_, ok := response.(map[string]interface{})
assert.True(t, ok)
}
func TestProcessRun(t *testing.T) {
@ -46,9 +49,3 @@ func TestProcessRun(t *testing.T) {
_, ok := response.(map[string]int)
assert.True(t, ok)
}
func TestProcessRules(t *testing.T) {
args := []interface{}{"order"}
response := gou.NewProcess("xiang.import.Rules", args...).Run()
assert.Nil(t, response)
}

View file

@ -35,7 +35,7 @@
"path": "/:name/data/setting",
"method": "GET",
"process": "xiang.import.DataSetting",
"in": ["$param.name", ":query"],
"in": ["$param.name"],
"out": {
"status": 200,
"type": "application/json"
@ -60,16 +60,6 @@
"status": 200,
"type": "application/json"
}
},
{
"path": "/:name/rule/select",
"method": "GET",
"process": "xiang.import.Rules",
"in": ["$param.name", ":query"],
"out": {
"status": 200,
"type": "application/json"
}
}
]
}