mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-09 02:08:50 +01:00
🎨 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:
parent
3842a17d07
commit
688f3a13bf
1 changed files with 34 additions and 26 deletions
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -391,6 +390,16 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
if 1 > len(operation.SrcIDs) {
|
||||
// 不绑定到任何块的情况,比如直接在属性视图中添加一个块
|
||||
// New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294
|
||||
var avErr error
|
||||
if avErr = addAttributeViewBlock("", operation, nil, tx); nil != avErr {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: avErr.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, id := range operation.SrcIDs {
|
||||
tree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
|
|
@ -407,21 +416,18 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr)
|
|||
}
|
||||
|
||||
func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
var node *ast.Node
|
||||
if "" != blockID {
|
||||
node = treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
|
||||
if ast.NodeAttributeView == node.Type {
|
||||
// 不能将一个属性视图拖拽到另一个属性视图中
|
||||
return
|
||||
}
|
||||
|
||||
block := sql.BuildBlockFromNode(node, tree)
|
||||
if nil == block {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
if ast.NodeAttributeView == node.Type {
|
||||
// 不能将一个属性视图拖拽到另一个属性视图中
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
|
|
@ -445,19 +451,21 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
value := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, Block: &av.ValueBlock{ID: blockID, Content: getNodeRefText(node)}}
|
||||
blockValues.Values = append(blockValues.Values, value)
|
||||
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
if nil != node {
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
if "" == attrs[NodeAttrNameAvs] {
|
||||
attrs[NodeAttrNameAvs] = operation.AvID
|
||||
} else {
|
||||
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
|
||||
avIDs = append(avIDs, operation.AvID)
|
||||
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
}
|
||||
if "" == attrs[NodeAttrNameAvs] {
|
||||
attrs[NodeAttrNameAvs] = operation.AvID
|
||||
} else {
|
||||
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
|
||||
avIDs = append(avIDs, operation.AvID)
|
||||
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
}
|
||||
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
return
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
switch view.LayoutType {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue