Refactor bind logic in DSL

This commit is contained in:
Max 2024-04-02 12:29:27 +08:00
parent dff977590b
commit edad2e76f3
2 changed files with 27 additions and 21 deletions

View file

@ -10,23 +10,27 @@ import (
// Bind model / store / table / ...
func (dsl *DSL) Bind() error {
if dsl.Action.Bind == nil {
return nil
}
if dsl.Action.Bind.Model != "" {
return dsl.bindModel()
}
if dsl.Action.Bind.Store != "" {
return dsl.bindStore()
}
if dsl.Action.Bind.Table != "" {
return dsl.bindTable()
}
// Support bind in future version
return nil
// if dsl.Action.Bind == nil {
// return nil
// }
// if dsl.Action.Bind.Model != "" {
// return dsl.bindModel()
// }
// if dsl.Action.Bind.Store != "" {
// return dsl.bindStore()
// }
// if dsl.Action.Bind.Table != "" {
// return dsl.bindTable()
// }
// return nil
}
func (dsl *DSL) bindModel() error {

View file

@ -104,13 +104,15 @@ func (dsl *DSL) translate(name string, process *gouProcess.Process, data interfa
}
widgets := []string{}
if dsl.Action.Bind.Model != "" {
m := model.Select(dsl.Action.Bind.Model)
widgets = append(widgets, fmt.Sprintf("model.%s", m.ID))
}
if dsl.Action.Bind != nil {
if dsl.Action.Bind.Model != "" {
m := model.Select(dsl.Action.Bind.Model)
widgets = append(widgets, fmt.Sprintf("model.%s", m.ID))
}
if dsl.Action.Bind.Table != "" {
widgets = append(widgets, fmt.Sprintf("table.%s", dsl.Action.Bind.Table))
if dsl.Action.Bind.Table != "" {
widgets = append(widgets, fmt.Sprintf("table.%s", dsl.Action.Bind.Table))
}
}
widgets = append(widgets, fmt.Sprintf("list.%s", dsl.ID))