[add] filter & column parser
This commit is contained in:
parent
0f781ad059
commit
437a894505
3 changed files with 71 additions and 0 deletions
|
|
@ -1,10 +1,41 @@
|
|||
package field
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/yao/widgets/component"
|
||||
"github.com/yaoapp/yao/widgets/expression"
|
||||
"golang.org/x/crypto/md4"
|
||||
)
|
||||
|
||||
// UnmarshalJSON for json UnmarshalJSON
|
||||
func (column *ColumnDSL) UnmarshalJSON(data []byte) error {
|
||||
var alias aliasColumnDSL
|
||||
err := jsoniter.Unmarshal(data, &alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*column = ColumnDSL(alias)
|
||||
column.ID, err = column.Hash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hash hash value
|
||||
func (column ColumnDSL) Hash() (string, error) {
|
||||
h := md4.New()
|
||||
origin := fmt.Sprintf("%#v", column)
|
||||
// fmt.Println(origin)
|
||||
io.WriteString(h, origin)
|
||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
// Replace replace with data
|
||||
func (column ColumnDSL) Replace(data map[string]interface{}) (*ColumnDSL, error) {
|
||||
new := column
|
||||
|
|
@ -72,6 +103,7 @@ func (column *ColumnDSL) Clone() *ColumnDSL {
|
|||
// Map cast to map[string]inteface{}
|
||||
func (column ColumnDSL) Map() map[string]interface{} {
|
||||
res := map[string]interface{}{
|
||||
"id": column.ID,
|
||||
"bind": column.Bind,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,41 @@
|
|||
package field
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/yao/widgets/component"
|
||||
"github.com/yaoapp/yao/widgets/expression"
|
||||
"golang.org/x/crypto/md4"
|
||||
)
|
||||
|
||||
// UnmarshalJSON for json UnmarshalJSON
|
||||
func (filter *FilterDSL) UnmarshalJSON(data []byte) error {
|
||||
var alias aliasFilterDSL
|
||||
err := jsoniter.Unmarshal(data, &alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*filter = FilterDSL(alias)
|
||||
filter.ID, err = filter.Hash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hash hash value
|
||||
func (filter FilterDSL) Hash() (string, error) {
|
||||
h := md4.New()
|
||||
origin := fmt.Sprintf("%#v", filter)
|
||||
// fmt.Println(origin)
|
||||
io.WriteString(h, origin)
|
||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
// Replace replace with data
|
||||
func (filter FilterDSL) Replace(data map[string]interface{}) (*FilterDSL, error) {
|
||||
new := filter
|
||||
|
|
@ -42,7 +73,9 @@ func (filter *FilterDSL) Clone() *FilterDSL {
|
|||
|
||||
// Map cast to map[string]inteface{}
|
||||
func (filter FilterDSL) Map() map[string]interface{} {
|
||||
|
||||
res := map[string]interface{}{
|
||||
"id": filter.ID,
|
||||
"bind": filter.Bind,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type CloudProps map[string]component.CloudPropsDSL
|
|||
|
||||
// ColumnDSL the field column dsl
|
||||
type ColumnDSL struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Bind string `json:"bind,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
|
|
@ -25,13 +26,18 @@ type ColumnDSL struct {
|
|||
Edit *component.DSL `json:"edit,omitempty"`
|
||||
}
|
||||
|
||||
type aliasColumnDSL ColumnDSL
|
||||
|
||||
// FilterDSL the field filter dsl
|
||||
type FilterDSL struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Bind string `json:"bind,omitempty"`
|
||||
Edit *component.DSL `json:"edit,omitempty"`
|
||||
}
|
||||
|
||||
type aliasFilterDSL FilterDSL
|
||||
|
||||
// Compute the compute filed
|
||||
type Compute string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue