🎨 Database template columns support number filter Fix https://github.com/siyuan-note/siyuan/issues/9414

This commit is contained in:
Daniel 2023-10-12 17:15:36 +08:00
parent 01670f2b00
commit 8fb35f5565
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -474,6 +474,65 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
return 0 != len(value.MAsset) && !(1 == len(value.MAsset) && "" == value.MAsset[0].Content) return 0 != len(value.MAsset) && !(1 == len(value.MAsset) && "" == value.MAsset[0].Content)
} }
} }
if nil != value.Template && nil != other.Template {
switch operator {
case FilterOperatorIsEqual:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content == other.Template.Content
case FilterOperatorIsNotEqual:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content != other.Template.Content
case FilterOperatorIsGreater:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content > other.Template.Content
case FilterOperatorIsGreaterOrEqual:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content >= other.Template.Content
case FilterOperatorIsLess:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content < other.Template.Content
case FilterOperatorIsLessOrEqual:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return value.Template.Content <= other.Template.Content
case FilterOperatorContains:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return strings.Contains(value.Template.Content, other.Template.Content)
case FilterOperatorDoesNotContain:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return !strings.Contains(value.Template.Content, other.Template.Content)
case FilterOperatorStartsWith:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return strings.HasPrefix(value.Template.Content, other.Template.Content)
case FilterOperatorEndsWith:
if "" == strings.TrimSpace(other.Template.Content) {
return true
}
return strings.HasSuffix(value.Template.Content, other.Template.Content)
case FilterOperatorIsEmpty:
return "" == strings.TrimSpace(value.Template.Content)
case FilterOperatorIsNotEmpty:
return "" != strings.TrimSpace(value.Template.Content)
}
}
return true return true
} }