🎨 The database rollup field supports using the template field https://github.com/siyuan-note/siyuan/issues/12384

This commit is contained in:
Daniel 2025-08-06 11:33:43 +08:00
parent bc16cd658f
commit f2dda8b389
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 22 additions and 10 deletions

View file

@ -46,11 +46,20 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
}
func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av.Viewable) {
depth := 1
return renderView(attrView, view, query, &depth)
}
func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret av.Viewable) {
if 7 < *depth {
return
}
switch view.LayoutType {
case av.LayoutTypeTable:
ret = RenderAttributeViewTable(attrView, view, query)
ret = RenderAttributeViewTable(attrView, view, query, depth)
case av.LayoutTypeGallery:
ret = RenderAttributeViewGallery(attrView, view, query)
ret = RenderAttributeViewGallery(attrView, view, query, depth)
}
return
}
@ -285,7 +294,7 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID string,
}
}
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues) {
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues, depth *int) {
avCache := map[string]*av.AttributeView{}
avCache[attrView.ID] = attrView
for _, item := range collection.GetItems() {
@ -336,12 +345,13 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
var viewable av.Viewable
if av.KeyTypeTemplate == destKey.Type {
viewable = RenderView(destAv, destAv.Views[0], "")
// 渲染目标视图,这样才能汇总渲染后的模板字段值
viewable = renderView(destAv, destAv.Views[0], "", depth)
}
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal && av.KeyTypeTemplate == destKey.Type && nil != viewable {
if nil != viewable && nil == destVal && av.KeyTypeTemplate == destKey.Type {
destVal = viewable.(av.Collection).GetValue(blockID, destKey.ID)
}