Skip to content

Commit

Permalink
Merge pull request #772 from trheyi/main
Browse files Browse the repository at this point in the history
Add color field support to QueryProp and Option structures
  • Loading branch information
trheyi authored Nov 4, 2024
2 parents de630d8 + 35f16e1 commit a9182c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions widgets/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var BackendOnlyProps = map[string]map[string]map[string]interface{}{
},
},
},
"tag": {
"query": {
"xProps": map[string]interface{}{
"$remote": map[string]interface{}{"process": "yao.component.GetOptions"},
},
},
},
"autocomplete": {"query": {
"xProps": map[string]interface{}{
"$remote": map[string]interface{}{"process": "yao.component.GetOptions"},
Expand Down
15 changes: 15 additions & 0 deletions widgets/component/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ type QueryProp struct {
LabelField string `json:"labelField,omitempty"`
ValueField string `json:"valueField,omitempty"`
IconField string `json:"iconField,omitempty"`
ColorField string `json:"colorField,omitempty"`
LabelFormat string `json:"labelFormat,omitempty"`
ValueFormat string `json:"valueFormat,omitempty"`
IconFormat string `json:"iconFormat,omitempty"`
ColorFormat string `json:"colorFormat,omitempty"`
Wheres []map[string]interface{} `json:"wheres,omitempty"`
param model.QueryParam
dsl map[string]interface{}
Expand All @@ -37,6 +39,7 @@ type Option struct {
Label string `json:"label"`
Value interface{} `json:"value"`
Icon string `json:"icon,omitempty"`
Color string `json:"color,omitempty"`
}

// Export process
Expand Down Expand Up @@ -177,6 +180,10 @@ func (q *QueryProp) format(options *[]Option, row map[string]interface{}) {
option.Icon = fmt.Sprintf("%v", row[q.IconField])
}

if q.ColorField != "" {
option.Color = fmt.Sprintf("%v", row[q.ColorField])
}

if q.LabelFormat != "" {
option.Label = q.replaceString(q.LabelFormat, row)
}
Expand All @@ -189,6 +196,10 @@ func (q *QueryProp) format(options *[]Option, row map[string]interface{}) {
option.Icon = q.replaceString(q.IconFormat, row)
}

if q.ColorField != "" && q.ColorFormat != "" {
option.Color = q.replaceString(q.ColorFormat, row)
}

// Update the option
*options = append(*options, option)
}
Expand Down Expand Up @@ -259,6 +270,10 @@ func (q *QueryProp) parse(query map[string]interface{}) error {
q.param.Select = append(q.param.Select, q.IconField)
}

if q.ColorField != "" {
q.param.Select = append(q.param.Select, q.ColorField)
}

raw, err := jsoniter.Marshal(props)
if err != nil {
return err
Expand Down

0 comments on commit a9182c5

Please sign in to comment.