Skip to content

Commit

Permalink
[change] optimize table widget default values
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 22, 2022
1 parent c081bd4 commit 409b449
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 103 deletions.
82 changes: 41 additions & 41 deletions data/bindata.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions widgets/app/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type DSL struct {
AdminRoot string `json:"adminRoot,omitempty"`
Optional OptionalDSL `json:"optional,omitempty"`
Setting string `json:"setting,omitempty"` // custom setting process
Setup string `json:"setup,omitempty"` // setup process
}

// MenuDSL the menu DSL
Expand Down
44 changes: 22 additions & 22 deletions widgets/expression/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func TestReplaceMap(t *testing.T) {
err := Replace(&mapv, data)
assert.Nil(t, err)
assert.Equal(t, "::please select Bar", mapv["placeholder"])
assert.Equal(t, "Hello", mapv["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", mapv["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", mapv["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", mapv["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", mapv["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", mapv["options"].([]map[string]interface{})[1]["value"])
}

Expand All @@ -149,9 +149,9 @@ func TestReplaceSlice(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 2, len(arrv))
assert.Equal(t, "::please select Bar", arrv[0])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["value"])
}

Expand All @@ -162,17 +162,17 @@ func TestReplaceNest(t *testing.T) {
err := Replace(&nestv, data)
assert.Nil(t, err)
assert.Equal(t, "::please select Bar", nestv["placeholder"])
assert.Equal(t, "Hello", nestv["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", nestv["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", nestv["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", nestv["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", nestv["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", nestv["options"].([]map[string]interface{})[1]["value"])

arrv := nestv["data"].([]interface{})
assert.Equal(t, 2, len(arrv))
assert.Equal(t, "::please select Bar", arrv[0])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["value"])
}

Expand All @@ -184,17 +184,17 @@ func TestReplaceStruct(t *testing.T) {
assert.Nil(t, err)

assert.Equal(t, "Bar", structv.Name)
assert.Equal(t, "Hello", structv.Map["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", structv.Map["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", structv.Map["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", structv.Map["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", structv.Map["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", structv.Map["options"].([]map[string]interface{})[1]["value"])

arrv := structv.Slice
assert.Equal(t, 2, len(arrv))
assert.Equal(t, "::please select Bar", arrv[0])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["value"])
}

Expand Down Expand Up @@ -276,9 +276,9 @@ func TestReplaceAny(t *testing.T) {
res, ok := anyv.([]map[string]interface{})
assert.True(t, ok)
assert.Equal(t, 2, len(res))
assert.Equal(t, "Hello", res[0]["label"])
assert.Equal(t, "::Hello", res[0]["label"])
assert.Equal(t, "Hello", res[0]["value"])
assert.Equal(t, "World", res[1]["label"])
assert.Equal(t, "::World", res[1]["label"])
assert.Equal(t, "World", res[1]["value"])

anyv = 1024
Expand All @@ -293,36 +293,36 @@ func TestReplaceAny(t *testing.T) {
err = Replace(&anyv, data)
assert.Nil(t, err)
assert.Equal(t, "::please select Bar", anyv.(TestMap)["placeholder"])
assert.Equal(t, "Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["value"])

anyv = testSlice()
err = Replace(&anyv, data)
assert.Nil(t, err)
assert.Equal(t, 2, len(anyv.([]interface{})))
assert.Equal(t, "::please select Bar", anyv.([]interface{})[0])
assert.Equal(t, "Hello", anyv.([]interface{})[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", anyv.([]interface{})[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", anyv.([]interface{})[1].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", anyv.([]interface{})[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", anyv.([]interface{})[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", anyv.([]interface{})[1].([]map[string]interface{})[1]["value"])

anyv = testNest()
err = Replace(&anyv, data)
assert.Nil(t, err)
assert.Equal(t, "::please select Bar", anyv.(TestMap)["placeholder"])
assert.Equal(t, "Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", anyv.(TestMap)["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", anyv.(TestMap)["options"].([]map[string]interface{})[1]["value"])

arrv := anyv.(TestMap)["data"].([]interface{})
assert.Equal(t, 2, len(arrv))
assert.Equal(t, "::please select Bar", arrv[0])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", arrv[1].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", arrv[1].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", arrv[1].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", arrv[1].([]map[string]interface{})[1]["value"])

}
Expand Down
6 changes: 3 additions & 3 deletions widgets/expression/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func processSelectOption(process *gou.Process) interface{} {
opts := strings.Split(input.(string), ",")
for _, opt := range opts {
options = append(options, map[string]interface{}{
"label": strings.TrimSpace(opt),
"label": fmt.Sprintf("::%s", strings.TrimSpace(opt)),
"value": strings.TrimSpace(opt),
})
}
Expand All @@ -38,7 +38,7 @@ func processSelectOption(process *gou.Process) interface{} {
switch opt.(type) {
case string, int, int64, int32, int8, float32, float64:
options = append(options, map[string]interface{}{
"label": strings.TrimSpace(fmt.Sprintf("%v", opt)),
"label": fmt.Sprintf("::%s", strings.TrimSpace(fmt.Sprintf("%v", opt))),
"value": strings.TrimSpace(fmt.Sprintf("%v", opt)),
})
break
Expand All @@ -57,7 +57,7 @@ func processSelectOption(process *gou.Process) interface{} {

row := any.Of(opt).MapStr()
options = append(options, map[string]interface{}{
"label": row.Get(key),
"label": fmt.Sprintf("::%s", row.Get(key)),
"value": row.Get(value),
})
break
Expand Down
4 changes: 2 additions & 2 deletions widgets/field/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestColumnReplace(t *testing.T) {
assert.Equal(t, "Bar", new.Key)
assert.Equal(t, "Foo", new.Bind)
assert.Equal(t, "::please select Bar", new.Edit.Props["placeholder"])
assert.Equal(t, "Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", new.Edit.Props["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", new.Edit.Props["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", new.Edit.Props["options"].([]map[string]interface{})[1]["value"])
}

Expand Down
4 changes: 2 additions & 2 deletions widgets/field/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestFilterReplace(t *testing.T) {
assert.Equal(t, "Bar", new.Key)
assert.Equal(t, "Foo", new.Bind)
assert.Equal(t, "::please select Bar", new.Edit.Props["placeholder"])
assert.Equal(t, "Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "::Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["label"])
assert.Equal(t, "Hello", new.Edit.Props["options"].([]map[string]interface{})[0]["value"])
assert.Equal(t, "World", new.Edit.Props["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "::World", new.Edit.Props["options"].([]map[string]interface{})[1]["label"])
assert.Equal(t, "World", new.Edit.Props["options"].([]map[string]interface{})[1]["value"])
}

Expand Down
29 changes: 19 additions & 10 deletions widgets/table/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,41 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
}

if hasForm {
layout.Table.Operation.Width = 160
layout.Table.Operation.Width = 140
layout.Table.Operation.Hide = false
layout.Table.Operation.Actions = append(
layout.Table.Operation.Actions,

component.ActionDSL{
Title: "查看",
Title: "::View",
Icon: "icon-eye",
Action: map[string]component.ParamsDSL{
"Common.openModal": {
"width": 640,
"Form": map[string]interface{}{"type": "view", "model": formName},
"Form": map[string]interface{}{"type": "view", "model": formName},
},
},
},

component.ActionDSL{
Title: "编辑",
Title: "::Edit",
Icon: "icon-edit-2",
Action: map[string]component.ParamsDSL{
"Common.openModal": {
"width": 640,
"Form": map[string]interface{}{"type": "edit", "model": formName},
"Form": map[string]interface{}{"type": "edit", "model": formName},
},
},
},

component.ActionDSL{
Title: "删除",
Title: "::Delete",
Icon: "icon-trash-2",
Style: "danger",
Action: map[string]component.ParamsDSL{
"Table.delete": {"model": formName},
},
Confirm: &component.ConfirmActionDSL{
Title: "提示",
Desc: "确认删除,删除后数据无法恢复?",
Title: "::Confirm",
Desc: "::Please confirm, the data cannot be recovered",
},
},
)
Expand Down Expand Up @@ -159,6 +157,17 @@ func (layout *LayoutDSL) BindTable(tab *DSL, fields *FieldsDSL) error {
// Xgen trans to Xgen setting
func (layout *LayoutDSL) Xgen() (map[string]interface{}, error) {
res := map[string]interface{}{}

if layout.Table != nil {
if layout.Table.Props == nil {
layout.Table.Props = component.PropsDSL{}
}

if _, has := layout.Table.Props["scroll"]; !has {
layout.Table.Props["scroll"] = map[string]interface{}{"x": "max-content"}
}
}

data, err := jsoniter.Marshal(layout)
if err != nil {
return nil, err
Expand Down
14 changes: 9 additions & 5 deletions widgets/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ var Tables map[string]*DSL = map[string]*DSL{}
// New create a new DSL
func New(id string) *DSL {
return &DSL{
ID: id,
Fields: &FieldsDSL{Filter: field.Filters{}, Table: field.Columns{}},
CProps: field.CloudProps{},
ComputesIn: field.ComputeFields{},
ComputesOut: field.ComputeFields{},
ID: id,
Fields: &FieldsDSL{Filter: field.Filters{}, Table: field.Columns{}},
CProps: field.CloudProps{},
Config: map[string]interface{}{},
}
}

Expand Down Expand Up @@ -262,6 +261,11 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
return nil, err
}

// full width default value
if _, has := dsl.Config["full"]; !has {
dsl.Config["full"] = true
}

setting["fields"] = fields
setting["config"] = dsl.Config
for _, cProp := range dsl.CProps {
Expand Down
20 changes: 9 additions & 11 deletions widgets/table/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ const (

// DSL the table DSL
type DSL struct {
Root string `json:"-"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Action *ActionDSL `json:"action"`
Layout *LayoutDSL `json:"layout"`
Fields *FieldsDSL `json:"fields"`
Config map[string]interface{} `json:"config,omitempty"`
ComputesIn field.ComputeFields `json:"-"`
ComputesOut field.ComputeFields `json:"-"`
CProps field.CloudProps `json:"-"`
computes *computeMaps
Root string `json:"-"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Action *ActionDSL `json:"action"`
Layout *LayoutDSL `json:"layout"`
Fields *FieldsDSL `json:"fields"`
Config map[string]interface{} `json:"config,omitempty"`
CProps field.CloudProps `json:"-"`
computes *computeMaps
}

type computeMaps struct {
Expand Down
20 changes: 13 additions & 7 deletions yao/fields/model.trans.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@
"table": {
"key": "${label || comment || name}",
"bind": "${name}",
"view": { "type": "Text", "props": {} },
"view": {
"type": "Tag",
"props": {
"placeholder": "$L(please select) ${label || comment}",
"options": "$.SelectOption{option}"
}
},
"edit": {
"type": "Select",
"props": {
Expand Down Expand Up @@ -496,8 +502,8 @@
"type": "RadioGroup",
"props": {
"options": [
{ "label": "::Enable", "value": 1 },
{ "label": "::Disable", "value": 0 }
{ "label": "::Enable", "value": true },
{ "label": "::Disable", "value": false }
]
}
}
Expand All @@ -509,8 +515,8 @@
"type": "RadioGroup",
"props": {
"options": [
{ "label": "::Enable", "value": 1 },
{ "label": "::Disable", "value": 0 }
{ "label": "::Enable", "value": true },
{ "label": "::Disable", "value": false }
]
}
}
Expand All @@ -521,8 +527,8 @@
"view": {
"type": "Switch",
"props": {
"checkedValue": 1,
"unCheckedValue": 0,
"checkedValue": true,
"unCheckedValue": false,
"checkedChildren": "::Enable",
"unCheckedChildren": "::Disable"
}
Expand Down
8 changes: 8 additions & 0 deletions yao/langs/zh-cn/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ Listening: " 监听"
SessionPort: "会话服务端口"
Force migrate: "强制更新数据表结构"
Migrate is not allowed on production mode.: "Migrate 不能再生产环境下使用"
Please confirm, the data cannot be recovered: 请确认删除,删除后数据无法恢复
Create: 创建
Edit: 编辑
View: 查看
Confirm: 确认
please input: 请输入
Please input: 请输入
please select: 请选择
Please select: 请选择
Enable: 开启
Disable: 关闭
enable: 开启
disable: 关闭
Enabled: 开启
Disabled: 关闭
enabled: 开启
disabled: 关闭
8 changes: 8 additions & 0 deletions yao/langs/zh-hk/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ Listening: " 監聽"
SessionPort: "會話服務端口"
Force migrate: "強制更新數據表結構"
Migrate is not allowed on production mode.: "Migrate 不能再生產環境下使用"
Please confirm, the data cannot be recovered: 請確認刪除,刪除後數據無法恢復
Create: 創建
Edit: 編輯
View: 查看
Confirm: 確認
please input: 請輸入
Please input: 請輸入
please select: 請選擇
Please select: 請選擇
Enable: 開啟
Disable: 關閉
enable: 開啟
disable: 關閉
Enabled: 開啟
Disabled: 關閉
enabled: 開啟
disabled: 關閉

0 comments on commit 409b449

Please sign in to comment.