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 {
|
if blockIDArg := arg["blockID"]; nil != blockIDArg {
|
||||||
blockID = blockIDArg.(string)
|
blockID = blockIDArg.(string)
|
||||||
}
|
}
|
||||||
|
var viewID string
|
||||||
|
if viewIDArg := arg["viewID"]; nil != viewIDArg {
|
||||||
|
viewID = viewIDArg.(string)
|
||||||
|
}
|
||||||
var groupID string
|
var groupID string
|
||||||
if groupIDArg := arg["groupID"]; nil != groupIDArg {
|
if groupIDArg := arg["groupID"]; nil != groupIDArg {
|
||||||
groupID = groupIDArg.(string)
|
groupID = groupIDArg.(string)
|
||||||
|
@ -351,7 +355,7 @@ func addAttributeViewBlocks(c *gin.Context) {
|
||||||
ignoreDefaultFill = arg["ignoreDefaultFill"].(bool)
|
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 {
|
if err != nil {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
@ -2964,14 +2964,14 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr)
|
||||||
operation.Context = map[string]interface{}{}
|
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 {
|
if err != nil {
|
||||||
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
}
|
}
|
||||||
return
|
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
|
slices.Reverse(srcs) // https://github.com/siyuan-note/siyuan/issues/11286
|
||||||
|
|
||||||
now := time.Now().UnixMilli()
|
now := time.Now().UnixMilli()
|
||||||
|
@ -3006,14 +3006,14 @@ func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID,
|
||||||
if nil != src["content"] {
|
if nil != src["content"] {
|
||||||
srcContent = src["content"].(string)
|
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 avErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
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
|
var node *ast.Node
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
node = treenode.GetNodeInTree(tree, addingBoundBlockID)
|
node = treenode.GetNodeInTree(tree, addingBoundBlockID)
|
||||||
|
@ -3085,6 +3085,14 @@ func addAttributeViewBlock(now int64, avID, dbBlockID, groupID, previousItemID,
|
||||||
return
|
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
|
groupView := view
|
||||||
if "" != groupID {
|
if "" != groupID {
|
||||||
groupView = view.GetGroupByID(groupID)
|
groupView = view.GetGroupByID(groupID)
|
||||||
|
|
|
@ -991,7 +991,7 @@ func DuplicateDoc(tree *parse.Tree) {
|
||||||
AddAttributeViewBlock(nil, []map[string]interface{}{{
|
AddAttributeViewBlock(nil, []map[string]interface{}{{
|
||||||
"id": n.ID,
|
"id": n.ID,
|
||||||
"isDetached": false,
|
"isDetached": false,
|
||||||
}}, avID, "", "", "", false, map[string]interface{}{})
|
}}, avID, "", "", "", "", false, map[string]interface{}{})
|
||||||
ReloadAttrView(avID)
|
ReloadAttrView(avID)
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
|
@ -1099,7 +1099,7 @@ func (tx *Transaction) doLargeInsert(previousID string) (ret *TxErr) {
|
||||||
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
||||||
"id": insertedNode.ID,
|
"id": insertedNode.ID,
|
||||||
"isDetached": false,
|
"isDetached": false,
|
||||||
}}, avID, "", "", previousID, false, map[string]interface{}{})
|
}}, avID, "", "", "", previousID, false, map[string]interface{}{})
|
||||||
ReloadAttrView(avID)
|
ReloadAttrView(avID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,7 +1284,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||||
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
AddAttributeViewBlock(tx, []map[string]interface{}{{
|
||||||
"id": insertedNode.ID,
|
"id": insertedNode.ID,
|
||||||
"isDetached": false,
|
"isDetached": false,
|
||||||
}}, avID, "", "", previousID, false, map[string]interface{}{})
|
}}, avID, "", "", "", previousID, false, map[string]interface{}{})
|
||||||
ReloadAttrView(avID)
|
ReloadAttrView(avID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1727,6 +1727,7 @@ type Operation struct {
|
||||||
Layout av.LayoutType `json:"layout"` // 属性视图布局类型
|
Layout av.LayoutType `json:"layout"` // 属性视图布局类型
|
||||||
GroupID string `json:"groupID"` // 属性视图分组视图 ID
|
GroupID string `json:"groupID"` // 属性视图分组视图 ID
|
||||||
TargetGroupID string `json:"targetGroupID"` // 属性视图目标分组视图 ID
|
TargetGroupID string `json:"targetGroupID"` // 属性视图目标分组视图 ID
|
||||||
|
ViewID string `json:"viewID"` // 属性视图视图 ID
|
||||||
IgnoreDefaultFill bool `json:"ignoreDefaultFill"` // 是否忽略默认填充
|
IgnoreDefaultFill bool `json:"ignoreDefaultFill"` // 是否忽略默认填充
|
||||||
|
|
||||||
Context map[string]interface{} `json:"context"` // 上下文信息
|
Context map[string]interface{} `json:"context"` // 上下文信息
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue