mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
🎨 Improve handling of database column filters containing empty values Fix https://github.com/siyuan-note/siyuan/issues/9394
This commit is contained in:
parent
28e4e1ef2f
commit
ccb65454a2
@ -165,8 +165,8 @@ func (value *Value) Compare(other *Value) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool {
|
func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool {
|
||||||
if nil == value || nil == other {
|
if nil == other {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != value.Block && nil != other.Block {
|
if nil != value.Block && nil != other.Block {
|
||||||
@ -193,16 +193,34 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
|
|||||||
if nil != value.Text && nil != other.Text {
|
if nil != value.Text && nil != other.Text {
|
||||||
switch operator {
|
switch operator {
|
||||||
case FilterOperatorIsEqual:
|
case FilterOperatorIsEqual:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Text.Content == other.Text.Content
|
return value.Text.Content == other.Text.Content
|
||||||
case FilterOperatorIsNotEqual:
|
case FilterOperatorIsNotEqual:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Text.Content != other.Text.Content
|
return value.Text.Content != other.Text.Content
|
||||||
case FilterOperatorContains:
|
case FilterOperatorContains:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return strings.Contains(value.Text.Content, other.Text.Content)
|
return strings.Contains(value.Text.Content, other.Text.Content)
|
||||||
case FilterOperatorDoesNotContain:
|
case FilterOperatorDoesNotContain:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return !strings.Contains(value.Text.Content, other.Text.Content)
|
return !strings.Contains(value.Text.Content, other.Text.Content)
|
||||||
case FilterOperatorStartsWith:
|
case FilterOperatorStartsWith:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return strings.HasPrefix(value.Text.Content, other.Text.Content)
|
return strings.HasPrefix(value.Text.Content, other.Text.Content)
|
||||||
case FilterOperatorEndsWith:
|
case FilterOperatorEndsWith:
|
||||||
|
if "" == strings.TrimSpace(other.Text.Content) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return strings.HasSuffix(value.Text.Content, other.Text.Content)
|
return strings.HasSuffix(value.Text.Content, other.Text.Content)
|
||||||
case FilterOperatorIsEmpty:
|
case FilterOperatorIsEmpty:
|
||||||
return "" == strings.TrimSpace(value.Text.Content)
|
return "" == strings.TrimSpace(value.Text.Content)
|
||||||
@ -214,8 +232,14 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
|
|||||||
if nil != value.Number && nil != other.Number {
|
if nil != value.Number && nil != other.Number {
|
||||||
switch operator {
|
switch operator {
|
||||||
case FilterOperatorIsEqual:
|
case FilterOperatorIsEqual:
|
||||||
|
if !other.Number.IsNotEmpty {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Number.Content == other.Number.Content
|
return value.Number.Content == other.Number.Content
|
||||||
case FilterOperatorIsNotEqual:
|
case FilterOperatorIsNotEqual:
|
||||||
|
if !other.Number.IsNotEmpty {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Number.Content != other.Number.Content
|
return value.Number.Content != other.Number.Content
|
||||||
case FilterOperatorIsGreater:
|
case FilterOperatorIsGreater:
|
||||||
return value.Number.Content > other.Number.Content
|
return value.Number.Content > other.Number.Content
|
||||||
@ -235,8 +259,14 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
|
|||||||
if nil != value.Date && nil != other.Date {
|
if nil != value.Date && nil != other.Date {
|
||||||
switch operator {
|
switch operator {
|
||||||
case FilterOperatorIsEqual:
|
case FilterOperatorIsEqual:
|
||||||
|
if !other.Date.IsNotEmpty {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Date.Content == other.Date.Content
|
return value.Date.Content == other.Date.Content
|
||||||
case FilterOperatorIsNotEqual:
|
case FilterOperatorIsNotEqual:
|
||||||
|
if !other.Date.IsNotEmpty {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return value.Date.Content != other.Date.Content
|
return value.Date.Content != other.Date.Content
|
||||||
case FilterOperatorIsGreater:
|
case FilterOperatorIsGreater:
|
||||||
return value.Date.Content > other.Date.Content
|
return value.Date.Content > other.Date.Content
|
||||||
@ -541,7 +571,17 @@ func (table *Table) FilterRows() {
|
|||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
pass := true
|
pass := true
|
||||||
for j, index := range colIndexes {
|
for j, index := range colIndexes {
|
||||||
if !row.Cells[index].Value.CompareOperator(table.Filters[j].Value, table.Filters[j].Operator) {
|
operator := table.Filters[j].Operator
|
||||||
|
|
||||||
|
if nil == row.Cells[index].Value {
|
||||||
|
switch operator {
|
||||||
|
case FilterOperatorIsNotEmpty:
|
||||||
|
pass = false
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if !row.Cells[index].Value.CompareOperator(table.Filters[j].Value, operator) {
|
||||||
pass = false
|
pass = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user