mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Improve av
This commit is contained in:
parent
e015f72945
commit
50956851c8
3 changed files with 35 additions and 14 deletions
|
|
@ -78,17 +78,17 @@ func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av
|
||||||
}
|
}
|
||||||
|
|
||||||
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, cachedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
|
||||||
if 7 < *depth {
|
if 2 < *depth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
*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, cachedAttrViews)
|
||||||
case av.LayoutTypeGallery:
|
case av.LayoutTypeGallery:
|
||||||
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews)
|
ret = RenderAttributeViewGallery(attrView, view, query, depth, cachedAttrViews)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +335,7 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string,
|
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string,
|
||||||
depth *int, renderedAttrViews map[string]*av.AttributeView) {
|
depth *int, cachedAttrViews map[string]*av.AttributeView) {
|
||||||
|
|
||||||
// 先渲染主键、创建时间、更新时间
|
// 先渲染主键、创建时间、更新时间
|
||||||
for _, item := range collection.GetItems() {
|
for _, item := range collection.GetItems() {
|
||||||
|
|
@ -421,11 +421,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
destAv := renderedAttrViews[relKey.Relation.AvID]
|
destAv := cachedAttrViews[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 {
|
||||||
renderedAttrViews[relKey.Relation.AvID] = destAv
|
cachedAttrViews[relKey.Relation.AvID] = destAv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil == destAv {
|
if nil == destAv {
|
||||||
|
|
@ -440,7 +440,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
|
||||||
isSameAv := destAv.ID == attrView.ID
|
isSameAv := destAv.ID == attrView.ID
|
||||||
var furtherCollection av.Collection
|
var furtherCollection av.Collection
|
||||||
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
|
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
|
||||||
viewable := renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews)
|
viewable := renderView(destAv, destAv.Views[0], "", depth, cachedAttrViews)
|
||||||
if nil != viewable {
|
if nil != viewable {
|
||||||
furtherCollection = viewable.(av.Collection)
|
furtherCollection = viewable.(av.Collection)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -454,11 +454,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 := renderedAttrViews[relKey.Relation.AvID]
|
destAv := cachedAttrViews[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 {
|
||||||
renderedAttrViews[relKey.Relation.AvID] = destAv
|
cachedAttrViews[relKey.Relation.AvID] = destAv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil != destAv {
|
if nil != destAv {
|
||||||
|
|
@ -498,6 +498,10 @@ func fillAttributeViewTemplateValues(attrView *av.AttributeView, view *av.View,
|
||||||
for _, templateKey := range templateKeys {
|
for _, templateKey := range templateKeys {
|
||||||
for _, item := range collection.GetItems() {
|
for _, item := range collection.GetItems() {
|
||||||
value := item.GetValue(templateKey.ID)
|
value := item.GetValue(templateKey.ID)
|
||||||
|
if nil == value || nil == value.Template {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
keyValues := items[item.GetID()]
|
keyValues := items[item.GetID()]
|
||||||
var ial map[string]string
|
var ial map[string]string
|
||||||
blockVal := item.GetBlockValue()
|
blockVal := item.GetBlockValue()
|
||||||
|
|
@ -550,6 +554,23 @@ func fillAttributeViewKeyValues(attrView *av.AttributeView, collection av.Collec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mergeKeyValues(kv1, kv2 []*av.KeyValues) (ret []*av.KeyValues) {
|
||||||
|
ret = kv2
|
||||||
|
for _, k1 := range kv1 {
|
||||||
|
found := false
|
||||||
|
for _, k2 := range kv2 {
|
||||||
|
if k1.Key.ID == k2.Key.ID {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
ret = append(ret, k1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) {
|
func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) {
|
||||||
value.Type = typ
|
value.Type = typ
|
||||||
switch typ {
|
switch typ {
|
||||||
|
|
|
||||||
|
|
@ -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, cachedAttrViews 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,
|
||||||
|
|
@ -118,7 +118,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
|
||||||
|
|
||||||
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)
|
||||||
|
|
|
||||||
|
|
@ -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, cachedAttrViews 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{},
|
||||||
|
|
@ -111,7 +111,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
ials := BatchGetBlockAttrs(ialIDs)
|
ials := BatchGetBlockAttrs(ialIDs)
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
// 渲染自动生成的字段值,比如关联、汇总、创建时间和更新时间
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, renderedAttrViews)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, depth, cachedAttrViews)
|
||||||
|
|
||||||
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
// 最后渲染模板字段,这样模板就可以使用汇总、关联、创建时间和更新时间的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, view, ret, ials)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue