🎨 Rows non-bound in the database support Add to Database
https://github.com/siyuan-note/siyuan/issues/11093
This commit is contained in:
parent
4cc2d9a6a8
commit
0f06692da4
3 changed files with 33 additions and 27 deletions
|
@ -127,12 +127,15 @@ func addAttributeViewValues(c *gin.Context) {
|
|||
if nil != arg["ignoreFillFilter"] {
|
||||
ignoreFillFilter = arg["ignoreFillFilter"].(bool)
|
||||
}
|
||||
var content string
|
||||
if nil != arg["content"] {
|
||||
content = arg["content"].(string)
|
||||
}
|
||||
|
||||
err := model.AddAttributeViewBlock(nil, srcIDs, avID, blockID, previousID, content, isDetached, ignoreFillFilter)
|
||||
var srcs []map[string]interface{}
|
||||
for _, srcID := range srcIDs {
|
||||
src := map[string]interface{}{
|
||||
"id": srcID,
|
||||
}
|
||||
srcs = append(srcs, src)
|
||||
}
|
||||
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, previousID, isDetached, ignoreFillFilter)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
@ -2165,37 +2165,39 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
err := AddAttributeViewBlock(tx, operation.SrcIDs, operation.AvID, operation.BlockID, operation.PreviousID, operation.Name, operation.IsDetached, operation.IgnoreFillFilterVal)
|
||||
err := AddAttributeViewBlock(tx, operation.Srcs, operation.AvID, operation.BlockID, operation.PreviousID, operation.IsDetached, operation.IgnoreFillFilterVal)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func AddAttributeViewBlock(tx *Transaction, srcIDs []string, avID, blockID, previousBlockID, content string, isDetached, ignoreFillFilter bool) (err error) {
|
||||
for _, id := range srcIDs {
|
||||
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, blockID, previousBlockID string, isDetached, ignoreFillFilter bool) (err error) {
|
||||
for _, src := range srcs {
|
||||
srcID := src["id"].(string)
|
||||
var tree *parse.Tree
|
||||
if !isDetached {
|
||||
var loadErr error
|
||||
if nil != tx {
|
||||
tree, loadErr = tx.loadTree(id)
|
||||
tree, loadErr = tx.loadTree(srcID)
|
||||
} else {
|
||||
tree, loadErr = LoadTreeByBlockID(id)
|
||||
tree, loadErr = LoadTreeByBlockID(srcID)
|
||||
}
|
||||
if nil != loadErr {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", id, err)
|
||||
logging.LogErrorf("load tree [%s] failed: %s", srcID, err)
|
||||
return loadErr
|
||||
}
|
||||
}
|
||||
|
||||
if avErr := addAttributeViewBlock(avID, blockID, previousBlockID, id, content, isDetached, ignoreFillFilter, tree, tx); nil != avErr {
|
||||
srcContent := src["content"].(string)
|
||||
if avErr := addAttributeViewBlock(avID, blockID, previousBlockID, srcID, srcContent, isDetached, ignoreFillFilter, tree, tx); nil != avErr {
|
||||
return avErr
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, content string, isDetached, ignoreFillFilter bool, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, addingBlockContent string, isDetached, ignoreFillFilter bool, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
var node *ast.Node
|
||||
if !isDetached {
|
||||
node = treenode.GetNodeInTree(tree, addingBlockID)
|
||||
|
@ -2216,7 +2218,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, conten
|
|||
}
|
||||
|
||||
if !isDetached {
|
||||
content = getNodeRefText(node)
|
||||
addingBlockContent = getNodeRefText(node)
|
||||
}
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
|
@ -2229,7 +2231,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, conten
|
|||
// 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要
|
||||
bindBlockAv0(tx, avID, node, tree)
|
||||
blockValue.IsDetached = isDetached
|
||||
blockValue.Block.Content = content
|
||||
blockValue.Block.Content = addingBlockContent
|
||||
blockValue.UpdatedAt = now
|
||||
err = av.SaveAttributeView(attrView)
|
||||
}
|
||||
|
@ -2245,7 +2247,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID, conten
|
|||
IsDetached: isDetached,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
Block: &av.ValueBlock{ID: addingBlockID, Content: content, Created: now, Updated: now}}
|
||||
Block: &av.ValueBlock{ID: addingBlockID, Content: addingBlockContent, Created: now, Updated: now}}
|
||||
blockValues.Values = append(blockValues.Values, blockValue)
|
||||
|
||||
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
||||
|
|
|
@ -1262,17 +1262,18 @@ type Operation struct {
|
|||
|
||||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中
|
||||
IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
Format string `json:"format"` // 属性视图列格式化
|
||||
KeyID string `json:"keyID"` // 属性视列 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
IsTwoWay bool `json:"isTwoWay"` // 属性视图关联列是否是双向关系
|
||||
BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
Srcs []map[string]interface{} `json:"srcs"` // 属性视图中多选 添加到数据库
|
||||
IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中
|
||||
IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
Format string `json:"format"` // 属性视图列格式化
|
||||
KeyID string `json:"keyID"` // 属性视列 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
IsTwoWay bool `json:"isTwoWay"` // 属性视图关联列是否是双向关系
|
||||
BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
|
||||
}
|
||||
|
||||
type Transaction struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue