[add] widget compute $C(id)
This commit is contained in:
parent
0300f74311
commit
7320b7a5b6
6 changed files with 35 additions and 32 deletions
|
|
@ -7,23 +7,23 @@ import (
|
|||
"github.com/yaoapp/yao/widgets/field"
|
||||
)
|
||||
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, error) {
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, string, error) {
|
||||
field, has := dsl.Fields.Chart[name]
|
||||
if !has {
|
||||
return nil, "fields.chart", fmt.Errorf("fields.chart.%s does not exist", name)
|
||||
return nil, "fields.chart", dsl.ID, fmt.Errorf("fields.chart.%s does not exist", name)
|
||||
}
|
||||
return &field, "fields.chart", nil
|
||||
return &field, "fields.chart", dsl.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (dsl *DSL) getFilter() func(string) (*field.FilterDSL, string, error) {
|
||||
return func(name string) (*field.FilterDSL, string, error) {
|
||||
func (dsl *DSL) getFilter() func(string) (*field.FilterDSL, string, string, error) {
|
||||
return func(name string) (*field.FilterDSL, string, string, error) {
|
||||
field, has := dsl.Fields.Filter[name]
|
||||
if !has {
|
||||
return nil, "fields.filter", fmt.Errorf("fields.filter.%s does not exist", name)
|
||||
return nil, "fields.filter", dsl.ID, fmt.Errorf("fields.filter.%s does not exist", name)
|
||||
}
|
||||
return &field, "fields.filter", nil
|
||||
return &field, "fields.filter", dsl.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ var defaults = []CArg{
|
|||
{IsExp: true, key: "value", value: nil},
|
||||
{IsExp: true, key: "props", value: nil},
|
||||
{IsExp: true, key: "type", value: nil},
|
||||
{IsExp: true, key: "id", value: nil},
|
||||
}
|
||||
|
||||
// Value compute value
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
var views = map[string]bool{"find": true, "get": true, "search": true, "data": true}
|
||||
|
||||
// ComputeEdit edit compute edit
|
||||
func (c *Computable) ComputeEdit(name string, process *gou.Process, args []interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) ComputeEdit(name string, process *gou.Process, args []interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
namer := strings.Split(strings.ToLower(name), ".")
|
||||
name = namer[len(namer)-1]
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ func (c *Computable) ComputeEdit(name string, process *gou.Process, args []inter
|
|||
}
|
||||
|
||||
// EditRow edit row
|
||||
func (c *Computable) editRow(process *gou.Process, res map[string]interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) editRow(process *gou.Process, res map[string]interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
|
||||
messages := []string{}
|
||||
row := maps.MapOf(res).Dot()
|
||||
|
|
@ -94,12 +94,13 @@ func (c *Computable) editRow(process *gou.Process, res map[string]interface{}, g
|
|||
for key := range res {
|
||||
if computes, has := c.Computes.Edit[key]; has {
|
||||
unit := computes[0]
|
||||
field, path, err := getField(unit.Name)
|
||||
field, path, id, err := getField(unit.Name)
|
||||
if err != nil {
|
||||
messages = append(messages, err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
data.Set("id", id)
|
||||
data.Set("value", res[key])
|
||||
data.Merge(any.MapOf(field.Edit.Map()).MapStrAny.Dot())
|
||||
new, err := field.Edit.Compute.Value(data, process.Sid, process.Global)
|
||||
|
|
@ -119,7 +120,7 @@ func (c *Computable) editRow(process *gou.Process, res map[string]interface{}, g
|
|||
}
|
||||
|
||||
// EditRows edit row
|
||||
func (c *Computable) editRows(process *gou.Process, columns []string, res [][]interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) editRows(process *gou.Process, columns []string, res [][]interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
|
||||
messages := []string{}
|
||||
keys := map[string]int{}
|
||||
|
|
@ -155,7 +156,7 @@ func (c *Computable) editRows(process *gou.Process, columns []string, res [][]in
|
|||
}
|
||||
|
||||
// ComputeView view view
|
||||
func (c *Computable) ComputeView(name string, process *gou.Process, res interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) ComputeView(name string, process *gou.Process, res interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
|
||||
namer := strings.Split(strings.ToLower(name), ".")
|
||||
name = namer[len(namer)-1]
|
||||
|
|
@ -178,7 +179,7 @@ func (c *Computable) ComputeView(name string, process *gou.Process, res interfac
|
|||
}
|
||||
|
||||
// ViewRows viewrows
|
||||
func (c *Computable) viewRows(name string, process *gou.Process, res interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) viewRows(name string, process *gou.Process, res interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
switch res.(type) {
|
||||
|
||||
case []interface{}:
|
||||
|
|
@ -212,7 +213,7 @@ func (c *Computable) viewRows(name string, process *gou.Process, res interface{}
|
|||
}
|
||||
|
||||
// ViewRow row
|
||||
func (c *Computable) viewRow(name string, process *gou.Process, res map[string]interface{}, getField func(string) (*field.ColumnDSL, string, error)) error {
|
||||
func (c *Computable) viewRow(name string, process *gou.Process, res map[string]interface{}, getField func(string) (*field.ColumnDSL, string, string, error)) error {
|
||||
|
||||
messages := []string{}
|
||||
row := maps.MapOf(res).Dot()
|
||||
|
|
@ -234,13 +235,14 @@ func (c *Computable) viewRow(name string, process *gou.Process, res map[string]i
|
|||
|
||||
for key, computes := range c.Computes.View {
|
||||
unit := computes[0]
|
||||
field, path, err := getField(unit.Name)
|
||||
field, path, id, err := getField(unit.Name)
|
||||
if err != nil {
|
||||
messages = append(messages, err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
data.Set("value", res[key])
|
||||
data.Set("id", id)
|
||||
data.Merge(any.MapOf(field.View.Map()).MapStrAny.Dot())
|
||||
new, err := field.View.Compute.Value(data, process.Sid, process.Global)
|
||||
if err != nil {
|
||||
|
|
@ -259,6 +261,6 @@ func (c *Computable) viewRow(name string, process *gou.Process, res map[string]i
|
|||
}
|
||||
|
||||
// ComputeFilter filter
|
||||
func (c *Computable) ComputeFilter(name string, process *gou.Process, args []interface{}, getFilter func(string) (*field.FilterDSL, string, error)) error {
|
||||
func (c *Computable) ComputeFilter(name string, process *gou.Process, args []interface{}, getFilter func(string) (*field.FilterDSL, string, string, error)) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import (
|
|||
"github.com/yaoapp/yao/widgets/field"
|
||||
)
|
||||
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, error) {
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, string, error) {
|
||||
field, has := dsl.Fields.Form[name]
|
||||
if !has {
|
||||
return nil, "fields.table", fmt.Errorf("fields.table.%s does not exist", name)
|
||||
return nil, "fields.table", dsl.ID, fmt.Errorf("fields.table.%s does not exist", name)
|
||||
}
|
||||
return &field, "fields.table", nil
|
||||
return &field, "fields.table", dsl.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,23 +7,23 @@ import (
|
|||
"github.com/yaoapp/yao/widgets/field"
|
||||
)
|
||||
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, error) {
|
||||
func (dsl *DSL) getField() func(string) (*field.ColumnDSL, string, string, error) {
|
||||
return func(name string) (*field.ColumnDSL, string, string, error) {
|
||||
field, has := dsl.Fields.Table[name]
|
||||
if !has {
|
||||
return nil, "fields.table", fmt.Errorf("fields.table.%s does not exist", name)
|
||||
return nil, "fields.table", dsl.ID, fmt.Errorf("fields.table.%s does not exist", name)
|
||||
}
|
||||
return &field, "fields.table", nil
|
||||
return &field, "fields.table", dsl.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (dsl *DSL) getFilter() func(string) (*field.FilterDSL, string, error) {
|
||||
return func(name string) (*field.FilterDSL, string, error) {
|
||||
func (dsl *DSL) getFilter() func(string) (*field.FilterDSL, string, string, error) {
|
||||
return func(name string) (*field.FilterDSL, string, string, error) {
|
||||
field, has := dsl.Fields.Filter[name]
|
||||
if !has {
|
||||
return nil, "fields.filter", fmt.Errorf("fields.filter.%s does not exist", name)
|
||||
return nil, "fields.filter", dsl.ID, fmt.Errorf("fields.filter.%s does not exist", name)
|
||||
}
|
||||
return &field, "fields.filter", nil
|
||||
return &field, "fields.filter", dsl.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func TestComputeFind(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
data := any.Of(res).MapStr().Dot()
|
||||
assert.Equal(t, "cat::Cookie-checked", data.Get("name_view"))
|
||||
assert.Equal(t, "cat::Cookie-checked-compute", data.Get("name_view"))
|
||||
}
|
||||
|
||||
func TestComputeGet(t *testing.T) {
|
||||
|
|
@ -57,7 +57,7 @@ func TestComputeGet(t *testing.T) {
|
|||
}
|
||||
arr := any.Of(res).CArray()
|
||||
data := any.Of(arr[0]).MapStr().Dot()
|
||||
assert.Equal(t, "cat::Cookie-checked", data.Get("name_view"))
|
||||
assert.Equal(t, "cat::Cookie-checked-compute", data.Get("name_view"))
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ func TestComputeSearch(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
data := any.Of(res).MapStr().Dot()
|
||||
assert.Equal(t, "cat::Cookie-checked", data.Get("data.0.name_view"))
|
||||
assert.Equal(t, "cat::Cookie-checked-compute", data.Get("data.0.name_view"))
|
||||
}
|
||||
|
||||
func TestComputeSave(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue