Skip to content

Commit

Permalink
Merge pull request YaoApp#413 from trheyi/main
Browse files Browse the repository at this point in the history
[add] form & table loadFieSync & fix props bug
  • Loading branch information
trheyi authored May 13, 2023
2 parents b86c84d + ff2e1b4 commit fada127
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions widgets/component/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion widgets/form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"
"sync"

jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion widgets/form/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion widgets/table/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 9 additions & 0 deletions widgets/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"
"sync"

jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {

Expand Down

0 comments on commit fada127

Please sign in to comment.