Merge pull request #413 from trheyi/main

[add] form & table loadFieSync & fix props bug
This commit is contained in:
Max 2023-05-13 20:39:51 +08:00 committed by GitHub
commit fada1277e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 3 deletions

View file

@ -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 {
xpath := fmt.Sprintf(".%s.$%s", cProp.Xpath, cProp.Name)
// get keys
keys := []string{}
for key := range data {
keys = append(keys, key)
}
for _, key := range keys {
path := fmt.Sprintf("%s.%s", root, key)
if !strings.HasPrefix(xpath, path) {
continue

View file

@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"
"sync"
jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
@ -51,6 +52,7 @@ import (
// Forms the loaded form widgets
var Forms map[string]*DSL = map[string]*DSL{}
var lock sync.Mutex
// New create a new DSL
func New(id string) *DSL {
@ -94,7 +96,14 @@ func Load(cfg config.Config) error {
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 {
id := share.ID(root, file)

View file

@ -191,5 +191,5 @@ func processLoad(process *gouProcess.Process) interface{} {
}
file = strings.TrimPrefix(file, string(os.PathSeparator))
return LoadFile("forms", file)
return LoadFileSync("forms", file)
}

View file

@ -318,5 +318,5 @@ func processLoad(process *gouProcess.Process) interface{} {
}
file = strings.TrimPrefix(file, string(os.PathSeparator))
return LoadFile("tables", file)
return LoadFileSync("tables", file)
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"
"sync"
jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
@ -81,6 +82,7 @@ import (
// Tables the loaded table widgets
var Tables map[string]*DSL = map[string]*DSL{}
var lock sync.Mutex
// New create a new 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)
}
// 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
func LoadFile(root string, file string) error {