[add] widget dashboard on change
This commit is contained in:
parent
448b0eaa0e
commit
605d4d9aab
3 changed files with 44 additions and 1 deletions
|
|
@ -169,6 +169,8 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map
|
|||
|
||||
setting["fields"] = fields
|
||||
setting["config"] = dsl.Config
|
||||
|
||||
onChange := map[string]interface{}{} // Hooks
|
||||
for _, cProp := range dsl.CProps {
|
||||
err := cProp.Replace(setting, func(cProp component.CloudPropsDSL) interface{} {
|
||||
return map[string]interface{}{
|
||||
|
|
@ -179,8 +181,19 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// hooks
|
||||
if cProp.Name == "on:change" {
|
||||
field := strings.TrimPrefix(cProp.Xpath, "fields.dashboard.")
|
||||
field = strings.TrimSuffix(field, ".view.props")
|
||||
field = strings.TrimSuffix(field, ".edit.props")
|
||||
onChange[field] = map[string]interface{}{
|
||||
"api": fmt.Sprintf("/api/__yao/dashboard/%s%s", dsl.ID, cProp.Path()),
|
||||
"params": cProp.Query,
|
||||
}
|
||||
}
|
||||
}
|
||||
setting["hooks"] = map[string]interface{}{"onChange": onChange}
|
||||
return setting, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,38 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
|||
if layout.Dashboard != nil && layout.Dashboard.Columns != nil {
|
||||
for _, inst := range layout.Dashboard.Columns {
|
||||
if c, has := fields.Dashboard[inst.Name]; has {
|
||||
|
||||
if c.Edit != nil && c.Edit.Props != nil {
|
||||
if _, has := c.Edit.Props["$on:change"]; has {
|
||||
delete(c.Edit.Props, "$on:change")
|
||||
}
|
||||
}
|
||||
|
||||
if c.View != nil && c.View.Props != nil {
|
||||
if _, has := c.View.Props["$on:change"]; has {
|
||||
delete(c.View.Props, "$on:change")
|
||||
}
|
||||
}
|
||||
|
||||
columns[inst.Name] = c
|
||||
}
|
||||
|
||||
if inst.Rows != nil {
|
||||
for _, inst := range inst.Rows {
|
||||
if c, has := fields.Dashboard[inst.Name]; has {
|
||||
|
||||
if c.Edit != nil && c.Edit.Props != nil {
|
||||
if _, has := c.Edit.Props["$on:change"]; has {
|
||||
delete(c.Edit.Props, "$on:change")
|
||||
}
|
||||
}
|
||||
|
||||
if c.View != nil && c.View.Props != nil {
|
||||
if _, has := c.View.Props["$on:change"]; has {
|
||||
delete(c.View.Props, "$on:change")
|
||||
}
|
||||
}
|
||||
|
||||
columns[inst.Name] = c
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,9 @@ func TestProcessSetting(t *testing.T) {
|
|||
|
||||
data := any.Of(res).MapStr().Dot()
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.filter."+url.QueryEscape("状态")+".edit.props.xProps/remote", data.Get("fields.filter.状态.edit.props.xProps.remote.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("图表展示1")+"/data", data.Get("fields.dashboard.图表展示1.data.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("图表展示2")+"/data", data.Get("fields.dashboard.图表展示2.data.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("宠物列表")+".view.props/"+url.QueryEscape("on:change"), data.Get("hooks.onChange.宠物列表.api"))
|
||||
}
|
||||
|
||||
func TestProcessXgen(t *testing.T) {
|
||||
|
|
@ -116,6 +119,7 @@ func TestProcessXgen(t *testing.T) {
|
|||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.filter."+url.QueryEscape("状态")+".edit.props.xProps/remote", data.Get("fields.filter.状态.edit.props.xProps.remote.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("图表展示1")+"/data", data.Get("fields.dashboard.图表展示1.data.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("图表展示2")+"/data", data.Get("fields.dashboard.图表展示2.data.api"))
|
||||
assert.Equal(t, "/api/__yao/dashboard/workspace/component/fields.dashboard."+url.QueryEscape("宠物列表")+".view.props/"+url.QueryEscape("on:change"), data.Get("hooks.onChange.宠物列表.api"))
|
||||
}
|
||||
|
||||
func TestProcessXgenWithPermissions(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue