This commit is contained in:
Liang Ding 2023-03-02 18:42:19 +08:00
parent afc792b476
commit 68ef3770a9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
6 changed files with 69 additions and 26 deletions

View file

@ -27,6 +27,42 @@ import (
"github.com/siyuan-note/siyuan/kernel/treenode"
)
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
firstSrcID := operation.SrcIDs[0]
tree, err := tx.loadTree(firstSrcID)
if nil != err {
logging.LogErrorf("load tree [%s] failed: %s", firstSrcID, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: firstSrcID}
}
avID := operation.ParentID
for _, id := range operation.SrcIDs {
if err = addAttributeViewBlock(id, avID, tree); nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: avID}
}
}
return
}
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
firstSrcID := operation.SrcIDs[0]
tree, err := tx.loadTree(firstSrcID)
if nil != err {
logging.LogErrorf("load tree [%s] failed: %s", firstSrcID, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: firstSrcID}
}
avID := operation.ParentID
for _, id := range operation.SrcIDs {
if err = removeAttributeViewBlock(id, avID, tree); nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: avID}
}
}
return
return
}
func AddAttributeViewColumn(name string, typ string, columnIndex int, avID string) (err error) {
attrView, err := av.ParseAttributeView(avID)
if nil != err {
@ -47,12 +83,30 @@ func AddAttributeViewColumn(name string, typ string, columnIndex int, avID strin
return
}
func AddAttributeViewBlock(blockID, avID string) (err error) {
tree, err := loadTreeByBlockID(blockID)
func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
err = ErrBlockNotFound
return
}
attrView, err := av.ParseAttributeView(avID)
if nil != err {
return
}
for i, row := range attrView.Rows {
if row[0].Value() == blockID {
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
break
}
}
err = av.SaveAttributeView(attrView)
return
}
func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
err = ErrBlockNotFound

View file

@ -161,6 +161,7 @@ const (
TxErrCodeBlockNotFound = 0
TxErrCodeUnableAccessFile = 1
TxErrCodeWriteTree = 2
TxErrWriteAttributeView = 3
)
type TxErr struct {
@ -214,9 +215,9 @@ func performTx(tx *Transaction) (ret *TxErr) {
case "setAttrs":
ret = tx.setAttrs(op)
case "insertAttrViewBlock":
ret = tx.insertAttrViewBlock(op)
ret = tx.doInsertAttrViewBlock(op)
case "removeAttrViewBlock":
ret = tx.removeAttrViewBlock(op)
ret = tx.doRemoveAttrViewBlock(op)
}
if nil != ret {
@ -236,14 +237,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
return
}
func (tx *Transaction) insertAttrViewBlock(operation *Operation) (ret *TxErr) {
return
}
func (tx *Transaction) removeAttrViewBlock(operation *Operation) (ret *TxErr) {
return
}
func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
var err error
id := operation.ID