mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve database rollup template rendering https://github.com/siyuan-note/siyuan/issues/15722
This commit is contained in:
parent
50956851c8
commit
7952fec7cb
2 changed files with 90 additions and 23 deletions
|
|
@ -338,6 +338,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
|||
depth *int, cachedAttrViews map[string]*av.AttributeView) {
|
||||
|
||||
// 先渲染主键、创建时间、更新时间
|
||||
|
||||
for _, item := range collection.GetItems() {
|
||||
for _, value := range item.GetValues() {
|
||||
itemID := item.GetID()
|
||||
|
|
@ -399,7 +400,54 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
|||
}
|
||||
}
|
||||
|
||||
// 再渲染汇总和关联
|
||||
// 再渲染关联和汇总
|
||||
|
||||
rollupFurtherCollections := map[string]av.Collection{}
|
||||
for _, field := range collection.GetFields() {
|
||||
if av.KeyTypeRollup != field.GetType() {
|
||||
continue
|
||||
}
|
||||
|
||||
rollupKey, _ := attrView.GetKey(field.GetID())
|
||||
if nil == rollupKey || nil == rollupKey.Rollup {
|
||||
continue
|
||||
}
|
||||
|
||||
relKey, _ := attrView.GetKey(rollupKey.Rollup.RelationKeyID)
|
||||
if nil == relKey || nil == relKey.Relation {
|
||||
continue
|
||||
}
|
||||
|
||||
destAv := cachedAttrViews[relKey.Relation.AvID]
|
||||
if nil == destAv {
|
||||
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
||||
if nil != destAv {
|
||||
cachedAttrViews[relKey.Relation.AvID] = destAv
|
||||
}
|
||||
}
|
||||
if nil == destAv {
|
||||
continue
|
||||
}
|
||||
|
||||
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
|
||||
isSameAv := destAv.ID == attrView.ID
|
||||
var furtherCollection av.Collection
|
||||
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
|
||||
viewable := renderView(destAv, destAv.Views[0], "", depth, cachedAttrViews)
|
||||
if nil != viewable {
|
||||
furtherCollection = viewable.(av.Collection)
|
||||
} else {
|
||||
fillAttributeViewTemplateValues(destAv, destAv.Views[0], collection, ials)
|
||||
furtherCollection = collection
|
||||
}
|
||||
}
|
||||
rollupFurtherCollections[rollupKey.ID] = furtherCollection
|
||||
}
|
||||
|
||||
for _, item := range collection.GetItems() {
|
||||
for _, value := range item.GetValues() {
|
||||
itemID := item.GetID()
|
||||
|
|
@ -437,18 +485,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
|||
break
|
||||
}
|
||||
|
||||
isSameAv := destAv.ID == attrView.ID
|
||||
var furtherCollection av.Collection
|
||||
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
|
||||
viewable := renderView(destAv, destAv.Views[0], "", depth, cachedAttrViews)
|
||||
if nil != viewable {
|
||||
furtherCollection = viewable.(av.Collection)
|
||||
} else {
|
||||
fillAttributeViewTemplateValues(destAv, destAv.Views[0], collection, ials)
|
||||
furtherCollection = collection
|
||||
}
|
||||
}
|
||||
|
||||
furtherCollection := rollupFurtherCollections[rollupKey.ID]
|
||||
value.Rollup.BuildContents(destAv.KeyValues, destKey, relVal, rollupKey.Rollup.Calc, furtherCollection)
|
||||
case av.KeyTypeRelation: // 渲染关联
|
||||
value.Relation.Contents = nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue