Skip to content

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

:art: Attribute View columns calculate https://github.com/siyuan-note/siyuan/issues/8699

Daniel3a7e0cd014b2
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 1a6fe83abe..1027c6650b 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -258,6 +258,50 @@ func setAttributeViewSorts(operation *Operation) (err error) {
return
}
+func (tx *Transaction) doSetAttrViewColCalc(operation *Operation) (ret *TxErr) {
+ err := setAttributeViewColumnCalc(operation)
+ if nil != err {
+ return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
+ }
+ return
+}
+
+func setAttributeViewColumnCalc(operation *Operation) (err error) {
+ attrView, err := av.ParseAttributeView(operation.AvID)
+ if nil != err {
+ return
+ }
+
+ view, err := attrView.GetView()
+ if nil != err {
+ return
+ }
+
+ operationData := operation.Data.([]interface{})
+ data, err := gulu.JSON.MarshalJSON(operationData)
+ if nil != err {
+ return
+ }
+
+ calc := &av.ColumnCalc{}
+ switch view.LayoutType {
+ case av.LayoutTypeTable:
+ if err = gulu.JSON.UnmarshalJSON(data, calc); nil != err {
+ return
+ }
+
+ for _, column := range view.Table.Columns {
+ if column.ID == operation.ID {
+ column.Calc = calc
+ break
+ }
+ }
+ }
+
+ err = av.SaveAttributeView(attrView)
+ return
+}
+
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
firstSrcID := operation.SrcIDs[0]
tree, err := tx.loadTree(firstSrcID)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index aa46372846..bca88c1eeb 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -251,6 +251,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doRemoveAttrViewColOption(op)
case "updateAttrViewColOption":
ret = tx.doUpdateAttrViewColOption(op)
+ case "setAttrViewColCalc":
+ ret = tx.doSetAttrViewColCalc(op)
}
if nil != ret {