mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 16:58:49 +01:00
🎨 Improve db tv relation render
This commit is contained in:
parent
5700a9f18a
commit
646d8c2b57
1 changed files with 31 additions and 33 deletions
|
|
@ -219,8 +219,31 @@ func (value *Value) Compare(other *Value) int {
|
|||
}
|
||||
case KeyTypeRelation:
|
||||
if nil != value.Relation && nil != other.Relation {
|
||||
vContent := strings.TrimSpace(strings.Join(value.Relation.Contents, " "))
|
||||
oContent := strings.TrimSpace(strings.Join(other.Relation.Contents, " "))
|
||||
vContentBuf := bytes.Buffer{}
|
||||
for _, c := range value.Relation.Contents {
|
||||
vContentBuf.WriteString(c.String())
|
||||
vContentBuf.WriteByte(' ')
|
||||
}
|
||||
vContent := strings.TrimSpace(vContentBuf.String())
|
||||
oContentBuf := bytes.Buffer{}
|
||||
for _, c := range other.Relation.Contents {
|
||||
oContentBuf.WriteString(c.String())
|
||||
oContentBuf.WriteByte(' ')
|
||||
}
|
||||
oContent := strings.TrimSpace(oContentBuf.String())
|
||||
|
||||
if util.IsNumeric(vContent) && util.IsNumeric(oContent) {
|
||||
v1, _ := strconv.ParseFloat(vContent, 64)
|
||||
v2, _ := strconv.ParseFloat(oContent, 64)
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
return strings.Compare(vContent, oContent)
|
||||
}
|
||||
case KeyTypeRollup:
|
||||
|
|
@ -302,6 +325,12 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID st
|
|||
return false
|
||||
}
|
||||
|
||||
if nil != value.Relation && KeyTypeRelation == value.Type && nil != filter && nil != filter.Value && KeyTypeRelation == filter.Value.Type &&
|
||||
nil != filter.Value.Relation && 0 < len(filter.Value.Relation.Contents) {
|
||||
// 单独处理关联类型的比较
|
||||
return value.filter(filter.Value.Relation.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
||||
}
|
||||
|
||||
return value.filter(filter.Value, filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
||||
}
|
||||
|
||||
|
|
@ -752,37 +781,6 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
|
|||
return !value.Checkbox.Checked
|
||||
}
|
||||
}
|
||||
case KeyTypeRelation:
|
||||
if nil != value.Relation && nil != other && nil != other.Relation {
|
||||
switch operator {
|
||||
case FilterOperatorContains:
|
||||
contains := false
|
||||
for _, c := range value.Relation.Contents {
|
||||
for _, c1 := range other.Relation.Contents {
|
||||
if strings.Contains(c, c1) {
|
||||
contains = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return contains
|
||||
case FilterOperatorDoesNotContain:
|
||||
contains := false
|
||||
for _, c := range value.Relation.Contents {
|
||||
for _, c1 := range other.Relation.Contents {
|
||||
if strings.Contains(c, c1) {
|
||||
contains = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return !contains
|
||||
case FilterOperatorIsEmpty:
|
||||
return 0 == len(value.Relation.Contents) || 1 == len(value.Relation.Contents) && "" == value.Relation.Contents[0]
|
||||
case FilterOperatorIsNotEmpty:
|
||||
return 0 != len(value.Relation.Contents) && !(1 == len(value.Relation.Contents) && "" == value.Relation.Contents[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue