mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 The database rollup field supports using the template field https://github.com/siyuan-note/siyuan/issues/12384
This commit is contained in:
parent
bc16cd658f
commit
f2dda8b389
4 changed files with 22 additions and 10 deletions
|
|
@ -3422,7 +3422,9 @@ func getAttrViewTable(attrView *av.AttributeView, view *av.View, query string) (
|
||||||
view.Table.Columns = append(view.Table.Columns, &av.ViewTableColumn{BaseField: &av.BaseField{ID: field.ID}})
|
view.Table.Columns = append(view.Table.Columns, &av.ViewTableColumn{BaseField: &av.BaseField{ID: field.ID}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = sql.RenderAttributeViewTable(attrView, view, query)
|
|
||||||
|
depth := 1
|
||||||
|
ret = sql.RenderAttributeViewTable(attrView, view, query, &depth)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,20 @@ 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
|
||||||
|
return renderView(attrView, view, query, &depth)
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret av.Viewable) {
|
||||||
|
if 7 < *depth {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch view.LayoutType {
|
switch view.LayoutType {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
ret = RenderAttributeViewTable(attrView, view, query)
|
ret = RenderAttributeViewTable(attrView, view, query, depth)
|
||||||
case av.LayoutTypeGallery:
|
case av.LayoutTypeGallery:
|
||||||
ret = RenderAttributeViewGallery(attrView, view, query)
|
ret = RenderAttributeViewGallery(attrView, view, query, depth)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -285,7 +294,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) {
|
||||||
avCache := map[string]*av.AttributeView{}
|
avCache := map[string]*av.AttributeView{}
|
||||||
avCache[attrView.ID] = attrView
|
avCache[attrView.ID] = attrView
|
||||||
for _, item := range collection.GetItems() {
|
for _, item := range collection.GetItems() {
|
||||||
|
|
@ -336,12 +345,13 @@ 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], "")
|
// 渲染目标视图,这样才能汇总渲染后的模板字段值
|
||||||
|
viewable = renderView(destAv, destAv.Views[0], "", depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 == destVal && av.KeyTypeTemplate == destKey.Type && nil != viewable {
|
if nil != viewable && nil == destVal && av.KeyTypeTemplate == destKey.Type {
|
||||||
destVal = viewable.(av.Collection).GetValue(blockID, destKey.ID)
|
destVal = viewable.(av.Collection).GetValue(blockID, destKey.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ 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) (ret *av.Gallery) {
|
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string, depth *int) (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 +114,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
ials := BatchGetBlockAttrsWitTrees(ialIDs, boundTrees)
|
||||||
|
|
||||||
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
|
// 渲染自动生成的字段值,比如关联字段、汇总字段、创建时间字段和更新时间字段
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, cardsValues, depth)
|
||||||
|
|
||||||
// 最后单独渲染模板字段,这样模板字段就可以使用汇总、关联、创建时间和更新时间字段的值了
|
// 最后单独渲染模板字段,这样模板字段就可以使用汇总、关联、创建时间和更新时间字段的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, cardsValues)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ 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) (ret *av.Table) {
|
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, depth *int) (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 +107,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
ials := BatchGetBlockAttrs(ialIDs)
|
ials := BatchGetBlockAttrs(ialIDs)
|
||||||
|
|
||||||
// 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列
|
// 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列
|
||||||
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues)
|
fillAttributeViewAutoGeneratedValues(attrView, ret, ials, rowsValues, depth)
|
||||||
|
|
||||||
// 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了
|
// 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了
|
||||||
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
renderTemplateErr := fillAttributeViewTemplateValues(attrView, ret, ials, rowsValues)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue