diff --git a/kernel/api/av.go b/kernel/api/av.go index b1c9426dd..a4843cde6 100644 --- a/kernel/api/av.go +++ b/kernel/api/av.go @@ -77,3 +77,21 @@ func getAttributeViewKeys(c *gin.Context) { blockAttributeViewKeys := model.GetBlockAttributeViewKeys(id) ret.Data = blockAttributeViewKeys } + +func setAttributeViewBlockAttrs(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + avID := arg["avID"].(string) + keyID := arg["keyID"].(string) + rowID := arg["rowID"].(string) + cellID := arg["cellID"].(string) + value := arg["value"].(interface{}) + blockAttributeViewKeys := model.UpdateAttributeViewCell(avID, keyID, rowID, cellID, value) + ret.Data = blockAttributeViewKeys +} diff --git a/kernel/api/router.go b/kernel/api/router.go index 8ebb5568d..17f6e8a09 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -360,6 +360,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView) ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys) + ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttrs", model.CheckAuth, setAttributeViewBlockAttrs) ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckReadonly, chatGPT) ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckReadonly, chatGPTWithAction) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index c0eeb642f..20ae85818 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -816,19 +816,24 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) { } func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error) { - attrView, err := av.ParseAttributeView(operation.AvID) + err = UpdateAttributeViewCell(operation.AvID, operation.KeyID, operation.RowID, operation.ID, operation.Data) + return +} + +func UpdateAttributeViewCell(avID, keyID, rowID, cellID string, value interface{}) (err error) { + attrView, err := av.ParseAttributeView(avID) if nil != err { return } var val *av.Value for _, keyValues := range attrView.KeyValues { - if operation.KeyID != keyValues.Key.ID { + if keyID != keyValues.Key.ID { continue } for _, value := range keyValues.Values { - if operation.ID == value.ID { + if cellID == value.ID { val = value val.Type = keyValues.Key.Type break @@ -836,13 +841,13 @@ func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error) } if nil == val { - val = &av.Value{ID: operation.ID, KeyID: keyValues.Key.ID, BlockID: operation.RowID, Type: keyValues.Key.Type} + val = &av.Value{ID: cellID, KeyID: keyValues.Key.ID, BlockID: rowID, Type: keyValues.Key.Type} keyValues.Values = append(keyValues.Values, val) } break } - tree, err := tx.loadTree(val.BlockID) + tree, err := loadTreeByBlockID(val.BlockID) if nil != err { return } @@ -852,7 +857,7 @@ func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error) return } - data, err := gulu.JSON.MarshalJSON(operation.Data) + data, err := gulu.JSON.MarshalJSON(value) if nil != err { return } @@ -861,8 +866,9 @@ func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error) } attrs := parse.IAL2Map(node.KramdownIAL) - attrs[NodeAttrNamePrefixAvKey+operation.AvID+"-"+val.KeyID] = val.ToJSONString() - if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err { + attrs[NodeAttrNamePrefixAvKey+avID+"-"+val.KeyID] = val.ToJSONString() + + if err = setNodeAttrs(node, tree, attrs); nil != err { return }