[change] action setting
This commit is contained in:
parent
7151a28534
commit
7ba65f8c68
6 changed files with 34 additions and 13 deletions
|
|
@ -15,7 +15,7 @@ var processActionDefaults = map[string]*action.Process{
|
|||
Name: "yao.form.Setting",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "yao.form.Xgen",
|
||||
Default: []interface{}{nil},
|
||||
Default: []interface{}{nil, nil},
|
||||
},
|
||||
"Component": {
|
||||
Name: "yao.form.Component",
|
||||
|
|
|
|||
|
|
@ -118,6 +118,18 @@ func exportAPI() error {
|
|||
}
|
||||
http.Paths = append(http.Paths, path)
|
||||
|
||||
// POST /api/__yao/form/:id/component/:xpath/:method -> Default process: yao.form.Component $param.id $param.xpath $param.method :payload
|
||||
path = gou.Path{
|
||||
Label: "Component",
|
||||
Description: "Component",
|
||||
Path: "/:id/component/:xpath/:method",
|
||||
Method: "POST",
|
||||
Process: "yao.form.Component",
|
||||
In: []string{"$param.id", "$param.xpath", "$param.method", ":payload"},
|
||||
Out: gou.Out{Status: 200, Type: "application/json"},
|
||||
}
|
||||
http.Paths = append(http.Paths, path)
|
||||
|
||||
// POST /api/__yao/table/:id/upload/:xpath/:method -> Default process: yao.form.Upload $param.id $param.xpath $param.method $file.file
|
||||
path = gou.Path{
|
||||
Label: "Upload",
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
|||
if layout.Form != nil && layout.Form.Sections != nil {
|
||||
|
||||
layout.listColumns(func(path string, f Column) {
|
||||
|
||||
name := f.Name
|
||||
field, has := fields.Form[name]
|
||||
if !has {
|
||||
|
|
@ -120,7 +121,15 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
|||
}
|
||||
}
|
||||
messages = append(messages, fmt.Sprintf("fields.form.%s not found, checking %s", f.Name, path))
|
||||
return
|
||||
}
|
||||
|
||||
if field.Edit != nil && field.Edit.Props != nil {
|
||||
if _, has := field.Edit.Props["$on:change"]; has {
|
||||
delete(field.Edit.Props, "$on:change")
|
||||
}
|
||||
}
|
||||
|
||||
forms[name] = field.Map()
|
||||
}, "", nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
|||
dsl.Config["full"] = true
|
||||
}
|
||||
|
||||
// action.Hooks
|
||||
// Hooks
|
||||
hooks := map[string]interface{}{}
|
||||
setting["fields"] = fields
|
||||
setting["config"] = dsl.Config
|
||||
|
|
@ -256,8 +256,8 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// action.hooks
|
||||
if cProp.Name == "onChange" {
|
||||
// hooks
|
||||
if cProp.Name == "on:change" {
|
||||
field := strings.TrimPrefix(cProp.Xpath, "fields.form.")
|
||||
field = strings.TrimSuffix(field, ".edit.props")
|
||||
hooks[field] = map[string]interface{}{
|
||||
|
|
@ -265,10 +265,9 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
|||
"params": cProp.Query,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setting["action"] = map[string]interface{}{"hooks": hooks}
|
||||
setting["hooks"] = hooks
|
||||
setting["name"] = dsl.Name
|
||||
return setting, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ func processComponent(process *gou.Process) interface{} {
|
|||
|
||||
process.ValidateArgNums(3)
|
||||
form := MustGet(process)
|
||||
xpath := process.ArgsString(1)
|
||||
method := process.ArgsString(2)
|
||||
xpath, _ := url.QueryUnescape(process.ArgsString(1))
|
||||
method, _ := url.QueryUnescape(process.ArgsString(2))
|
||||
key := fmt.Sprintf("%s.$%s", xpath, method)
|
||||
|
||||
// get cloud props
|
||||
|
|
@ -147,7 +147,8 @@ func processUpload(process *gou.Process) interface{} {
|
|||
|
||||
func processSetting(process *gou.Process) interface{} {
|
||||
form := MustGet(process)
|
||||
process.Args = append(process.Args, process.Args[0]) // formle name
|
||||
args := []interface{}{form.ID}
|
||||
process.Args = append(args, process.Args...) // form name
|
||||
return form.Action.Setting.MustExec(process)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -229,8 +229,8 @@ func TestProcessSetting(t *testing.T) {
|
|||
}
|
||||
|
||||
data := any.Of(res).MapStr().Dot()
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/onChange", data.Get("action.hooks.住院天数.api"))
|
||||
assert.Equal(t, "开发者定义数据", data.Get("action.hooks.住院天数.params.extra"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/"+url.QueryEscape("on:change"), data.Get("hooks.住院天数.api"))
|
||||
assert.Equal(t, "开发者定义数据", data.Get("hooks.住院天数.params.extra"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("状态")+".edit.props.xProps/remote", data.Get("fields.form.状态.edit.props.xProps.remote.api"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/upload/fields.form."+url.QueryEscape("相关图片")+".edit.props/api", data.Get("fields.form.相关图片.edit.props.api"))
|
||||
}
|
||||
|
|
@ -246,8 +246,8 @@ func TestProcessXgen(t *testing.T) {
|
|||
}
|
||||
|
||||
data := any.Of(res).MapStr().Dot()
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/onChange", data.Get("action.hooks.住院天数.api"))
|
||||
assert.Equal(t, "开发者定义数据", data.Get("action.hooks.住院天数.params.extra"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/"+url.QueryEscape("on:change"), data.Get("hooks.住院天数.api"))
|
||||
assert.Equal(t, "开发者定义数据", data.Get("hooks.住院天数.params.extra"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("状态")+".edit.props.xProps/remote", data.Get("fields.form.状态.edit.props.xProps.remote.api"))
|
||||
assert.Equal(t, "/api/__yao/form/pet/upload/fields.form."+url.QueryEscape("相关图片")+".edit.props/api", data.Get("fields.form.相关图片.edit.props.api"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue