[add] form & table loadFieSync & fix props bug
This commit is contained in:
parent
ae4880c6dc
commit
ff2e1b4727
5 changed files with 28 additions and 3 deletions
|
|
@ -112,7 +112,14 @@ func (cProp CloudPropsDSL) replaceAny(data interface{}, root string, replace fun
|
||||||
|
|
||||||
func (cProp CloudPropsDSL) replaceMap(data map[string]interface{}, root string, replace func(cProp CloudPropsDSL) interface{}) error {
|
func (cProp CloudPropsDSL) replaceMap(data map[string]interface{}, root string, replace func(cProp CloudPropsDSL) interface{}) error {
|
||||||
xpath := fmt.Sprintf(".%s.$%s", cProp.Xpath, cProp.Name)
|
xpath := fmt.Sprintf(".%s.$%s", cProp.Xpath, cProp.Name)
|
||||||
|
|
||||||
|
// get keys
|
||||||
|
keys := []string{}
|
||||||
for key := range data {
|
for key := range data {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
path := fmt.Sprintf("%s.%s", root, key)
|
path := fmt.Sprintf("%s.%s", root, key)
|
||||||
if !strings.HasPrefix(xpath, path) {
|
if !strings.HasPrefix(xpath, path) {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou/application"
|
"github.com/yaoapp/gou/application"
|
||||||
|
|
@ -51,6 +52,7 @@ import (
|
||||||
|
|
||||||
// Forms the loaded form widgets
|
// Forms the loaded form widgets
|
||||||
var Forms map[string]*DSL = map[string]*DSL{}
|
var Forms map[string]*DSL = map[string]*DSL{}
|
||||||
|
var lock sync.Mutex
|
||||||
|
|
||||||
// New create a new DSL
|
// New create a new DSL
|
||||||
func New(id string) *DSL {
|
func New(id string) *DSL {
|
||||||
|
|
@ -94,7 +96,14 @@ func Load(cfg config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFile load table dsl by file
|
// LoadFileSync load form dsl by file
|
||||||
|
func LoadFileSync(root string, file string) error {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
return LoadFile(root, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadFile load form dsl by file
|
||||||
func LoadFile(root string, file string) error {
|
func LoadFile(root string, file string) error {
|
||||||
|
|
||||||
id := share.ID(root, file)
|
id := share.ID(root, file)
|
||||||
|
|
|
||||||
|
|
@ -191,5 +191,5 @@ func processLoad(process *gouProcess.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
file = strings.TrimPrefix(file, string(os.PathSeparator))
|
file = strings.TrimPrefix(file, string(os.PathSeparator))
|
||||||
return LoadFile("forms", file)
|
return LoadFileSync("forms", file)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,5 +318,5 @@ func processLoad(process *gouProcess.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
file = strings.TrimPrefix(file, string(os.PathSeparator))
|
file = strings.TrimPrefix(file, string(os.PathSeparator))
|
||||||
return LoadFile("tables", file)
|
return LoadFileSync("tables", file)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou/application"
|
"github.com/yaoapp/gou/application"
|
||||||
|
|
@ -81,6 +82,7 @@ import (
|
||||||
|
|
||||||
// Tables the loaded table widgets
|
// Tables the loaded table widgets
|
||||||
var Tables map[string]*DSL = map[string]*DSL{}
|
var Tables map[string]*DSL = map[string]*DSL{}
|
||||||
|
var lock sync.Mutex
|
||||||
|
|
||||||
// New create a new DSL
|
// New create a new DSL
|
||||||
func New(id string) *DSL {
|
func New(id string) *DSL {
|
||||||
|
|
@ -144,6 +146,13 @@ func LoadID(id string, root string) error {
|
||||||
return fmt.Errorf("table %s not found", id)
|
return fmt.Errorf("table %s not found", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadFileSync load table dsl by file
|
||||||
|
func LoadFileSync(root string, file string) error {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
return LoadFile(root, file)
|
||||||
|
}
|
||||||
|
|
||||||
// LoadFile load table dsl by file
|
// LoadFile load table dsl by file
|
||||||
func LoadFile(root string, file string) error {
|
func LoadFile(root string, file string) error {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue