Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Block data sync to Attribute View https://github.com/siyuan-note/siyuan/issues/8696

Daniel060d93339004
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 9550deb802..202eb5fe8d 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -40,9 +40,10 @@ type AttributeView struct {
Columns []*Column `json:"columns"` // 表格列名
Rows []*Row `json:"rows"` // 表格行记录
- Type AttributeViewType `json:"type"` // 属性视图类型
- Filters []*AttributeViewFilter `json:"filters"` // 过滤规则
- Sorts []*AttributeViewSort `json:"sorts"` // 排序规则
+ Type AttributeViewType `json:"type"` // 属性视图类型
+ Filters []*AttributeViewFilter `json:"filters"` // 过滤规则
+ Sorts []*AttributeViewSort `json:"sorts"` // 排序规则
+ Calculates []*AttributeViewCalc `json:"calculates"` // 计算规则
}
// AttributeViewType 描述了属性视图的类型。
@@ -98,6 +99,17 @@ const (
FilterOperatorIsRelativeToToday FilterOperator = "Is relative to today"
)
+type AttributeViewCalc struct {
+ Column string `json:"column"`
+ Operator CalcOperator `json:"operator"`
+}
+
+type CalcOperator string
+
+const (
+ CalcOperatorIsEqual FilterOperator = "="
+)
+
type AttributeViewSort struct {
Column string `json:"column"` // 列 ID
Order SortOrder `json:"order"` // 排序顺序
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index ba20ce367d..9f6a6cc2b9 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -558,6 +558,6 @@ func addAttributeViewBlock(blockID, previousRowID, avID string, tree *parse.Tree
}
const (
- NodeAttrNameAVs = "avs"
- NodeAttrNamePrefixAvCol = "av-col-"
+ NodeAttrNameAVs = "custom-avs"
+ NodeAttrNamePrefixAvCol = "custom-av-col-"
)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 124d19238c..06254f890c 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -19,6 +19,7 @@ package model
import (
"bytes"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/av"
"path/filepath"
"strings"
"sync"
@@ -1188,7 +1189,41 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
}
}
- // TODO 2. 更新属性视图主键内容
+ // 2. 更新属性视图主键内容
+ for _, updatedDefNode := range updatedDefNodes {
+ avs := updatedDefNode.IALAttr(NodeAttrNameAVs)
+ if "" == avs {
+ continue
+ }
+
+ avIDs := strings.Split(avs, ",")
+ for _, avID := range avIDs {
+ attrView, parseErr := av.ParseAttributeView(avID)
+ if nil != parseErr {
+ continue
+ }
+
+ changedAv := false
+ for _, row := range attrView.Rows {
+ blockCell := row.GetBlockCell()
+ if nil == blockCell || nil == blockCell.Value || nil == blockCell.Value.Block {
+ continue
+ }
+
+ if blockCell.Value.Block.ID == updatedDefNode.ID {
+ newContent := getNodeRefText(updatedDefNode)
+ if newContent != blockCell.Value.Block.Content {
+ blockCell.Value.Block.Content = newContent
+ changedAv = true
+ }
+ break
+ }
+ }
+ if changedAv {
+ av.SaveAttributeView(attrView)
+ }
+ }
+ }
// 3. 保存变更
for _, tree := range changedRefTree {