An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442
Daniel45bfaefb1857
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 70bf634d82..6fc65d09dd 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -860,19 +860,10 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *aret.Rows = append(ret.Rows, &tableRow)}- // 渲染自动生成的列值,比如模板列、关联列、汇总列、创建时间列和更新时间列+ // 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列for _, row := range ret.Rows {for _, cell := range row.Cells {switch cell.ValueType {- case av.KeyTypeTemplate: // 渲染模板列- keyValues := rows[row.ID]- ial := map[string]string{}- block := row.GetBlockValue()- if nil != block && !block.IsDetached {- ial = GetBlockAttrsWithoutWaitWriting(row.ID)- }- content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)- cell.Value.Template.Content = contentcase av.KeyTypeRollup: // 渲染汇总列rollupKey, _ := attrView.GetKey(cell.Value.KeyID)if nil == rollupKey || nil == rollupKey.Rollup {@@ -913,6 +904,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a}cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey)++ // 将汇总列的值保存到 rows 中,后续渲染模板列的时候会用到,下同+ // Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442+ keyValues := rows[row.ID]+ keyValues = append(keyValues, &av.KeyValues{Key: rollupKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: rollupKey.ID, BlockID: row.ID, Type: av.KeyTypeRollup, Rollup: cell.Value.Rollup}}})+ rows[row.ID] = keyValuescase av.KeyTypeRelation: // 渲染关联列relKey, _ := attrView.GetKey(cell.Value.KeyID)if nil != relKey && nil != relKey.Relation {@@ -927,6 +924,10 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a}}}++ keyValues := rows[row.ID]+ keyValues = append(keyValues, &av.KeyValues{Key: relKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: relKey.ID, BlockID: row.ID, Type: av.KeyTypeRelation, Relation: cell.Value.Relation}}})+ rows[row.ID] = keyValuescase av.KeyTypeCreated: // 渲染创建时间createdStr := row.ID[:len("20060102150405")]created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)@@ -936,6 +937,11 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a} else {cell.Value.Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)}++ keyValues := rows[row.ID]+ createdKey, _ := attrView.GetKey(cell.Value.KeyID)+ keyValues = append(keyValues, &av.KeyValues{Key: createdKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: createdKey.ID, BlockID: row.ID, Type: av.KeyTypeCreated, Created: cell.Value.Created}}})+ rows[row.ID] = keyValuescase av.KeyTypeUpdated: // 渲染更新时间ial := map[string]string{}block := row.GetBlockValue()@@ -955,6 +961,29 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *acell.Value.Updated = av.NewFormattedValueUpdated(time.Now().UnixMilli(), 0, av.UpdatedFormatNone)}}++ keyValues := rows[row.ID]+ updatedKey, _ := attrView.GetKey(cell.Value.KeyID)+ keyValues = append(keyValues, &av.KeyValues{Key: updatedKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: updatedKey.ID, BlockID: row.ID, Type: av.KeyTypeUpdated, Updated: cell.Value.Updated}}})+ rows[row.ID] = keyValues+ }+ }+ }++ // 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了+ // Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442+ for _, row := range ret.Rows {+ for _, cell := range row.Cells {+ switch cell.ValueType {+ case av.KeyTypeTemplate: // 渲染模板列+ keyValues := rows[row.ID]+ ial := map[string]string{}+ block := row.GetBlockValue()+ if nil != block && !block.IsDetached {+ ial = GetBlockAttrsWithoutWaitWriting(row.ID)+ }+ content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)+ cell.Value.Template.Content = content}}}@@ -1658,7 +1687,7 @@ func addAttributeViewBlock(avID, previousBlockID, blockID string, isDetached booif 0 < len(viewable.Rows) {row := GetLastSortRow(viewable.Rows)if nil != row {- for affectKeyID, _ := range affectKeyIDs {+ for affectKeyID := range affectKeyIDs {for _, cell := range row.Cells {if nil != cell.Value && cell.Value.KeyID == affectKeyID {if av.KeyTypeBlock == cell.ValueType {@@ -1681,7 +1710,7 @@ func addAttributeViewBlock(avID, previousBlockID, blockID string, isDetached boo}notAddedValues := map[string]bool{}- for affectKeyID, _ := range affectKeyIDs {+ for affectKeyID := range affectKeyIDs {if !addedValues[affectKeyID] {notAddedValues[affectKeyID] = truebreakdiff --git a/kernel/treenode/node.go b/kernel/treenode/node.goindex 9d1967f788..f9076b07c7 100644--- a/kernel/treenode/node.go+++ b/kernel/treenode/node.go@@ -740,22 +740,10 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *aret.Rows = append(ret.Rows, &tableRow)}- // 渲染自动生成的列值,比如模板列、关联列、汇总列、创建时间列和更新时间列+ // 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列for _, row := range ret.Rows {for _, cell := range row.Cells {switch cell.ValueType {- case av.KeyTypeTemplate: // 渲染模板列- keyValues := rows[row.ID]- ial := map[string]string{}- block := row.GetBlockValue()- if nil != block && !block.IsDetached {- ial = cache.GetBlockIAL(row.ID)- if nil == ial {- ial = map[string]string{}- }- }- content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)- cell.Value.Template.Content = contentcase av.KeyTypeRollup: // 渲染汇总列rollupKey, _ := attrView.GetKey(cell.Value.KeyID)if nil == rollupKey || nil == rollupKey.Rollup {@@ -796,6 +784,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a}cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey)++ // 将汇总列的值保存到 rows 中,后续渲染模板列的时候会用到,下同+ // Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442+ keyValues := rows[row.ID]+ keyValues = append(keyValues, &av.KeyValues{Key: rollupKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: rollupKey.ID, BlockID: row.ID, Type: av.KeyTypeRollup, Rollup: cell.Value.Rollup}}})+ rows[row.ID] = keyValuescase av.KeyTypeRelation: // 渲染关联列relKey, _ := attrView.GetKey(cell.Value.KeyID)if nil != relKey && nil != relKey.Relation {@@ -819,6 +813,11 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a} else {cell.Value.Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)}++ keyValues := rows[row.ID]+ createdKey, _ := attrView.GetKey(cell.Value.KeyID)+ keyValues = append(keyValues, &av.KeyValues{Key: createdKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: createdKey.ID, BlockID: row.ID, Type: av.KeyTypeCreated, Created: cell.Value.Created}}})+ rows[row.ID] = keyValuescase av.KeyTypeUpdated: // 渲染更新时间ial := map[string]string{}block := row.GetBlockValue()@@ -841,6 +840,32 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *acell.Value.Updated = av.NewFormattedValueUpdated(time.Now().UnixMilli(), 0, av.UpdatedFormatNone)}}++ keyValues := rows[row.ID]+ updatedKey, _ := attrView.GetKey(cell.Value.KeyID)+ keyValues = append(keyValues, &av.KeyValues{Key: updatedKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: updatedKey.ID, BlockID: row.ID, Type: av.KeyTypeUpdated, Updated: cell.Value.Updated}}})+ rows[row.ID] = keyValues+ }+ }+ }++ // 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了+ // Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442+ for _, row := range ret.Rows {+ for _, cell := range row.Cells {+ switch cell.ValueType {+ case av.KeyTypeTemplate: // 渲染模板列+ keyValues := rows[row.ID]+ ial := map[string]string{}+ block := row.GetBlockValue()+ if nil != block && !block.IsDetached {+ ial = cache.GetBlockIAL(row.ID)+ if nil == ial {+ ial = map[string]string{}+ }+ }+ content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)+ cell.Value.Template.Content = content}}}