mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-04 20:00:17 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
91a773e6af
4 changed files with 57 additions and 51 deletions
|
|
@ -456,7 +456,7 @@ func addAttributeViewBlocks(c *gin.Context) {
|
|||
ignoreDefaultFill = arg["ignoreDefaultFill"].(bool)
|
||||
}
|
||||
|
||||
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, viewID, groupID, previousID, ignoreDefaultFill, map[string]interface{}{})
|
||||
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, viewID, groupID, previousID, ignoreDefaultFill)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
|||
|
|
@ -3457,18 +3457,14 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
if nil == operation.Context {
|
||||
operation.Context = map[string]interface{}{}
|
||||
}
|
||||
|
||||
err := AddAttributeViewBlock(tx, operation.Srcs, operation.AvID, operation.BlockID, operation.ViewID, operation.GroupID, operation.PreviousID, operation.IgnoreDefaultFill, operation.Context)
|
||||
err := AddAttributeViewBlock(tx, operation.Srcs, operation.AvID, operation.BlockID, operation.ViewID, operation.GroupID, operation.PreviousID, operation.IgnoreDefaultFill)
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, dbBlockID, viewID, groupID, previousItemID string, ignoreDefaultFill bool, context map[string]interface{}) (err error) {
|
||||
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, dbBlockID, viewID, groupID, previousItemID string, ignoreDefaultFill bool) (err error) {
|
||||
slices.Reverse(srcs) // https://github.com/siyuan-note/siyuan/issues/11286
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
|
|
@ -3503,14 +3499,14 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
|
|||
if nil != src["content"] {
|
||||
srcContent = src["content"].(string)
|
||||
}
|
||||
if avErr := addAttributeViewBlock(now, avID, dbBlockID, viewID, groupID, previousItemID, srcItemID, boundBlockID, srcContent, isDetached, ignoreDefaultFill, tree, tx, context); nil != avErr {
|
||||
if avErr := addAttributeViewBlock(now, avID, dbBlockID, viewID, groupID, previousItemID, srcItemID, boundBlockID, srcContent, isDetached, ignoreDefaultFill, tree, tx); nil != avErr {
|
||||
return avErr
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewBlock(now int64, avID, dbBlockID, viewID, groupID, previousItemID, addingItemID, addingBoundBlockID, addingBlockContent string, isDetached, ignoreDefaultFill bool, tree *parse.Tree, tx *Transaction, context map[string]interface{}) (err error) {
|
||||
func addAttributeViewBlock(now int64, avID, dbBlockID, viewID, groupID, previousItemID, addingItemID, addingBoundBlockID, addingBlockContent string, isDetached, ignoreDefaultFill bool, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
var node *ast.Node
|
||||
if !isDetached {
|
||||
node = treenode.GetNodeInTree(tree, addingBoundBlockID)
|
||||
|
|
|
|||
|
|
@ -1603,7 +1603,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) (ret *parse.Tree) {
|
|||
continue
|
||||
}
|
||||
|
||||
syncDelete2AvBlock(removeTree.Root, removeTree, nil)
|
||||
syncDelete2AvBlock(removeTree.Root, removeTree, true, nil)
|
||||
}
|
||||
|
||||
if existChildren {
|
||||
|
|
|
|||
|
|
@ -1011,12 +1011,12 @@ func (tx *Transaction) doDelete0(operation *Operation, tree *parse.Tree) {
|
|||
}
|
||||
|
||||
if needSyncDel2AvBlock {
|
||||
syncDelete2AvBlock(node, tree, tx)
|
||||
syncDelete2AvBlock(node, tree, true, tx)
|
||||
}
|
||||
}
|
||||
|
||||
func syncDelete2AvBlock(node *ast.Node, nodeTree *parse.Tree, tx *Transaction) {
|
||||
changedAvIDs := syncDelete2AttributeView(node)
|
||||
func syncDelete2AvBlock(node *ast.Node, nodeTree *parse.Tree, delChildrenWhenDelParent bool, tx *Transaction) {
|
||||
changedAvIDs := syncDelete2AttributeView(node, delChildrenWhenDelParent)
|
||||
avIDs := tx.syncDelete2Block(node, nodeTree)
|
||||
changedAvIDs = append(changedAvIDs, avIDs...)
|
||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||
|
|
@ -1078,48 +1078,18 @@ func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (c
|
|||
return
|
||||
}
|
||||
|
||||
func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
||||
func syncDelete2AttributeView(node *ast.Node, delChildrenWhenDelParent bool) (changedAvIDs []string) {
|
||||
if !delChildrenWhenDelParent {
|
||||
changedAvIDs = deleteAttrView(node, changedAvIDs)
|
||||
return
|
||||
}
|
||||
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
avs := n.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
avIDs := strings.Split(avs, ",")
|
||||
for _, avID := range avIDs {
|
||||
attrView, parseErr := av.ParseAttributeView(avID)
|
||||
if nil != parseErr {
|
||||
continue
|
||||
}
|
||||
|
||||
changedAv := false
|
||||
blockValues := attrView.GetBlockKeyValues()
|
||||
if nil == blockValues {
|
||||
continue
|
||||
}
|
||||
|
||||
for i, blockValue := range blockValues.Values {
|
||||
if nil == blockValue.Block {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockValue.Block.ID == n.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if changedAv {
|
||||
regenAttrViewGroups(attrView)
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs = append(changedAvIDs, avID)
|
||||
}
|
||||
}
|
||||
changedAvIDs = append(changedAvIDs, deleteAttrView(n, changedAvIDs)...)
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
|
|
@ -1127,6 +1097,46 @@ func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func deleteAttrView(n *ast.Node, changedAvIDs []string) []string {
|
||||
avs := n.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return nil
|
||||
}
|
||||
|
||||
avIDs := strings.Split(avs, ",")
|
||||
for _, avID := range avIDs {
|
||||
attrView, parseErr := av.ParseAttributeView(avID)
|
||||
if nil != parseErr {
|
||||
continue
|
||||
}
|
||||
|
||||
changedAv := false
|
||||
blockValues := attrView.GetBlockKeyValues()
|
||||
if nil == blockValues {
|
||||
continue
|
||||
}
|
||||
|
||||
for i, blockValue := range blockValues.Values {
|
||||
if nil == blockValue.Block {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockValue.Block.ID == n.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if changedAv {
|
||||
regenAttrViewGroups(attrView)
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs = append(changedAvIDs, avID)
|
||||
}
|
||||
}
|
||||
return changedAvIDs
|
||||
}
|
||||
|
||||
func (tx *Transaction) doLargeInsert(operations []*Operation) {
|
||||
tree, _ := tx.loadTree(operations[0].ID)
|
||||
if nil == tree {
|
||||
|
|
@ -1482,7 +1492,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
|
||||
removedNodes := getRemovedNodes(oldNode, updatedNode)
|
||||
for _, n := range removedNodes {
|
||||
syncDelete2AvBlock(n, tree, tx)
|
||||
syncDelete2AvBlock(n, tree, false, tx)
|
||||
}
|
||||
|
||||
// 将不属于折叠标题的块移动到折叠标题下方,需要展开折叠标题
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue