From 863eb5e5703dd348af78b9080d4056d9fc1bb2b4 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 23:14:42 +0800 Subject: [PATCH] :art: New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294 --- kernel/av/av.go | 9 +++++---- kernel/model/attribute_view.go | 14 ++++++++++---- kernel/model/transaction.go | 15 ++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/kernel/av/av.go b/kernel/av/av.go index 602e96410..2d50e2848 100644 --- a/kernel/av/av.go +++ b/kernel/av/av.go @@ -94,10 +94,11 @@ type KeySelectOption struct { } type Value struct { - ID string `json:"id,omitempty"` - KeyID string `json:"keyID,omitempty"` - BlockID string `json:"blockID,omitempty"` - Type KeyType `json:"type,omitempty"` + ID string `json:"id,omitempty"` + KeyID string `json:"keyID,omitempty"` + BlockID string `json:"blockID,omitempty"` + Type KeyType `json:"type,omitempty"` + IsDetached bool `json:"isDetached,omitempty"` Block *ValueBlock `json:"block,omitempty"` Text *ValueText `json:"text,omitempty"` diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index e8d23ab30..8fe906917 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -171,8 +171,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a } // 过滤掉不存在的行 - notFound := []string{} - for blockID, _ := range rows { + var notFound []string + for blockID, v := range rows { + if v[0].IsDetached { + continue + } + if treenode.GetBlockTree(blockID) == nil { notFound = append(notFound, blockID) } @@ -417,7 +421,7 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tree, tx *Transaction) (err error) { var node *ast.Node - if "" != blockID { + if !operation.IsDetached { node = treenode.GetNodeInTree(tree, blockID) if nil == node { err = ErrBlockNotFound @@ -428,6 +432,8 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre // 不能将一个属性视图拖拽到另一个属性视图中 return } + } else { + blockID = ast.NewNodeID() } attrView, err := av.ParseAttributeView(operation.AvID) @@ -448,7 +454,7 @@ 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)}} + value := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, IsDetached: operation.IsDetached, Block: &av.ValueBlock{ID: blockID, Content: getNodeRefText(node)}} blockValues.Values = append(blockValues.Values, value) if nil != node { diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 90efbf22c..18c455cf3 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -1099,13 +1099,14 @@ type Operation struct { DeckID string `json:"deckID"` // 用于添加/删除闪卡 - AvID string `json:"avID"` // 属性视图 ID - SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中 - Name string `json:"name"` // 属性视图列名 - Typ string `json:"type"` // 属性视图列类型 - Format string `json:"format"` // 属性视图列格式化 - KeyID string `json:"keyID"` // 属性视列 ID - RowID string `json:"rowID"` // 属性视图行 ID + AvID string `json:"avID"` // 属性视图 ID + SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中 + IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中 + Name string `json:"name"` // 属性视图列名 + Typ string `json:"type"` // 属性视图列类型 + Format string `json:"format"` // 属性视图列格式化 + KeyID string `json:"keyID"` // 属性视列 ID + RowID string `json:"rowID"` // 属性视图行 ID discard bool // 用于标识是否在事务合并中丢弃 }