Skip to content

Fix the UI display problem of FilterOperatorLike while maintaining the function of correctly generating Like sql statements #661

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion plugins/admin/modules/parameter/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ var operators = map[string]string{
"free": "free",
}

// Global registry for Like operator fields
var likeOperatorFields = make(map[string]bool)

// RegisterLikeOperatorField registers a field as using the Like operator
func RegisterLikeOperatorField(fieldName string) {
likeOperatorFields[fieldName] = true
}

// IsLikeOperatorField checks if a field is registered as using the Like operator
func IsLikeOperatorField(fieldName string) bool {
return likeOperatorFields[fieldName]
}

var keys = []string{Page, PageSize, Sort, Columns, Prefix, Pjax, form.NoAnimationKey}

func BaseParam() Parameters {
Expand Down Expand Up @@ -402,7 +415,11 @@ func (param Parameters) Statement(wheres, table, delimiter, delimiter2 string, w
} else if len(value) > 1 {
op = "in"
} else if !strings.Contains(key, FilterParamOperatorSuffix) {
op = operators[param.GetFieldOperator(key, keyIndexSuffix)]
if IsLikeOperatorField(key) {
op = "like"
} else {
op = operators[param.GetFieldOperator(key, keyIndexSuffix)]
}
} else {
continue
}
Expand Down
5 changes: 5 additions & 0 deletions template/types/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ func (f Field) GetFilterFormFields(params parameter.Parameters, headField string
keySuffix = parameter.FilterParamCountInfix + strconv.Itoa(index)
}

// Register Like operator fields for global tracking
if filter.Operator == FilterOperatorLike {
parameter.RegisterLikeOperatorField(headField)
}

if filter.Type.IsRange() {
value = params.GetFilterFieldValueStart(headField)
value2 = params.GetFilterFieldValueEnd(headField)
Expand Down