🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958

This commit is contained in:
Daniel 2023-12-30 23:01:21 +08:00
parent 8bf3efb355
commit 6a8602c1cd
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 43 additions and 9 deletions

View file

@ -22,7 +22,7 @@ import (
)
type Filterable interface {
FilterRows()
FilterRows(attrView *AttributeView)
}
type ViewFilter struct {

View file

@ -230,7 +230,44 @@ func (value *Value) Compare(other *Value) int {
return 0
}
func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool {
func (value *Value) CompareOperator(other *Value, operator FilterOperator, attrView *AttributeView, rowID string) bool {
if nil != value.Rollup && nil != other.Rollup {
rollupKey, _ := attrView.GetKey(value.KeyID)
if nil == rollupKey {
return false
}
relKey, _ := attrView.GetKey(rollupKey.Rollup.RelationKeyID)
if nil == relKey {
return false
}
relVal := attrView.GetValue(relKey.ID, rowID)
if nil == relVal || nil == relVal.Relation {
return false
}
destAv, _ := ParseAttributeView(relKey.Relation.AvID)
if nil == destAv {
return false
}
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal {
continue
}
if destVal.compareOperator(other, operator, attrView) {
return true
}
}
return false
}
return value.compareOperator(other, operator, attrView)
}
func (value *Value) compareOperator(other *Value, operator FilterOperator, attrView *AttributeView) bool {
if nil == other {
return true
}
@ -639,9 +676,6 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
}
}
if nil != value.Rollup && nil != other.Rollup {
// TODO: rollup filter
}
return false
}
@ -745,7 +779,7 @@ func (table *Table) SortRows() {
})
}
func (table *Table) FilterRows() {
func (table *Table) FilterRows(attrView *AttributeView) {
if 1 > len(table.Filters) {
return
}
@ -780,7 +814,7 @@ func (table *Table) FilterRows() {
break
}
if !row.Cells[index].Value.CompareOperator(table.Filters[j].Value, operator) {
if !row.Cells[index].Value.CompareOperator(table.Filters[j].Value, operator, attrView, row.ID) {
pass = false
break
}

View file

@ -547,7 +547,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
viewable, err = renderAttributeViewTable(attrView, view)
}
viewable.FilterRows()
viewable.FilterRows(attrView)
viewable.SortRows()
viewable.CalcCols()
@ -1566,7 +1566,7 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
view, _ := attrView.GetCurrentView()
if nil != view && 0 < len(view.Table.Filters) {
viewable, _ := renderAttributeViewTable(attrView, view)
viewable.FilterRows()
viewable.FilterRows(attrView)
viewable.SortRows()
addedVal := false