Merge pull request #212 from trheyi/main
[change] widget table filter.actions
This commit is contained in:
commit
cf7a8a64fd
7 changed files with 58 additions and 20 deletions
|
|
@ -24,6 +24,7 @@ type InstanceDSL struct {
|
|||
// ActionDSL the component action DSL
|
||||
type ActionDSL struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Style string `json:"style,omitempty"`
|
||||
Props PropsDSL `json:"props,omitempty"`
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/widgets/action"
|
||||
)
|
||||
|
||||
|
|
@ -196,5 +198,26 @@ func processHandler(p *action.Process, process *gou.Process) (interface{}, error
|
|||
}
|
||||
}
|
||||
|
||||
// Tranlate
|
||||
if p.Name == "yao.form.Setting" {
|
||||
|
||||
widgets := []string{}
|
||||
if form.Action.Bind.Model != "" {
|
||||
m := gou.Select(form.Action.Bind.Model)
|
||||
widgets = append(widgets, fmt.Sprintf("model.%s", m.ID))
|
||||
}
|
||||
|
||||
if form.Action.Bind.Table != "" {
|
||||
widgets = append(widgets, fmt.Sprintf("table.%s", form.Action.Bind.Table))
|
||||
}
|
||||
|
||||
widgets = append(widgets, fmt.Sprintf("form.%s", form.ID))
|
||||
res, err = i18n.Trans(process.Lang(config.Conf.Lang), widgets, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[form] Trans.table.%s %s", form.ID, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/lang"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
|
|
@ -129,11 +128,6 @@ func LoadFrom(dir string, prefix string) error {
|
|||
return
|
||||
}
|
||||
|
||||
// Apply a language pack
|
||||
if lang.Default != nil {
|
||||
lang.Default.Apply(dsl)
|
||||
}
|
||||
|
||||
Forms[id] = dsl
|
||||
})
|
||||
|
||||
|
|
@ -211,5 +205,6 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
setting["name"] = dsl.Name
|
||||
return setting, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package form
|
||||
|
||||
// Lang for applying a language pack
|
||||
func (dsl *DSL) Lang(trans func(widget string, inst string, value *string) bool) {
|
||||
widget := "form"
|
||||
trans(widget, dsl.ID, &dsl.Name)
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package table
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/widgets/field"
|
||||
|
|
@ -84,21 +85,37 @@ func (fields *FieldsDSL) Xgen(layout *LayoutDSL) (map[string]interface{}, error)
|
|||
tables := map[string]interface{}{}
|
||||
if layout.Filter != nil {
|
||||
for i, f := range layout.Filter.Columns {
|
||||
field, has := fields.Filter[f.Name]
|
||||
name := f.Name
|
||||
field, has := fields.Filter[name]
|
||||
if !has {
|
||||
if strings.HasPrefix(f.Name, "::") {
|
||||
name = fmt.Sprintf("$L(%s)", strings.TrimPrefix(f.Name, "::"))
|
||||
if field, has = fields.Filter[name]; has {
|
||||
filters[name] = field.Map()
|
||||
continue
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("fields.filter.%s not found, checking layout.filter.columns.%d.name", f.Name, i)
|
||||
}
|
||||
filters[f.Name] = field.Map()
|
||||
filters[name] = field.Map()
|
||||
}
|
||||
}
|
||||
|
||||
if layout.Table != nil {
|
||||
for i, f := range layout.Table.Columns {
|
||||
field, has := fields.Table[f.Name]
|
||||
name := f.Name
|
||||
field, has := fields.Table[name]
|
||||
if !has {
|
||||
if strings.HasPrefix(f.Name, "::") {
|
||||
name = fmt.Sprintf("$L(%s)", strings.TrimPrefix(f.Name, "::"))
|
||||
if field, has = fields.Table[name]; has {
|
||||
tables[name] = field.Map()
|
||||
continue
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("fields.table.%s not found, checking layout.table.columns.%d.name", f.Name, i)
|
||||
}
|
||||
tables[f.Name] = field.Map()
|
||||
tables[name] = field.Map()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,16 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
|
|||
|
||||
layout.Filter = &FilterLayoutDSL{Columns: component.Instances{}}
|
||||
if hasForm {
|
||||
layout.Filter.BtnAddText = "创建"
|
||||
layout.Filter.Actions = component.Actions{
|
||||
{
|
||||
Title: "::Create",
|
||||
Icon: "icon-plus",
|
||||
Width: 3,
|
||||
Action: map[string]component.ParamsDSL{
|
||||
"Common.historyPush": {"pathname": fmt.Sprintf("/x/Form/%s/0/edit", formName)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
max := 3
|
||||
|
|
|
|||
|
|
@ -112,8 +112,8 @@ type OperationImportDSL struct {
|
|||
|
||||
// FilterLayoutDSL layout.filter
|
||||
type FilterLayoutDSL struct {
|
||||
BtnAddText string `json:"btnAddText,omitempty"`
|
||||
Columns component.Instances `json:"columns,omitempty"`
|
||||
Actions component.Actions `json:"actions,omitempty"`
|
||||
Columns component.Instances `json:"columns,omitempty"`
|
||||
}
|
||||
|
||||
// ViewLayoutDSL layout.table
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue