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 https://github.com/siyuan-note/siyuan/issues/15535
This commit is contained in:
parent
c9530ea1c2
commit
7e11be9d25
1 changed files with 45 additions and 108 deletions
|
|
@ -268,63 +268,11 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
||||||
switch value.Type {
|
switch value.Type {
|
||||||
case KeyTypeBlock:
|
case KeyTypeBlock:
|
||||||
if nil != value.Block && nil != other && nil != other.Block {
|
if nil != value.Block && nil != other && nil != other.Block {
|
||||||
switch operator {
|
return filterTextContent(operator, value.Block.Content, other.Block.Content)
|
||||||
case FilterOperatorIsEqual:
|
|
||||||
return value.Block.Content == other.Block.Content
|
|
||||||
case FilterOperatorIsNotEqual:
|
|
||||||
return value.Block.Content != other.Block.Content
|
|
||||||
case FilterOperatorContains:
|
|
||||||
return strings.Contains(value.Block.Content, other.Block.Content)
|
|
||||||
case FilterOperatorDoesNotContain:
|
|
||||||
return !strings.Contains(value.Block.Content, other.Block.Content)
|
|
||||||
case FilterOperatorStartsWith:
|
|
||||||
return strings.HasPrefix(value.Block.Content, other.Block.Content)
|
|
||||||
case FilterOperatorEndsWith:
|
|
||||||
return strings.HasSuffix(value.Block.Content, other.Block.Content)
|
|
||||||
case FilterOperatorIsEmpty:
|
|
||||||
return "" == strings.TrimSpace(value.Block.Content)
|
|
||||||
case FilterOperatorIsNotEmpty:
|
|
||||||
return "" != strings.TrimSpace(value.Block.Content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case KeyTypeText:
|
case KeyTypeText:
|
||||||
if nil != value.Text && nil != other && nil != other.Text {
|
if nil != value.Text && nil != other && nil != other.Text {
|
||||||
switch operator {
|
return filterTextContent(operator, value.Text.Content, other.Text.Content)
|
||||||
case FilterOperatorIsEqual:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return value.Text.Content == other.Text.Content
|
|
||||||
case FilterOperatorIsNotEqual:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return value.Text.Content != other.Text.Content
|
|
||||||
case FilterOperatorContains:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return strings.Contains(value.Text.Content, other.Text.Content)
|
|
||||||
case FilterOperatorDoesNotContain:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return !strings.Contains(value.Text.Content, other.Text.Content)
|
|
||||||
case FilterOperatorStartsWith:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return strings.HasPrefix(value.Text.Content, other.Text.Content)
|
|
||||||
case FilterOperatorEndsWith:
|
|
||||||
if "" == strings.TrimSpace(other.Text.Content) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return strings.HasSuffix(value.Text.Content, other.Text.Content)
|
|
||||||
case FilterOperatorIsEmpty:
|
|
||||||
return "" == strings.TrimSpace(value.Text.Content)
|
|
||||||
case FilterOperatorIsNotEmpty:
|
|
||||||
return "" != strings.TrimSpace(value.Text.Content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case KeyTypeNumber:
|
case KeyTypeNumber:
|
||||||
if nil != value.Number && nil != other && nil != other.Number {
|
if nil != value.Number && nil != other && nil != other.Number {
|
||||||
|
|
@ -448,66 +396,15 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
||||||
}
|
}
|
||||||
case KeyTypeURL:
|
case KeyTypeURL:
|
||||||
if nil != value.URL && nil != other && nil != other.URL {
|
if nil != value.URL && nil != other && nil != other.URL {
|
||||||
switch operator {
|
return filterTextContent(operator, value.URL.Content, other.URL.Content)
|
||||||
case FilterOperatorIsEqual:
|
|
||||||
return value.URL.Content == other.URL.Content
|
|
||||||
case FilterOperatorIsNotEqual:
|
|
||||||
return value.URL.Content != other.URL.Content
|
|
||||||
case FilterOperatorContains:
|
|
||||||
return strings.Contains(value.URL.Content, other.URL.Content)
|
|
||||||
case FilterOperatorDoesNotContain:
|
|
||||||
return !strings.Contains(value.URL.Content, other.URL.Content)
|
|
||||||
case FilterOperatorStartsWith:
|
|
||||||
return strings.HasPrefix(value.URL.Content, other.URL.Content)
|
|
||||||
case FilterOperatorEndsWith:
|
|
||||||
return strings.HasSuffix(value.URL.Content, other.URL.Content)
|
|
||||||
case FilterOperatorIsEmpty:
|
|
||||||
return "" == strings.TrimSpace(value.URL.Content)
|
|
||||||
case FilterOperatorIsNotEmpty:
|
|
||||||
return "" != strings.TrimSpace(value.URL.Content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case KeyTypeEmail:
|
case KeyTypeEmail:
|
||||||
if nil != value.Email && nil != other && nil != other.Email {
|
if nil != value.Email && nil != other && nil != other.Email {
|
||||||
switch operator {
|
return filterTextContent(operator, value.Email.Content, other.URL.Content)
|
||||||
case FilterOperatorIsEqual:
|
|
||||||
return value.Email.Content == other.Email.Content
|
|
||||||
case FilterOperatorIsNotEqual:
|
|
||||||
return value.Email.Content != other.Email.Content
|
|
||||||
case FilterOperatorContains:
|
|
||||||
return strings.Contains(value.Email.Content, other.Email.Content)
|
|
||||||
case FilterOperatorDoesNotContain:
|
|
||||||
return !strings.Contains(value.Email.Content, other.Email.Content)
|
|
||||||
case FilterOperatorStartsWith:
|
|
||||||
return strings.HasPrefix(value.Email.Content, other.Email.Content)
|
|
||||||
case FilterOperatorEndsWith:
|
|
||||||
return strings.HasSuffix(value.Email.Content, other.Email.Content)
|
|
||||||
case FilterOperatorIsEmpty:
|
|
||||||
return "" == strings.TrimSpace(value.Email.Content)
|
|
||||||
case FilterOperatorIsNotEmpty:
|
|
||||||
return "" != strings.TrimSpace(value.Email.Content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case KeyTypePhone:
|
case KeyTypePhone:
|
||||||
if nil != value.Phone && nil != other && nil != other.Phone {
|
if nil != value.Phone && nil != other && nil != other.Phone {
|
||||||
switch operator {
|
return filterTextContent(operator, value.Phone.Content, other.Phone.Content)
|
||||||
case FilterOperatorIsEqual:
|
|
||||||
return value.Phone.Content == other.Phone.Content
|
|
||||||
case FilterOperatorIsNotEqual:
|
|
||||||
return value.Phone.Content != other.Phone.Content
|
|
||||||
case FilterOperatorContains:
|
|
||||||
return strings.Contains(value.Phone.Content, other.Phone.Content)
|
|
||||||
case FilterOperatorDoesNotContain:
|
|
||||||
return !strings.Contains(value.Phone.Content, other.Phone.Content)
|
|
||||||
case FilterOperatorStartsWith:
|
|
||||||
return strings.HasPrefix(value.Phone.Content, other.Phone.Content)
|
|
||||||
case FilterOperatorEndsWith:
|
|
||||||
return strings.HasSuffix(value.Phone.Content, other.Phone.Content)
|
|
||||||
case FilterOperatorIsEmpty:
|
|
||||||
return "" == strings.TrimSpace(value.Phone.Content)
|
|
||||||
case FilterOperatorIsNotEmpty:
|
|
||||||
return "" != strings.TrimSpace(value.Phone.Content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case KeyTypeMAsset:
|
case KeyTypeMAsset:
|
||||||
if nil != value.MAsset && nil != other && nil != other.MAsset && 0 < len(value.MAsset) && 0 < len(other.MAsset) {
|
if nil != value.MAsset && nil != other && nil != other.MAsset && 0 < len(value.MAsset) && 0 < len(other.MAsset) {
|
||||||
|
|
@ -619,6 +516,46 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterTextContent(operator FilterOperator, valueContent, otherValueContent string) bool {
|
||||||
|
switch operator {
|
||||||
|
case FilterOperatorIsEqual:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return valueContent == otherValueContent
|
||||||
|
case FilterOperatorIsNotEqual:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return valueContent != otherValueContent
|
||||||
|
case FilterOperatorContains:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return strings.Contains(valueContent, otherValueContent)
|
||||||
|
case FilterOperatorDoesNotContain:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !strings.Contains(valueContent, otherValueContent)
|
||||||
|
case FilterOperatorStartsWith:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return strings.HasPrefix(valueContent, otherValueContent)
|
||||||
|
case FilterOperatorEndsWith:
|
||||||
|
if "" == strings.TrimSpace(otherValueContent) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return strings.HasSuffix(valueContent, otherValueContent)
|
||||||
|
case FilterOperatorIsEmpty:
|
||||||
|
return "" == strings.TrimSpace(valueContent)
|
||||||
|
case FilterOperatorIsNotEmpty:
|
||||||
|
return "" != strings.TrimSpace(valueContent)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterOperator, otherValueStart, otherValueEnd time.Time, direction RelativeDateDirection, otherValueStart2, otherValueEnd2 time.Time, direction2 RelativeDateDirection) bool {
|
func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterOperator, otherValueStart, otherValueEnd time.Time, direction RelativeDateDirection, otherValueStart2, otherValueEnd2 time.Time, direction2 RelativeDateDirection) bool {
|
||||||
valueTime := time.UnixMilli(valueMills)
|
valueTime := time.UnixMilli(valueMills)
|
||||||
switch operator {
|
switch operator {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue