mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve av https://github.com/siyuan-note/siyuan/issues/15521
This commit is contained in:
parent
b78e2edfb8
commit
176308d7d2
4 changed files with 25 additions and 15 deletions
|
|
@ -3442,7 +3442,7 @@ func getAttrViewTable(attrView *av.AttributeView, view *av.View, query string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
depth := 1
|
depth := 1
|
||||||
ret = sql.RenderAttributeViewTable(attrView, view, query, &depth, map[string]*av.AttributeView{})
|
ret = sql.RenderAttributeViewTable(attrView, view, query, &depth, map[string]*av.AttributeView{}, map[string]av.Collection{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,14 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
|
||||||
func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av.Viewable) {
|
func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av.Viewable) {
|
||||||
depth := 1
|
depth := 1
|
||||||
renderedAttrViews := map[string]*av.AttributeView{}
|
renderedAttrViews := map[string]*av.AttributeView{}
|
||||||
|
renderedTemplateKeyCollections := map[string]av.Collection{}
|
||||||
renderedAttrViews[attrView.ID] = attrView
|
renderedAttrViews[attrView.ID] = attrView
|
||||||
ret = renderView(attrView, view, query, &depth, renderedAttrViews)
|
ret = renderView(attrView, view, query, &depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderView(attrView *av.AttributeView, view *av.View, query string,
|
func renderView(attrView *av.AttributeView, view *av.View, query string,
|
||||||
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
|
depth *int, renderedAttrViews map[string]*av.AttributeView, renderedTemplateKeyCollections map[string]av.Collection) (ret av.Viewable) {
|
||||||
if 7 < *depth {
|
if 7 < *depth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -87,9 +88,9 @@ func renderView(attrView *av.AttributeView, view *av.View, query string,
|
||||||
*depth++
|
*depth++
|
||||||
switch view.LayoutType {
|
switch view.LayoutType {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews)
|
ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
case av.LayoutTypeGallery:
|
case av.LayoutTypeGallery:
|
||||||
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews)
|
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +327,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, renderedAttrViews map[string]*av.AttributeView) {
|
depth *int, renderedAttrViews map[string]*av.AttributeView, renderedTemplateKeyCollections map[string]av.Collection) {
|
||||||
for _, item := range collection.GetItems() {
|
for _, item := range collection.GetItems() {
|
||||||
for _, value := range item.GetValues() {
|
for _, value := range item.GetValues() {
|
||||||
itemID := item.GetID()
|
itemID := item.GetID()
|
||||||
|
|
@ -373,16 +374,25 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewable av.Viewable
|
var furtherCollection av.Collection
|
||||||
|
var ok bool
|
||||||
if av.KeyTypeTemplate == destKey.Type {
|
if av.KeyTypeTemplate == destKey.Type {
|
||||||
|
if furtherCollection, ok = renderedTemplateKeyCollections[destKey.ID]; !ok {
|
||||||
|
renderedTemplateKeyCollections[destKey.ID] = collection
|
||||||
|
|
||||||
// 渲染目标视图,这样才能汇总渲染后的模板字段值
|
// 渲染目标视图,这样才能汇总渲染后的模板字段值
|
||||||
viewable = renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews)
|
viewable := renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
|
if nil != viewable {
|
||||||
|
furtherCollection = viewable.(av.Collection)
|
||||||
|
renderedTemplateKeyCollections[destKey.ID] = furtherCollection
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, blockID := range relVal.Relation.BlockIDs {
|
for _, blockID := range relVal.Relation.BlockIDs {
|
||||||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||||
if nil != viewable && av.KeyTypeTemplate == destKey.Type {
|
if nil != furtherCollection && av.KeyTypeTemplate == destKey.Type {
|
||||||
destVal = viewable.(av.Collection).GetValue(blockID, destKey.ID)
|
destVal = furtherCollection.GetValue(blockID, destKey.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == destVal {
|
if nil == destVal {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string,
|
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string,
|
||||||
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret *av.Gallery) {
|
depth *int, renderedAttrViews map[string]*av.AttributeView, renderedTemplateKeyCollections map[string]av.Collection) (ret *av.Gallery) {
|
||||||
ret = &av.Gallery{
|
ret = &av.Gallery{
|
||||||
BaseInstance: av.NewViewBaseInstance(view),
|
BaseInstance: av.NewViewBaseInstance(view),
|
||||||
CoverFrom: view.Gallery.CoverFrom,
|
CoverFrom: view.Gallery.CoverFrom,
|
||||||
|
|
@ -115,7 +115,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues, depth, renderedAttrViews)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues, depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
|
|
||||||
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string,
|
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string,
|
||||||
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret *av.Table) {
|
depth *int, renderedAttrViews map[string]*av.AttributeView, renderedTemplateKeyCollections map[string]av.Collection) (ret *av.Table) {
|
||||||
ret = &av.Table{
|
ret = &av.Table{
|
||||||
BaseInstance: av.NewViewBaseInstance(view),
|
BaseInstance: av.NewViewBaseInstance(view),
|
||||||
Columns: []*av.TableColumn{},
|
Columns: []*av.TableColumn{},
|
||||||
|
|
@ -108,7 +108,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
ials := BatchGetBlockAttrs(ialIDs)
|
ials := BatchGetBlockAttrs(ialIDs)
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues, depth, renderedAttrViews)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues, depth, renderedAttrViews, renderedTemplateKeyCollections)
|
||||||
|
|
||||||
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue