[add] syntactic sugar action.disabled
This commit is contained in:
parent
b81eb750a3
commit
827b4cc3d3
3 changed files with 77 additions and 0 deletions
|
|
@ -23,6 +23,21 @@ func (action *ActionDSL) UnmarshalJSON(data []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Syntactic sugar Disabled
|
||||||
|
if action.Disabled != nil {
|
||||||
|
if action.Disabled.Eq != nil {
|
||||||
|
action.Disabled.Value = action.Disabled.Eq
|
||||||
|
}
|
||||||
|
|
||||||
|
if action.Disabled.Equal != nil {
|
||||||
|
action.Disabled.Value = action.Disabled.Equal
|
||||||
|
}
|
||||||
|
|
||||||
|
if action.Disabled.Field != "" {
|
||||||
|
action.Disabled.Bind = fmt.Sprintf("{{%s}}", action.Disabled.Field)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Syntactic sugar { "hide": ["add", "edit", "view"] }
|
// Syntactic sugar { "hide": ["add", "edit", "view"] }
|
||||||
// ["add", "edit", "view"]
|
// ["add", "edit", "view"]
|
||||||
if action.Hide != nil {
|
if action.Hide != nil {
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,30 @@ func TestActionUnmarshalJSON(t *testing.T) {
|
||||||
assert.Equal(t, "Actions.test.back", action.Action[0]["type"])
|
assert.Equal(t, "Actions.test.back", action.Action[0]["type"])
|
||||||
assert.Equal(t, "7daf632016d4d8ea77066bc54afd525e", action.ID)
|
assert.Equal(t, "7daf632016d4d8ea77066bc54afd525e", action.ID)
|
||||||
|
|
||||||
|
action = ActionDSL{}
|
||||||
|
err = jsoniter.Unmarshal(data["sugar-hide"], &action)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, false, action.ShowWhenAdd)
|
||||||
|
assert.Equal(t, false, action.ShowWhenView)
|
||||||
|
assert.Equal(t, false, action.HideWhenEdit)
|
||||||
|
|
||||||
|
action = ActionDSL{}
|
||||||
|
err = jsoniter.Unmarshal(data["sugar-disabled-eq"], &action)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, "{{data}}", action.Disabled.Bind)
|
||||||
|
assert.Equal(t, "1", action.Disabled.Value)
|
||||||
|
|
||||||
|
action = ActionDSL{}
|
||||||
|
err = jsoniter.Unmarshal(data["sugar-disabled-equal"], &action)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, "{{data}}", action.Disabled.Bind)
|
||||||
|
assert.Equal(t, "1", action.Disabled.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testActionData
|
// testActionData
|
||||||
|
|
@ -159,5 +183,40 @@ func testActionData() map[string][]byte {
|
||||||
},
|
},
|
||||||
"confirm": { "title": "Tips", "desc": "Delete Confirm" }
|
"confirm": { "title": "Tips", "desc": "Delete Confirm" }
|
||||||
}`),
|
}`),
|
||||||
|
|
||||||
|
"sugar-hide": []byte(`{
|
||||||
|
"title": "Delete",
|
||||||
|
"icon": "icon-trash-2",
|
||||||
|
"style": "danger",
|
||||||
|
"hide": ["view", "add"],
|
||||||
|
"action": {
|
||||||
|
"Actions.test.back": { "pathname": "/x/Table/env" }
|
||||||
|
},
|
||||||
|
"confirm": { "title": "Tips", "desc": "Delete Confirm" }
|
||||||
|
}`),
|
||||||
|
|
||||||
|
"sugar-disabled-eq": []byte(`{
|
||||||
|
"title": "Delete",
|
||||||
|
"icon": "icon-trash-2",
|
||||||
|
"style": "danger",
|
||||||
|
"hide": ["view", "add"],
|
||||||
|
"action": {
|
||||||
|
"Actions.test.back": { "pathname": "/x/Table/env" }
|
||||||
|
},
|
||||||
|
"confirm": { "title": "Tips", "desc": "Delete Confirm" },
|
||||||
|
"disabled": { "field":"data", "eq": "1" }
|
||||||
|
}`),
|
||||||
|
|
||||||
|
"sugar-disabled-equal": []byte(`{
|
||||||
|
"title": "Delete",
|
||||||
|
"icon": "icon-trash-2",
|
||||||
|
"style": "danger",
|
||||||
|
"hide": ["view", "add"],
|
||||||
|
"action": {
|
||||||
|
"Actions.test.back": { "pathname": "/x/Table/env" }
|
||||||
|
},
|
||||||
|
"confirm": { "title": "Tips", "desc": "Delete Confirm" },
|
||||||
|
"disabled": {"field":"data", "equal": "1" }
|
||||||
|
}`),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,10 @@ type ActionDSL struct {
|
||||||
|
|
||||||
// DisabledDSL the action disabled
|
// DisabledDSL the action disabled
|
||||||
type DisabledDSL struct {
|
type DisabledDSL struct {
|
||||||
|
Field string `json:"Field,omitempty"` // Syntactic sugar -> bind
|
||||||
Bind string `json:"bind,omitempty"`
|
Bind string `json:"bind,omitempty"`
|
||||||
|
Eq interface{} `json:"eq,omitempty"` // string | array<string> Syntactic sugar eq -> value
|
||||||
|
Equal interface{} `json:"equal,omitempty"` // string | array<string> Syntactic sugar equal -> value
|
||||||
Value interface{} `json:"value,omitempty"` // string | array<string>
|
Value interface{} `json:"value,omitempty"` // string | array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue