Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color field support to QueryProp and Option structures #772

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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