🎨 The database rollup field supports using the updated/created field https://github.com/siyuan-note/siyuan/issues/15662

This commit is contained in:
Daniel 2025-08-22 21:30:59 +08:00
parent ee95f9bf6f
commit 9bb6f4d134
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 54 additions and 44 deletions

View file

@ -79,6 +79,20 @@ func GetKeyBlockValue(blockKeyValues []*KeyValues) (ret *Value) {
return
}
func GetValue(keyValues []*KeyValues, keyID, itemID string) (ret *Value) {
for _, kv := range keyValues {
if kv.Key.ID == keyID {
for _, v := range kv.Values {
if v.BlockID == itemID {
ret = v
return
}
}
}
}
return
}
// KeyType 描述了属性视图属性字段的类型。
type KeyType string
@ -565,15 +579,6 @@ func (av *AttributeView) GetCurrentView(viewID string) (ret *View, err error) {
return
}
func (av *AttributeView) ExistItem(itemID string) bool {
for _, blockVal := range av.GetBlockKeyValues().Values {
if blockVal.BlockID == itemID {
return true
}
}
return false
}
func (av *AttributeView) ExistBoundBlock(nodeID string) bool {
for _, blockVal := range av.GetBlockKeyValues().Values {
if blockVal.Block.ID == nodeID {

View file

@ -182,7 +182,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID st
return false
}
value.Rollup.BuildContents(destAv, destKey, relVal, key.Rollup.Calc, nil)
value.Rollup.BuildContents(destAv.KeyValues, destKey, relVal, key.Rollup.Calc, nil)
for _, content := range value.Rollup.Contents {
switch filter.Operator {
case FilterOperatorContains:

View file

@ -796,21 +796,16 @@ type ValueRollup struct {
Contents []*Value `json:"contents"`
}
func (r *ValueRollup) BuildContents(destAv *AttributeView, destKey *Key, relationVal *Value, calc *RollupCalc, furtherCollection Collection) {
func (r *ValueRollup) BuildContents(keyValues []*KeyValues, destKey *Key, relationVal *Value, calc *RollupCalc, furtherCollection Collection) {
r.Contents = nil
for _, blockID := range relationVal.Relation.BlockIDs {
destVal := destAv.GetValue(destKey.ID, blockID)
destVal := GetValue(keyValues, destKey.ID, blockID)
if nil != furtherCollection && KeyTypeTemplate == destKey.Type {
destVal = furtherCollection.GetValue(blockID, destKey.ID)
}
if nil == destVal {
if destAv.ExistItem(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), destKey.ID, blockID, destKey.Type)
}
if nil == destVal {
continue
}
continue
}
if KeyTypeNumber == destKey.Type {
destVal.Number.Format = destKey.NumberFormat