🎨 Improve database field default filling https://github.com/siyuan-note/siyuan/issues/11966

This commit is contained in:
Daniel 2025-08-12 11:36:58 +08:00
parent 120b0c1e57
commit 1136c1c493
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 37 additions and 51 deletions

View file

@ -328,6 +328,10 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
} }
case KeyTypeNumber: case KeyTypeNumber:
if nil != value.Number && nil != other && nil != other.Number { if nil != value.Number && nil != other && nil != other.Number {
if !other.Number.IsNotEmpty {
return true
}
switch operator { switch operator {
case FilterOperatorIsEqual: case FilterOperatorIsEqual:
return value.Number.Content == other.Number.Content && value.Number.IsNotEmpty == other.Number.IsNotEmpty return value.Number.Content == other.Number.Content && value.Number.IsNotEmpty == other.Number.IsNotEmpty
@ -402,7 +406,10 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
} }
case KeyTypeSelect, KeyTypeMSelect: case KeyTypeSelect, KeyTypeMSelect:
if nil != value.MSelect { if nil != value.MSelect {
if nil != other && nil != other.MSelect { if nil == other || nil == other.MSelect || 1 > len(other.MSelect) {
return true
}
switch operator { switch operator {
case FilterOperatorIsEqual, FilterOperatorContains: case FilterOperatorIsEqual, FilterOperatorContains:
contains := false contains := false
@ -433,18 +440,6 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
} }
return false return false
} }
// 没有设置比较值
switch operator {
case FilterOperatorIsEqual, FilterOperatorIsNotEqual, FilterOperatorContains, FilterOperatorDoesNotContain:
return true
case FilterOperatorIsEmpty:
return 0 == len(value.MSelect) || 1 == len(value.MSelect) && "" == value.MSelect[0].Content
case FilterOperatorIsNotEmpty:
return 0 != len(value.MSelect) && !(1 == len(value.MSelect) && "" == value.MSelect[0].Content)
}
}
case KeyTypeURL: case KeyTypeURL:
if nil != value.URL && nil != other && nil != other.URL { if nil != value.URL && nil != other && nil != other.URL {
switch operator { switch operator {
@ -854,7 +849,6 @@ func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *V
ret.CreatedAt = util.CurrentTimeMillis() ret.CreatedAt = util.CurrentTimeMillis()
ret.UpdatedAt = ret.CreatedAt + 1000 ret.UpdatedAt = ret.CreatedAt + 1000
// 没有默认值则使用过滤条件的值
switch filter.Value.Type { switch filter.Value.Type {
case KeyTypeBlock: case KeyTypeBlock:
switch filter.Operator { switch filter.Operator {
@ -947,9 +941,13 @@ func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *V
} }
ret.MSelect = []*ValueSelect{valueSelect} ret.MSelect = []*ValueSelect{valueSelect}
case FilterOperatorIsNotEqual: case FilterOperatorIsNotEqual:
return nil
case FilterOperatorContains:
if 0 < len(filter.Value.MSelect) { if 0 < len(filter.Value.MSelect) {
ret.MSelect = []*ValueSelect{} ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content, Color: filter.Value.MSelect[0].Color}}
} }
case FilterOperatorDoesNotContain:
return nil
case FilterOperatorIsEmpty: case FilterOperatorIsEmpty:
ret.MSelect = []*ValueSelect{} ret.MSelect = []*ValueSelect{}
case FilterOperatorIsNotEmpty: case FilterOperatorIsNotEmpty:

View file

@ -115,22 +115,10 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
continue continue
} }
var newValue *av.Value newValue := filter.GetAffectValue(keyValues.Key, addingItemID)
switch keyValues.Key.Type {
case av.KeyTypeNumber:
newValue = filter.GetAffectValue(keyValues.Key, addingItemID)
if nil == newValue { if nil == newValue {
newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingItemID) newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingItemID)
} }
default:
if nil != nearItem {
newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingItemID)
} else {
newValue = filter.GetAffectValue(keyValues.Key, addingItemID)
}
}
if nil != newValue { if nil != newValue {
ret[keyValues.Key.ID] = newValue ret[keyValues.Key.ID] = newValue
} }