🎨 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:08:26 +08:00
parent 511c174e65
commit f6694810e2
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 15 additions and 25 deletions

View file

@ -334,8 +334,22 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
return
}
var viewable av.Viewable
if av.KeyTypeTemplate == destKey.Type {
viewable = RenderView(destAv, destAv.Views[0], "")
}
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal && av.KeyTypeTemplate == destKey.Type && nil != viewable {
for _, destItem := range viewable.(av.Collection).GetItems() {
if blockID == destItem.GetID() {
destVal = destItem.GetValue(destKey.ID)
break
}
}
}
if nil == destVal {
if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
@ -465,30 +479,6 @@ func fillAttributeViewTemplateValues(attrView *av.AttributeView, collection av.C
return
}
func fillAttributeViewTemplateValue(value *av.Value, item av.Item, attrView *av.AttributeView, ials map[string]map[string]string, items map[string][]*av.KeyValues) (err error) {
itemID := item.GetID()
switch value.Type {
case av.KeyTypeTemplate: // 渲染模板字段
keyValues := items[itemID]
ial := ials[itemID]
if nil == ial {
ial = map[string]string{}
}
content, renderErr := RenderTemplateField(ial, keyValues, value.Template.Content)
value.Template.Content = content
if nil != renderErr {
key, _ := attrView.GetKey(value.KeyID)
keyName := ""
if nil != key {
keyName = key.Name
}
err = fmt.Errorf("database [%s] template field [%s] rendering failed: %s", getAttrViewName(attrView), keyName, renderErr)
}
}
return
}
func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) {
value.Type = typ
switch typ {