Skip to content

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

:art: Add select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8694

Daniel2a8de9733eb0
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 0d56039737..e4d1272d00 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -167,6 +167,14 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
return
}
+func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {
+ err := updateAttributeViewColumnOptions(operation.Data, operation.ID, operation.ParentID)
+ if nil != err {
+ return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
+ }
+ return
+}
+
func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) {
err := addAttributeViewColumn(operation.Name, operation.Typ, operation.ParentID)
if nil != err {
@@ -291,6 +299,32 @@ func updateAttributeViewColumn(id, name string, typ string, avID string) (err er
return
}
+func updateAttributeViewColumnOptions(data interface{}, id, avID string) (err error) {
+ attrView, err := av.ParseAttributeView(avID)
+ if nil != err {
+ return
+ }
+
+ jsonData, err := gulu.JSON.MarshalJSON(data)
+ if nil != err {
+ return
+ }
+
+ options := []*av.ColumnSelectOption{}
+ if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {
+ return
+ }
+
+ for _, col := range attrView.Columns {
+ if col.ID == id {
+ col.Options = options
+ err = av.SaveAttributeView(attrView)
+ return
+ }
+ }
+ return
+}
+
func removeAttributeViewColumn(columnID string, avID string) (err error) {
attrView, err := av.ParseAttributeView(avID)
if nil != err {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index aef447dbdb..eecb31d1dd 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -241,6 +241,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewColumnWidth(op)
case "setAttrView":
ret = tx.doSetAttrView(op)
+ case "updateAttrViewColOptions":
+ ret = tx.doUpdateAttrViewColOptions(op)
}
if nil != ret {