mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 07:48:49 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
05e9133c7c
commit
c605c496ee
2 changed files with 89 additions and 90 deletions
|
|
@ -258,11 +258,11 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
return
|
||||
}
|
||||
|
||||
if "" == operation.PreviousRowID {
|
||||
if "" == operation.PreviousID {
|
||||
attrView.Rows = append([]*av.Row{row}, attrView.Rows...)
|
||||
} else {
|
||||
for i, r := range attrView.Rows {
|
||||
if r.ID == operation.PreviousRowID {
|
||||
if r.ID == operation.PreviousID {
|
||||
attrView.Rows = append(attrView.Rows[:i+1], append([]*av.Row{row}, attrView.Rows[i+1:]...)...)
|
||||
break
|
||||
}
|
||||
|
|
@ -306,6 +306,81 @@ func removeAttributeViewBlock(blockID string, operation *Operation) (err error)
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnWidth(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColWidth(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColWidth(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == operation.ID {
|
||||
column.Width = operation.Data.(string)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnWrap(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColWrap(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColWrap(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == operation.ID {
|
||||
column.Wrap = operation.Data.(bool)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnHidden(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColHidden(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColHidden(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == operation.ID {
|
||||
column.Hidden = operation.Data.(bool)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO 下面的方法要重写
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
||||
|
|
@ -437,30 +512,6 @@ func (tx *Transaction) doSortAttrViewRow(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnHidden(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColHidden(operation.Data.(bool), operation.ID, operation.ParentID)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnWrap(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColWrap(operation.Data.(bool), operation.ID, operation.ParentID)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnWidth(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColWidth(operation.Data.(string), operation.ID, operation.ParentID)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeView(operation)
|
||||
if nil != err {
|
||||
|
|
@ -781,57 +832,6 @@ func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColHidden(hidden bool, columnID, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == columnID {
|
||||
column.Hidden = hidden
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColWrap(wrap bool, columnID, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == columnID {
|
||||
column.Wrap = wrap
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColWidth(width, columnID, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range attrView.Columns {
|
||||
if column.ID == columnID {
|
||||
column.Width = width
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeView(operation *Operation) (err error) {
|
||||
avID := operation.ID
|
||||
attrViewMap, err := av.ParseAttributeViewMap(avID)
|
||||
|
|
|
|||
|
|
@ -223,6 +223,12 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSetAttrViewFilters(op)
|
||||
case "setAttrViewSorts":
|
||||
ret = tx.doSetAttrViewSorts(op)
|
||||
case "setAttrViewColWidth":
|
||||
ret = tx.doSetAttrViewColumnWidth(op)
|
||||
case "setAttrViewColWrap":
|
||||
ret = tx.doSetAttrViewColumnWrap(op)
|
||||
case "setAttrViewColHidden":
|
||||
ret = tx.doSetAttrViewColumnHidden(op)
|
||||
// TODO 下面的方法要重写
|
||||
case "insertAttrViewBlock":
|
||||
ret = tx.doInsertAttrViewBlock(op)
|
||||
|
|
@ -240,12 +246,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doUpdateAttrViewCell(op)
|
||||
case "sortAttrViewRow":
|
||||
ret = tx.doSortAttrViewRow(op)
|
||||
case "setAttrViewColHidden":
|
||||
ret = tx.doSetAttrViewColumnHidden(op)
|
||||
case "setAttrViewColWrap":
|
||||
ret = tx.doSetAttrViewColumnWrap(op)
|
||||
case "setAttrViewColWidth":
|
||||
ret = tx.doSetAttrViewColumnWidth(op)
|
||||
case "setAttrView":
|
||||
ret = tx.doSetAttrView(op)
|
||||
case "updateAttrViewColOptions":
|
||||
|
|
@ -1053,13 +1053,12 @@ type Operation struct {
|
|||
|
||||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
ViewID string `json:"viewID"` // 属性视图的视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
PreviousRowID string `json:"previousRowID"` // 属性视图前一行 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
ViewID string `json:"viewID"` // 属性视图的视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
|
||||
discard bool // 用于标识是否在事务合并中丢弃
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue