mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +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) {
|
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||||
var avs []*av.AttributeView
|
|
||||||
avID := operation.ParentID
|
|
||||||
for _, id := range operation.SrcIDs {
|
for _, id := range operation.SrcIDs {
|
||||||
var av *av.AttributeView
|
|
||||||
var avErr error
|
var avErr error
|
||||||
if av, avErr = removeAttributeViewBlock(id, avID); nil != avErr {
|
if avErr = removeAttributeViewBlock(id, operation); nil != avErr {
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
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
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -844,29 +858,6 @@ func setAttributeView(operation *Operation) (err error) {
|
||||||
return
|
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 (
|
const (
|
||||||
NodeAttrNameAVs = "custom-avs"
|
NodeAttrNameAVs = "custom-avs"
|
||||||
NodeAttrNamePrefixAvCol = "custom-av-col-"
|
NodeAttrNamePrefixAvCol = "custom-av-col-"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue