commit
a811efc094
6 changed files with 34 additions and 13 deletions
|
|
@ -15,7 +15,7 @@ var processActionDefaults = map[string]*action.Process{
|
||||||
Name: "yao.form.Setting",
|
Name: "yao.form.Setting",
|
||||||
Guard: "bearer-jwt",
|
Guard: "bearer-jwt",
|
||||||
Process: "yao.form.Xgen",
|
Process: "yao.form.Xgen",
|
||||||
Default: []interface{}{nil},
|
Default: []interface{}{nil, nil},
|
||||||
},
|
},
|
||||||
"Component": {
|
"Component": {
|
||||||
Name: "yao.form.Component",
|
Name: "yao.form.Component",
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,18 @@ func exportAPI() error {
|
||||||
}
|
}
|
||||||
http.Paths = append(http.Paths, path)
|
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
|
// POST /api/__yao/table/:id/upload/:xpath/:method -> Default process: yao.form.Upload $param.id $param.xpath $param.method $file.file
|
||||||
path = gou.Path{
|
path = gou.Path{
|
||||||
Label: "Upload",
|
Label: "Upload",
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
||||||
if layout.Form != nil && layout.Form.Sections != nil {
|
if layout.Form != nil && layout.Form.Sections != nil {
|
||||||
|
|
||||||
layout.listColumns(func(path string, f Column) {
|
layout.listColumns(func(path string, f Column) {
|
||||||
|
|
||||||
name := f.Name
|
name := f.Name
|
||||||
field, has := fields.Form[name]
|
field, has := fields.Form[name]
|
||||||
if !has {
|
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))
|
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()
|
forms[name] = field.Map()
|
||||||
}, "", nil)
|
}, "", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
||||||
dsl.Config["full"] = true
|
dsl.Config["full"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// action.Hooks
|
// Hooks
|
||||||
hooks := map[string]interface{}{}
|
hooks := map[string]interface{}{}
|
||||||
setting["fields"] = fields
|
setting["fields"] = fields
|
||||||
setting["config"] = dsl.Config
|
setting["config"] = dsl.Config
|
||||||
|
|
@ -256,8 +256,8 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// action.hooks
|
// hooks
|
||||||
if cProp.Name == "onChange" {
|
if cProp.Name == "on:change" {
|
||||||
field := strings.TrimPrefix(cProp.Xpath, "fields.form.")
|
field := strings.TrimPrefix(cProp.Xpath, "fields.form.")
|
||||||
field = strings.TrimSuffix(field, ".edit.props")
|
field = strings.TrimSuffix(field, ".edit.props")
|
||||||
hooks[field] = map[string]interface{}{
|
hooks[field] = map[string]interface{}{
|
||||||
|
|
@ -265,10 +265,9 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
||||||
"params": cProp.Query,
|
"params": cProp.Query,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setting["action"] = map[string]interface{}{"hooks": hooks}
|
setting["hooks"] = hooks
|
||||||
setting["name"] = dsl.Name
|
setting["name"] = dsl.Name
|
||||||
return setting, nil
|
return setting, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ func processComponent(process *gou.Process) interface{} {
|
||||||
|
|
||||||
process.ValidateArgNums(3)
|
process.ValidateArgNums(3)
|
||||||
form := MustGet(process)
|
form := MustGet(process)
|
||||||
xpath := process.ArgsString(1)
|
xpath, _ := url.QueryUnescape(process.ArgsString(1))
|
||||||
method := process.ArgsString(2)
|
method, _ := url.QueryUnescape(process.ArgsString(2))
|
||||||
key := fmt.Sprintf("%s.$%s", xpath, method)
|
key := fmt.Sprintf("%s.$%s", xpath, method)
|
||||||
|
|
||||||
// get cloud props
|
// get cloud props
|
||||||
|
|
@ -147,7 +147,8 @@ func processUpload(process *gou.Process) interface{} {
|
||||||
|
|
||||||
func processSetting(process *gou.Process) interface{} {
|
func processSetting(process *gou.Process) interface{} {
|
||||||
form := MustGet(process)
|
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)
|
return form.Action.Setting.MustExec(process)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,8 +229,8 @@ func TestProcessSetting(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data := any.Of(res).MapStr().Dot()
|
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, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/"+url.QueryEscape("on:change"), data.Get("hooks.住院天数.api"))
|
||||||
assert.Equal(t, "开发者定义数据", data.Get("action.hooks.住院天数.params.extra"))
|
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/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"))
|
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()
|
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, "/api/__yao/form/pet/component/fields.form."+url.QueryEscape("住院天数")+".edit.props/"+url.QueryEscape("on:change"), data.Get("hooks.住院天数.api"))
|
||||||
assert.Equal(t, "开发者定义数据", data.Get("action.hooks.住院天数.params.extra"))
|
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/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"))
|
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