Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-04-20 12:18:44 +08:00
commit 895ebccc9f
3 changed files with 42 additions and 24 deletions

View file

@ -128,7 +128,14 @@ func addAttributeViewValues(c *gin.Context) {
ignoreFillFilter = arg["ignoreFillFilter"].(bool)
}
err := model.AddAttributeViewBlock(nil, srcIDs, avID, blockID, previousID, isDetached, ignoreFillFilter)
var srcs []map[string]interface{}
for _, srcID := range srcIDs {
src := map[string]interface{}{
"id": srcID,
}
srcs = append(srcs, src)
}
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, previousID, isDetached, ignoreFillFilter)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()

View file

@ -2165,37 +2165,48 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
}
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
err := AddAttributeViewBlock(tx, operation.SrcIDs, operation.AvID, operation.BlockID, operation.PreviousID, operation.IsDetached, operation.IgnoreFillFilterVal)
var srcs []map[string]interface{}
if 0 < len(operation.Srcs) {
srcs = operation.Srcs
} else {
for _, srcID := range operation.SrcIDs {
srcs = append(srcs, map[string]interface{}{"id": srcID})
}
}
err := AddAttributeViewBlock(tx, srcs, operation.AvID, operation.BlockID, operation.PreviousID, operation.IsDetached, operation.IgnoreFillFilterVal)
if nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
func AddAttributeViewBlock(tx *Transaction, srcIDs []string, avID, blockID, previousBlockID string, isDetached, ignoreFillFilter bool) (err error) {
for _, id := range srcIDs {
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, blockID, previousBlockID string, isDetached, ignoreFillFilter bool) (err error) {
for _, src := range srcs {
srcID := src["id"].(string)
var tree *parse.Tree
if !isDetached {
var loadErr error
if nil != tx {
tree, loadErr = tx.loadTree(id)
tree, loadErr = tx.loadTree(srcID)
} else {
tree, loadErr = LoadTreeByBlockID(id)
tree, loadErr = LoadTreeByBlockID(srcID)
}
if nil != loadErr {
logging.LogErrorf("load tree [%s] failed: %s", id, err)
logging.LogErrorf("load tree [%s] failed: %s", srcID, err)
return loadErr
}
}
if avErr := addAttributeViewBlock(avID, blockID, previousBlockID, id, isDetached, ignoreFillFilter, tree, tx); nil != avErr {
srcContent := src["content"].(string)
if avErr := addAttributeViewBlock(avID, blockID, previousBlockID, srcID, srcContent, isDetached, ignoreFillFilter, tree, tx); nil != avErr {
return avErr
}
}
return
}
func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string, isDetached, ignoreFillFilter bool, tree *parse.Tree, tx *Transaction) (err error) {
func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, addingBlockContent string, isDetached, ignoreFillFilter bool, tree *parse.Tree, tx *Transaction) (err error) {
var node *ast.Node
if !isDetached {
node = treenode.GetNodeInTree(tree, addingBlockID)
@ -2215,9 +2226,8 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
return
}
var content string
if !isDetached {
content = getNodeRefText(node)
addingBlockContent = getNodeRefText(node)
}
now := time.Now().UnixMilli()
@ -2230,7 +2240,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
// 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要
bindBlockAv0(tx, avID, node, tree)
blockValue.IsDetached = isDetached
blockValue.Block.Content = content
blockValue.Block.Content = addingBlockContent
blockValue.UpdatedAt = now
err = av.SaveAttributeView(attrView)
}
@ -2246,7 +2256,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
IsDetached: isDetached,
CreatedAt: now,
UpdatedAt: now,
Block: &av.ValueBlock{ID: addingBlockID, Content: content, Created: now, Updated: now}}
Block: &av.ValueBlock{ID: addingBlockID, Content: addingBlockContent, Created: now, Updated: now}}
blockValues.Values = append(blockValues.Values, blockValue)
// 如果存在过滤条件,则将过滤条件应用到新添加的块上

View file

@ -1262,17 +1262,18 @@ type Operation struct {
DeckID string `json:"deckID"` // 用于添加/删除闪卡
AvID string `json:"avID"` // 属性视图 ID
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中
IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值
Name string `json:"name"` // 属性视图列名
Typ string `json:"type"` // 属性视图列类型
Format string `json:"format"` // 属性视图列格式化
KeyID string `json:"keyID"` // 属性视列 ID
RowID string `json:"rowID"` // 属性视图行 ID
IsTwoWay bool `json:"isTwoWay"` // 属性视图关联列是否是双向关系
BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
AvID string `json:"avID"` // 属性视图 ID
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
Srcs []map[string]interface{} `json:"srcs"` // 属性视图中多选 添加到数据库
IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中
IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值
Name string `json:"name"` // 属性视图列名
Typ string `json:"type"` // 属性视图列类型
Format string `json:"format"` // 属性视图列格式化
KeyID string `json:"keyID"` // 属性视列 ID
RowID string `json:"rowID"` // 属性视图行 ID
IsTwoWay bool `json:"isTwoWay"` // 属性视图关联列是否是双向关系
BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
}
type Transaction struct {