Update list action and API to include additional parameters
This commit is contained in:
parent
bba0119a95
commit
5202f4cca3
5 changed files with 54 additions and 10 deletions
|
|
@ -13,7 +13,7 @@ var processActionDefaults = map[string]*action.Process{
|
|||
Name: "yao.list.Setting",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "yao.list.Xgen",
|
||||
Default: []interface{}{nil},
|
||||
Default: []interface{}{nil, nil},
|
||||
},
|
||||
"Component": {
|
||||
Name: "yao.list.Component",
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func exportAPI() error {
|
|||
Path: "/:id/setting",
|
||||
Method: "GET",
|
||||
Process: "yao.list.Setting",
|
||||
In: []interface{}{"$param.id"},
|
||||
In: []interface{}{"$param.id", ":query"},
|
||||
Out: api.Out{Status: 200, Type: "application/json"},
|
||||
}
|
||||
http.Paths = append(http.Paths, path)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou/helper"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/yao/widgets/table"
|
||||
)
|
||||
|
||||
|
|
@ -88,10 +90,15 @@ func (fields *FieldsDSL) BindTable(tab *table.DSL) error {
|
|||
}
|
||||
|
||||
// Xgen trans to xgen setting
|
||||
func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error) {
|
||||
func (fields *FieldsDSL) Xgen(layout *LayoutDSL, query map[string]interface{}) (map[string]interface{}, error) {
|
||||
res := map[string]interface{}{}
|
||||
lists := map[string]interface{}{}
|
||||
messages := []string{}
|
||||
replacements := maps.Map{}
|
||||
if query != nil {
|
||||
replacements = maps.Of(map[string]interface{}{"$parent": query}).Dot()
|
||||
}
|
||||
|
||||
if layout.List != nil && layout.List.Columns != nil {
|
||||
|
||||
for i, f := range layout.List.Columns {
|
||||
|
|
@ -114,9 +121,20 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
|||
if _, has := field.Edit.Props["$on:change"]; has {
|
||||
delete(field.Edit.Props, "$on:change")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lists[name] = field.Map()
|
||||
|
||||
// Bind Parent Data
|
||||
if query != nil {
|
||||
if field.Edit != nil && field.Edit.Props != nil {
|
||||
lists[name] = helper.Bind(lists[name], replacements)
|
||||
}
|
||||
if field.View != nil && field.View.Props != nil {
|
||||
lists[name] = helper.Bind(lists[name], replacements)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ import (
|
|||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/helper"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/widgets/component"
|
||||
|
|
@ -197,7 +199,7 @@ func MustGet(list interface{}) *DSL {
|
|||
}
|
||||
|
||||
// Xgen trans to xgen setting
|
||||
func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map[string]interface{}, error) {
|
||||
func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool, query map[string]interface{}) (map[string]interface{}, error) {
|
||||
|
||||
if dsl.Layout == nil {
|
||||
dsl.Layout = &LayoutDSL{List: &ViewLayoutDSL{}}
|
||||
|
|
@ -212,7 +214,7 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map
|
|||
return nil, err
|
||||
}
|
||||
|
||||
fields, err := dsl.Fields.Xgen(layout)
|
||||
fields, err := dsl.Fields.Xgen(layout, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -236,9 +238,20 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map
|
|||
onChange := map[string]interface{}{} // Hooks
|
||||
setting["fields"] = fields
|
||||
setting["config"] = dsl.Config
|
||||
|
||||
replacements := maps.Map{}
|
||||
if query != nil {
|
||||
replacements = maps.Of(map[string]interface{}{"$parent": query}).Dot()
|
||||
}
|
||||
|
||||
for _, cProp := range dsl.CProps {
|
||||
err := cProp.Replace(setting, func(cProp component.CloudPropsDSL) interface{} {
|
||||
|
||||
if query != nil { // Replace Query
|
||||
newQuery := helper.Bind(cProp.Query, replacements)
|
||||
cProp.Query = newQuery.(map[string]interface{})
|
||||
}
|
||||
|
||||
if cProp.Type == "Upload" {
|
||||
return fmt.Sprintf("/api/__yao/list/%s%s", dsl.ID, cProp.UploadPath())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,14 @@ func exportProcess() {
|
|||
}
|
||||
|
||||
func processXgen(process *gouProcess.Process) interface{} {
|
||||
|
||||
list := MustGet(process)
|
||||
data := process.ArgsMap(1, map[string]interface{}{})
|
||||
query := process.ArgsMap(1, map[string]interface{}{})
|
||||
data := process.ArgsMap(2, map[string]interface{}{})
|
||||
excludes := app.Permissions(process, "lists", list.ID)
|
||||
setting, err := list.Xgen(data, excludes)
|
||||
setting, err := list.Xgen(data, excludes, query)
|
||||
if err != nil {
|
||||
exception.New(err.Error(), 500).Throw()
|
||||
}
|
||||
|
||||
return setting
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +146,21 @@ func processUpload(process *gouProcess.Process) interface{} {
|
|||
|
||||
func processSetting(process *gouProcess.Process) interface{} {
|
||||
list := MustGet(process)
|
||||
process.Args = append(process.Args, process.Args[0]) // list name
|
||||
name := process.ArgsString(0)
|
||||
params := process.ArgsMap(1, map[string]interface{}{})
|
||||
query := map[string]string{}
|
||||
for key, value := range params {
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
query[key] = v
|
||||
case []string:
|
||||
query[key] = strings.Join(v, ",")
|
||||
default:
|
||||
query[key] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
|
||||
process.Args = []interface{}{name, name, query} // list name
|
||||
return list.Action.Setting.MustExec(process)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue