mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Improve database field default filling https://github.com/siyuan-note/siyuan/issues/11966
This commit is contained in:
parent
120b0c1e57
commit
1136c1c493
2 changed files with 37 additions and 51 deletions
|
|
@ -328,6 +328,10 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
|||
}
|
||||
case KeyTypeNumber:
|
||||
if nil != value.Number && nil != other && nil != other.Number {
|
||||
if !other.Number.IsNotEmpty {
|
||||
return true
|
||||
}
|
||||
|
||||
switch operator {
|
||||
case FilterOperatorIsEqual:
|
||||
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:
|
||||
if nil != value.MSelect {
|
||||
if nil != other && nil != other.MSelect {
|
||||
if nil == other || nil == other.MSelect || 1 > len(other.MSelect) {
|
||||
return true
|
||||
}
|
||||
|
||||
switch operator {
|
||||
case FilterOperatorIsEqual, FilterOperatorContains:
|
||||
contains := false
|
||||
|
|
@ -433,18 +440,6 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
|||
}
|
||||
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:
|
||||
if nil != value.URL && nil != other && nil != other.URL {
|
||||
switch operator {
|
||||
|
|
@ -854,7 +849,6 @@ func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *V
|
|||
ret.CreatedAt = util.CurrentTimeMillis()
|
||||
ret.UpdatedAt = ret.CreatedAt + 1000
|
||||
|
||||
// 没有默认值则使用过滤条件的值
|
||||
switch filter.Value.Type {
|
||||
case KeyTypeBlock:
|
||||
switch filter.Operator {
|
||||
|
|
@ -947,9 +941,13 @@ func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *V
|
|||
}
|
||||
ret.MSelect = []*ValueSelect{valueSelect}
|
||||
case FilterOperatorIsNotEqual:
|
||||
return nil
|
||||
case FilterOperatorContains:
|
||||
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:
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
|
|
|
|||
|
|
@ -115,22 +115,10 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
|||
continue
|
||||
}
|
||||
|
||||
var newValue *av.Value
|
||||
|
||||
switch keyValues.Key.Type {
|
||||
case av.KeyTypeNumber:
|
||||
newValue = filter.GetAffectValue(keyValues.Key, addingItemID)
|
||||
newValue := filter.GetAffectValue(keyValues.Key, addingItemID)
|
||||
if nil == newValue {
|
||||
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 {
|
||||
ret[keyValues.Key.ID] = newValue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue