[change] componet setting
This commit is contained in:
parent
21b2105802
commit
a57d13e49e
8 changed files with 37 additions and 19 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
package component
|
package component
|
||||||
|
|
||||||
|
import (
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
// process
|
// process
|
||||||
// yao.component.TagView
|
// yao.component.TagView
|
||||||
// yao.component.TagEdit
|
// yao.component.TagEdit
|
||||||
|
|
@ -12,19 +16,27 @@ func Export() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON Custom JSON parse
|
||||||
|
func (dsl DSL) MarshalJSON() ([]byte, error) {
|
||||||
|
return jsoniter.Marshal(dsl.Map())
|
||||||
|
}
|
||||||
|
|
||||||
// Map cast to map[string]interface{}
|
// Map cast to map[string]interface{}
|
||||||
func (dsl DSL) Map() map[string]interface{} {
|
func (dsl DSL) Map() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
res := map[string]interface{}{
|
||||||
"type": dsl.Type,
|
"type": dsl.Type,
|
||||||
"in": dsl.In,
|
|
||||||
"out": dsl.Out,
|
|
||||||
"props": map[string]interface{}(dsl.Props),
|
"props": map[string]interface{}(dsl.Props),
|
||||||
}
|
}
|
||||||
|
if dsl.Bind != "" {
|
||||||
|
res["bind"] = dsl.Bind
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone Component
|
// Clone Component
|
||||||
func (dsl *DSL) Clone() *DSL {
|
func (dsl *DSL) Clone() *DSL {
|
||||||
new := DSL{
|
new := DSL{
|
||||||
|
Bind: dsl.Bind,
|
||||||
Type: dsl.Type,
|
Type: dsl.Type,
|
||||||
In: dsl.In,
|
In: dsl.In,
|
||||||
Out: dsl.Out,
|
Out: dsl.Out,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package component
|
||||||
|
|
||||||
// DSL the component DSL
|
// DSL the component DSL
|
||||||
type DSL struct {
|
type DSL struct {
|
||||||
|
Bind string `json:"bind,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
In string `json:"in,omitempty"`
|
In string `json:"in,omitempty"`
|
||||||
Out string `json:"out,omitempty"`
|
Out string `json:"out,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -61,11 +61,13 @@ func (column *ColumnDSL) Clone() *ColumnDSL {
|
||||||
// Map cast to map[string]inteface{}
|
// Map cast to map[string]inteface{}
|
||||||
func (column ColumnDSL) Map() map[string]interface{} {
|
func (column ColumnDSL) Map() map[string]interface{} {
|
||||||
res := map[string]interface{}{
|
res := map[string]interface{}{
|
||||||
"key": column.Key,
|
|
||||||
"link": column.Link,
|
|
||||||
"bind": column.Bind,
|
"bind": column.Bind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if column.Link != "" {
|
||||||
|
res["link"] = column.Link
|
||||||
|
}
|
||||||
|
|
||||||
if column.View != nil {
|
if column.View != nil {
|
||||||
res["view"] = column.View.Map()
|
res["view"] = column.View.Map()
|
||||||
}
|
}
|
||||||
|
|
@ -109,20 +111,20 @@ func (columns Columns) ComputeFieldsMerge(computeInFields map[string]string, com
|
||||||
|
|
||||||
// Compute In
|
// Compute In
|
||||||
if column.In != "" {
|
if column.In != "" {
|
||||||
if !strings.Contains(column.In, ".") {
|
if !strings.Contains(string(column.In), ".") {
|
||||||
column.In = fmt.Sprintf("yao.component.%s", column.In)
|
column.In = Compute(fmt.Sprintf("yao.component.%s", column.In))
|
||||||
}
|
}
|
||||||
computeInFields[column.Bind] = column.In
|
computeInFields[column.Bind] = string(column.In)
|
||||||
computeInFields[name] = column.In
|
computeInFields[name] = string(column.In)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Out
|
// Compute Out
|
||||||
if column.Out != "" {
|
if column.Out != "" {
|
||||||
if !strings.Contains(column.Out, ".") {
|
if !strings.Contains(string(column.Out), ".") {
|
||||||
column.In = fmt.Sprintf("yao.component.%s", column.Out)
|
column.In = Compute(fmt.Sprintf("yao.component.%s", column.Out))
|
||||||
}
|
}
|
||||||
computeOutFields[column.Bind] = column.Out
|
computeOutFields[column.Bind] = string(column.Out)
|
||||||
computeOutFields[name] = column.Out
|
computeOutFields[name] = string(column.Out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ func (filter *FilterDSL) Clone() *FilterDSL {
|
||||||
// Map cast to map[string]inteface{}
|
// Map cast to map[string]inteface{}
|
||||||
func (filter FilterDSL) Map() map[string]interface{} {
|
func (filter FilterDSL) Map() map[string]interface{} {
|
||||||
res := map[string]interface{}{
|
res := map[string]interface{}{
|
||||||
"key": filter.Key,
|
|
||||||
"bind": filter.Bind,
|
"bind": filter.Bind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ type ColumnDSL struct {
|
||||||
Key string `json:"key,omitempty"`
|
Key string `json:"key,omitempty"`
|
||||||
Bind string `json:"bind,omitempty"`
|
Bind string `json:"bind,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
Link string `json:"link,omitempty"`
|
||||||
In string `json:"in,omitempty"`
|
In Compute `json:"in,omitempty"`
|
||||||
Out string `json:"out,omitempty"`
|
Out Compute `json:"out,omitempty"`
|
||||||
View *component.DSL `json:"view,omitempty"`
|
View *component.DSL `json:"view,omitempty"`
|
||||||
Edit *component.DSL `json:"edit,omitempty"`
|
Edit *component.DSL `json:"edit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
@ -34,6 +34,9 @@ type FilterDSL struct {
|
||||||
Edit *component.DSL `json:"edit,omitempty"`
|
Edit *component.DSL `json:"edit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute the compute filed
|
||||||
|
type Compute string
|
||||||
|
|
||||||
// Transform the field transform
|
// Transform the field transform
|
||||||
type Transform struct {
|
type Transform struct {
|
||||||
Variables map[string]interface{} `json:"variables,omitempty"`
|
Variables map[string]interface{} `json:"variables,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
||||||
|
|
||||||
filters := map[string]interface{}{}
|
filters := map[string]interface{}{}
|
||||||
tables := map[string]interface{}{}
|
tables := map[string]interface{}{}
|
||||||
|
|
||||||
if layout.Filter != nil {
|
if layout.Filter != nil {
|
||||||
for i, f := range layout.Filter.Columns {
|
for i, f := range layout.Filter.Columns {
|
||||||
name := f.Name
|
name := f.Name
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ func TestFiledsBindModel(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, "id", tab.Fields.Table["ID"].Bind)
|
assert.Equal(t, "id", tab.Fields.Table["ID"].Bind)
|
||||||
assert.Equal(t, 15, len(tab.Fields.Table))
|
assert.Equal(t, 17, len(tab.Fields.Table))
|
||||||
assert.Equal(t, 4, len(tab.Fields.Filter))
|
assert.Equal(t, 6, len(tab.Fields.Filter))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func TestLoad(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, 9, len(Tables))
|
assert.Equal(t, 10, len(Tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadID(t *testing.T) {
|
func TestLoadID(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue