Skip to content

Commit

Permalink
🎨 New a row in the database no longer require to create a relevant doc
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 27, 2023
1 parent 3842a17 commit 688f3a1
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

if ast.NodeAttributeView == node.Type {
// 不能将一个属性视图拖拽到另一个属性视图中
return
}
var node *ast.Node
if "" != blockID {
node = treenode.GetNodeInTree(tree, blockID)
if nil == node {
err = ErrBlockNotFound
return
}

block := sql.BuildBlockFromNode(node, tree)
if nil == block {
err = ErrBlockNotFound
return
if ast.NodeAttributeView == node.Type {
// 不能将一个属性视图拖拽到另一个属性视图中
return
}
}

attrView, err := av.ParseAttributeView(operation.AvID)
Expand All @@ -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 {
Expand Down

0 comments on commit 688f3a1

Please sign in to comment.