mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Improve Add to Database
https://github.com/siyuan-note/siyuan/issues/10659
This commit is contained in:
parent
b332574217
commit
7b995fd16c
4 changed files with 21 additions and 8 deletions
|
@ -331,6 +331,10 @@ func addAttributeViewBlocks(c *gin.Context) {
|
|||
if blockIDArg := arg["blockID"]; nil != blockIDArg {
|
||||
blockID = blockIDArg.(string)
|
||||
}
|
||||
var viewID string
|
||||
if viewIDArg := arg["viewID"]; nil != viewIDArg {
|
||||
viewID = viewIDArg.(string)
|
||||
}
|
||||
var groupID string
|
||||
if groupIDArg := arg["groupID"]; nil != groupIDArg {
|
||||
groupID = groupIDArg.(string)
|
||||
|
@ -351,7 +355,7 @@ func addAttributeViewBlocks(c *gin.Context) {
|
|||
ignoreDefaultFill = arg["ignoreDefaultFill"].(bool)
|
||||
}
|
||||
|
||||
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, groupID, previousID, ignoreDefaultFill, map[string]interface{}{})
|
||||
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, viewID, groupID, previousID, ignoreDefaultFill, map[string]interface{}{})
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
@ -2964,14 +2964,14 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr)
|
|||
operation.Context = map[string]interface{}{}
|
||||
}
|
||||
|
||||
err := AddAttributeViewBlock(tx, operation.Srcs, operation.AvID, operation.BlockID, 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, operation.Context)
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, dbBlockID, 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, context map[string]interface{}) (err error) {
|
||||
slices.Reverse(srcs) // https://github.com/siyuan-note/siyuan/issues/11286
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
|
@ -3006,14 +3006,14 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
|
|||
if nil != src["content"] {
|
||||
srcContent = src["content"].(string)
|
||||
}
|
||||
if avErr := addAttributeViewBlock(now, avID, dbBlockID, 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, context); nil != avErr {
|
||||
return avErr
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewBlock(now int64, avID, dbBlockID, 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, context map[string]interface{}) (err error) {
|
||||
var node *ast.Node
|
||||
if !isDetached {
|
||||
node = treenode.GetNodeInTree(tree, addingBoundBlockID)
|
||||
|
@ -3085,6 +3085,14 @@ func addAttributeViewBlock(now int64, avID, dbBlockID, groupID, previousItemID,
|
|||
return
|
||||
}
|
||||
|
||||
if "" != viewID {
|
||||
view = attrView.GetView(viewID)
|
||||
if nil == view {
|
||||
logging.LogErrorf("get view by view ID [%s] failed", viewID)
|
||||
return av.ErrViewNotFound
|
||||
}
|
||||
}
|
||||
|
||||
groupView := view
|
||||
if "" != groupID {
|
||||
groupView = view.GetGroupByID(groupID)
|
||||
|
|
|
@ -991,7 +991,7 @@ func DuplicateDoc(tree *parse.Tree) {
|
|||
AddAttributeViewBlock(nil, []map[string]interface{}{{
|
||||
"id": n.ID,
|
||||
"isDetached": false,
|
||||
}}, avID, "", "", "", false, map[string]interface{}{})
|
||||
}}, avID, "", "", "", "", false, map[string]interface{}{})
|
||||
ReloadAttrView(avID)
|
||||
}
|
||||
return ast.WalkContinue
|
||||
|
|
|
@ -1099,7 +1099,7 @@ func (tx *Transaction) doLargeInsert(previousID string) (ret *TxErr) {
|
|||
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
||||
"id": insertedNode.ID,
|
||||
"isDetached": false,
|
||||
}}, avID, "", "", previousID, false, map[string]interface{}{})
|
||||
}}, avID, "", "", "", previousID, false, map[string]interface{}{})
|
||||
ReloadAttrView(avID)
|
||||
}
|
||||
|
||||
|
@ -1284,7 +1284,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
||||
"id": insertedNode.ID,
|
||||
"isDetached": false,
|
||||
}}, avID, "", "", previousID, false, map[string]interface{}{})
|
||||
}}, avID, "", "", "", previousID, false, map[string]interface{}{})
|
||||
ReloadAttrView(avID)
|
||||
}
|
||||
|
||||
|
@ -1727,6 +1727,7 @@ type Operation struct {
|
|||
Layout av.LayoutType `json:"layout"` // 属性视图布局类型
|
||||
GroupID string `json:"groupID"` // 属性视图分组视图 ID
|
||||
TargetGroupID string `json:"targetGroupID"` // 属性视图目标分组视图 ID
|
||||
ViewID string `json:"viewID"` // 属性视图视图 ID
|
||||
IgnoreDefaultFill bool `json:"ignoreDefaultFill"` // 是否忽略默认填充
|
||||
|
||||
Context map[string]interface{} `json:"context"` // 上下文信息
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue