Browse Source

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

Daniel 2 năm trước cách đây
mục cha
commit
2a8de9733e
2 tập tin đã thay đổi với 36 bổ sung0 xóa
  1. 34 0
      kernel/model/attribute_view.go
  2. 2 0
      kernel/model/transaction.go

+ 34 - 0
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 {

+ 2 - 0
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 {