mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958
This commit is contained in:
parent
8bf3efb355
commit
6a8602c1cd
3 changed files with 43 additions and 9 deletions
|
|
@ -22,7 +22,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Filterable interface {
|
type Filterable interface {
|
||||||
FilterRows()
|
FilterRows(attrView *AttributeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ViewFilter struct {
|
type ViewFilter struct {
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,44 @@ func (value *Value) Compare(other *Value) int {
|
||||||
return 0
|
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 {
|
if nil == other {
|
||||||
return true
|
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
|
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) {
|
if 1 > len(table.Filters) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -780,7 +814,7 @@ func (table *Table) FilterRows() {
|
||||||
break
|
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
|
pass = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -547,7 +547,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
|
||||||
viewable, err = renderAttributeViewTable(attrView, view)
|
viewable, err = renderAttributeViewTable(attrView, view)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewable.FilterRows()
|
viewable.FilterRows(attrView)
|
||||||
viewable.SortRows()
|
viewable.SortRows()
|
||||||
viewable.CalcCols()
|
viewable.CalcCols()
|
||||||
|
|
||||||
|
|
@ -1566,7 +1566,7 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
||||||
view, _ := attrView.GetCurrentView()
|
view, _ := attrView.GetCurrentView()
|
||||||
if nil != view && 0 < len(view.Table.Filters) {
|
if nil != view && 0 < len(view.Table.Filters) {
|
||||||
viewable, _ := renderAttributeViewTable(attrView, view)
|
viewable, _ := renderAttributeViewTable(attrView, view)
|
||||||
viewable.FilterRows()
|
viewable.FilterRows(attrView)
|
||||||
viewable.SortRows()
|
viewable.SortRows()
|
||||||
|
|
||||||
addedVal := false
|
addedVal := false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue