mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
1ccdb4c576
commit
05e9133c7c
1 changed files with 21 additions and 30 deletions
|
|
@ -274,21 +274,35 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
}
|
||||
|
||||
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
var avs []*av.AttributeView
|
||||
avID := operation.ParentID
|
||||
for _, id := range operation.SrcIDs {
|
||||
var av *av.AttributeView
|
||||
var avErr error
|
||||
if av, avErr = removeAttributeViewBlock(id, avID); nil != avErr {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||
if avErr = removeAttributeViewBlock(id, operation); nil != avErr {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if nil == av {
|
||||
func removeAttributeViewBlock(blockID string, operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for i, row := range attrView.Rows {
|
||||
blockCell := row.GetBlockCell()
|
||||
if nil == blockCell {
|
||||
continue
|
||||
}
|
||||
|
||||
avs = append(avs, av)
|
||||
if blockCell.Value.Block.ID == blockID {
|
||||
// 从行中移除,但是不移除属性
|
||||
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -844,29 +858,6 @@ func setAttributeView(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func removeAttributeViewBlock(blockID, avID string) (ret *av.AttributeView, err error) {
|
||||
ret, err = av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for i, row := range ret.Rows {
|
||||
blockCell := row.GetBlockCell()
|
||||
if nil == blockCell {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockCell.Value.Block.ID == blockID {
|
||||
// 从行中移除,但是不移除属性
|
||||
ret.Rows = append(ret.Rows[:i], ret.Rows[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(ret)
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
NodeAttrNameAVs = "custom-avs"
|
||||
NodeAttrNamePrefixAvCol = "custom-av-col-"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue