🎨 New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294

This commit is contained in:
Daniel 2023-09-28 11:17:49 +08:00
parent 4283f73407
commit 7b8d5edf77
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -907,6 +907,10 @@ func replaceAttributeViewBlock(operation *Operation) (err error) {
value.Block.ID = operation.NextID
value.IsDetached = operation.IsDetached
}
if !operation.IsDetached {
bindBlockAv(operation.AvID, operation.NextID)
}
}
}
}
@ -978,30 +982,7 @@ func UpdateAttributeViewCell(avID, keyID, rowID, cellID string, valueData interf
if oldIsDetached && !val.IsDetached {
// 将游离行绑定到新建的块上
tree, loadErr := loadTreeByBlockID(rowID)
if nil != loadErr {
logging.LogWarnf("load tree by block id [%s] failed: %s", rowID, loadErr)
} else {
node := treenode.GetNodeInTree(tree, rowID)
if nil == node {
logging.LogWarnf("node [%s] not found in tree [%s]", rowID, tree.ID)
} else {
attrs := parse.IAL2Map(node.KramdownIAL)
if "" == attrs[NodeAttrNameAvs] {
attrs[NodeAttrNameAvs] = avID
} else {
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
avIDs = append(avIDs, avID)
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
}
if err = setNodeAttrs(node, tree, attrs); nil != err {
logging.LogWarnf("set node [%s] attrs failed: %s", rowID, err)
}
}
}
bindBlockAv(avID, rowID)
}
if err = av.SaveAttributeView(attrView); nil != err {
@ -1010,6 +991,39 @@ func UpdateAttributeViewCell(avID, keyID, rowID, cellID string, valueData interf
return
}
func bindBlockAv(avID, blockID string) {
tree, loadErr := loadTreeByBlockID(blockID)
if nil != loadErr {
logging.LogWarnf("load tree by block id [%s] failed: %s", blockID, loadErr)
return
}
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
logging.LogWarnf("node [%s] not found in tree [%s]", blockID, tree.ID)
return
}
attrs := parse.IAL2Map(node.KramdownIAL)
if "" == attrs[NodeAttrNameAvs] {
attrs[NodeAttrNameAvs] = avID
} else {
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
if gulu.Str.Contains(avID, avIDs) {
return
}
avIDs = append(avIDs, avID)
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
}
if err := setNodeAttrs(node, tree, attrs); nil != err {
logging.LogWarnf("set node [%s] attrs failed: %s", blockID, err)
}
return
}
func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {
err := updateAttributeViewColumnOptions(operation)
if nil != err {