mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
🎨 Improve av
This commit is contained in:
parent
cd10072554
commit
b78e2edfb8
4 changed files with 22 additions and 17 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)
|
ret = sql.RenderAttributeViewTable(attrView, view, query, &depth, map[string]*av.AttributeView{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,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
|
||||||
return renderView(attrView, view, query, &depth)
|
renderedAttrViews := map[string]*av.AttributeView{}
|
||||||
|
renderedAttrViews[attrView.ID] = attrView
|
||||||
|
ret = renderView(attrView, view, query, &depth, renderedAttrViews)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret av.Viewable) {
|
func renderView(attrView *av.AttributeView, view *av.View, query string,
|
||||||
|
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
|
||||||
if 7 < *depth {
|
if 7 < *depth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -83,9 +87,9 @@ func renderView(attrView *av.AttributeView, view *av.View, query string, depth *
|
||||||
*depth++
|
*depth++
|
||||||
switch view.LayoutType {
|
switch view.LayoutType {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
ret = RenderAttributeViewTable(attrView, view, query, depth)
|
ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews)
|
||||||
case av.LayoutTypeGallery:
|
case av.LayoutTypeGallery:
|
||||||
ret = RenderAttributeViewGallery(attrView, view, query, depth)
|
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -321,9 +325,8 @@ 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, depth *int) {
|
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues,
|
||||||
avCache := map[string]*av.AttributeView{}
|
depth *int, renderedAttrViews map[string]*av.AttributeView) {
|
||||||
avCache[attrView.ID] = attrView
|
|
||||||
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()
|
||||||
|
@ -354,11 +357,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
destAv := avCache[relKey.Relation.AvID]
|
destAv := renderedAttrViews[relKey.Relation.AvID]
|
||||||
if nil == destAv {
|
if nil == destAv {
|
||||||
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
||||||
if nil != destAv {
|
if nil != destAv {
|
||||||
avCache[relKey.Relation.AvID] = destAv
|
renderedAttrViews[relKey.Relation.AvID] = destAv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil == destAv {
|
if nil == destAv {
|
||||||
|
@ -373,7 +376,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
var viewable av.Viewable
|
var viewable av.Viewable
|
||||||
if av.KeyTypeTemplate == destKey.Type {
|
if av.KeyTypeTemplate == destKey.Type {
|
||||||
// 渲染目标视图,这样才能汇总渲染后的模板字段值
|
// 渲染目标视图,这样才能汇总渲染后的模板字段值
|
||||||
viewable = renderView(destAv, destAv.Views[0], "", depth)
|
viewable = renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, blockID := range relVal.Relation.BlockIDs {
|
for _, blockID := range relVal.Relation.BlockIDs {
|
||||||
|
@ -409,11 +412,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
value.Relation.Contents = nil
|
value.Relation.Contents = nil
|
||||||
relKey, _ := attrView.GetKey(value.KeyID)
|
relKey, _ := attrView.GetKey(value.KeyID)
|
||||||
if nil != relKey && nil != relKey.Relation {
|
if nil != relKey && nil != relKey.Relation {
|
||||||
destAv := avCache[relKey.Relation.AvID]
|
destAv := renderedAttrViews[relKey.Relation.AvID]
|
||||||
if nil == destAv {
|
if nil == destAv {
|
||||||
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
||||||
if nil != destAv {
|
if nil != destAv {
|
||||||
avCache[relKey.Relation.AvID] = destAv
|
renderedAttrViews[relKey.Relation.AvID] = destAv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil != destAv {
|
if nil != destAv {
|
||||||
|
|
|
@ -18,7 +18,8 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret *av.Gallery) {
|
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string,
|
||||||
|
depth *int, renderedAttrViews map[string]*av.AttributeView) (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,
|
||||||
|
@ -114,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)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues, depth, renderedAttrViews)
|
||||||
|
|
||||||
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
||||||
|
|
|
@ -22,7 +22,8 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret *av.Table) {
|
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string,
|
||||||
|
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret *av.Table) {
|
||||||
ret = &av.Table{
|
ret = &av.Table{
|
||||||
BaseInstance: av.NewViewBaseInstance(view),
|
BaseInstance: av.NewViewBaseInstance(view),
|
||||||
Columns: []*av.TableColumn{},
|
Columns: []*av.TableColumn{},
|
||||||
|
@ -107,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)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues, depth, renderedAttrViews)
|
||||||
|
|
||||||
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后单独渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue