[add] field.$data cloud props
This commit is contained in:
parent
70a3d63450
commit
448b0eaa0e
5 changed files with 70 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/flow"
|
||||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
|
|
@ -38,6 +39,12 @@ func prepare(t *testing.T, language ...string) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// load flows
|
||||
err = flow.Load(config.Conf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// export
|
||||
err = Export()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -131,6 +131,9 @@ func (dsl *DSL) mapping() error {
|
|||
|
||||
// Columns
|
||||
return dsl.Fields.Dashboard.CPropsMerge(dsl.CProps, func(name string, kind string, column field.ColumnDSL) (xpath string) {
|
||||
if kind == "data" {
|
||||
return fmt.Sprintf("fields.dashboard.%s", name)
|
||||
}
|
||||
return fmt.Sprintf("fields.dashboard.%s.%s.props", name, kind)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,39 @@ func TestProcessComponent(t *testing.T) {
|
|||
assert.Equal(t, "checked", pets[0]["status"])
|
||||
assert.Equal(t, "Baby", pets[1]["name"])
|
||||
assert.Equal(t, "checked", pets[1]["status"])
|
||||
|
||||
args = []interface{}{
|
||||
"workspace",
|
||||
"fields.dashboard.图表展示1",
|
||||
"data",
|
||||
map[string]interface{}{"foo": "bar"},
|
||||
}
|
||||
|
||||
res2, err := gou.NewProcess("yao.dashboard.Component", args...).Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
values, ok := res2.([]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Greater(t, len(values), 1)
|
||||
|
||||
args = []interface{}{
|
||||
"workspace",
|
||||
"fields.dashboard.图表展示2",
|
||||
"data",
|
||||
map[string]interface{}{"foo": "bar"},
|
||||
}
|
||||
|
||||
res2, err = gou.NewProcess("yao.dashboard.Component", args...).Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
values, ok = res2.([]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Greater(t, len(values), 1)
|
||||
|
||||
}
|
||||
|
||||
func TestProcessComponentError(t *testing.T) {
|
||||
|
|
@ -81,6 +114,8 @@ func TestProcessXgen(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"))
|
||||
}
|
||||
|
||||
func TestProcessXgenWithPermissions(t *testing.T) {
|
||||
|
|
@ -89,8 +124,8 @@ func TestProcessXgenWithPermissions(t *testing.T) {
|
|||
"dashboards.workspace": []string{
|
||||
"7f46a38d7ff3f1832375ff63cd412f41", // operation.actions[0] 跳转至大屏
|
||||
"09302a46b1b6f13a346deeea79b859dd", // 时间区间
|
||||
"2e1b0010d201887cac2948ec75a2fae5", // 图表展示2
|
||||
"37dd001c9efada4f1d21530deba2a7cf", // 图表展示1
|
||||
"8b445709024e0e5361d8bcdd58c75fcb", // 图表展示2
|
||||
"0bdee1c9858ef2a821a0ff7109d3fc5b", // 图表展示1
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@ func (column ColumnDSL) Map() map[string]interface{} {
|
|||
"bind": column.Bind,
|
||||
}
|
||||
|
||||
if column.Data != nil {
|
||||
res["data"] = map[string]interface{}{"process": column.Data.Process, "query": column.Data.Query}
|
||||
}
|
||||
|
||||
if column.Link != "" {
|
||||
res["link"] = column.Link
|
||||
}
|
||||
|
|
@ -131,6 +135,18 @@ func (columns Columns) CPropsMerge(cloudProps map[string]component.CloudPropsDSL
|
|||
|
||||
for name, column := range columns {
|
||||
|
||||
if column.Data != nil {
|
||||
xpath := getXpath(name, "data", column)
|
||||
cProps := map[string]component.CloudPropsDSL{}
|
||||
cprop := *column.Data
|
||||
cprop.Xpath = xpath
|
||||
cprop.Name = "data"
|
||||
cprop.Type = "data"
|
||||
fullname := fmt.Sprintf("%s.$data", xpath)
|
||||
cProps[fullname] = cprop
|
||||
mergeCProps(cloudProps, cProps)
|
||||
}
|
||||
|
||||
if column.Edit != nil && column.Edit.Props != nil {
|
||||
xpath := getXpath(name, "edit", column)
|
||||
cProps, err := column.Edit.Props.CloudProps(xpath, column.Edit.Type)
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@ type CloudProps map[string]component.CloudPropsDSL
|
|||
|
||||
// ColumnDSL the field column dsl
|
||||
type ColumnDSL struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Bind string `json:"bind,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
View *component.DSL `json:"view,omitempty"`
|
||||
Edit *component.DSL `json:"edit,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Data *component.CloudPropsDSL `json:"$data,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Bind string `json:"bind,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
View *component.DSL `json:"view,omitempty"`
|
||||
Edit *component.DSL `json:"edit,omitempty"`
|
||||
}
|
||||
|
||||
type aliasColumnDSL ColumnDSL
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue