mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
c605c496ee
commit
3481e93463
2 changed files with 92 additions and 91 deletions
|
|
@ -381,6 +381,92 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doSortAttrViewRow(operation *Operation) (ret *TxErr) {
|
||||||
|
err := sortAttributeViewRow(operation)
|
||||||
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
|
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var row *av.Row
|
||||||
|
var index, previousIndex int
|
||||||
|
for i, r := range attrView.Rows {
|
||||||
|
if r.ID == operation.ID {
|
||||||
|
row = r
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nil == row {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
attrView.Rows = append(attrView.Rows[:index], attrView.Rows[index+1:]...)
|
||||||
|
for i, r := range attrView.Rows {
|
||||||
|
if r.ID == operation.PreviousID {
|
||||||
|
previousIndex = i + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrView.Rows = util.InsertElem(attrView.Rows, previousIndex, row)
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doSortAttrViewColumn(operation *Operation) (ret *TxErr) {
|
||||||
|
err := sortAttributeViewColumn(operation)
|
||||||
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortAttributeViewColumn(operation *Operation) (err error) {
|
||||||
|
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var col *av.Column
|
||||||
|
var index, previousIndex int
|
||||||
|
for i, column := range attrView.Columns {
|
||||||
|
if column.ID == operation.ID {
|
||||||
|
col = column
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nil == col {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
attrView.Columns = append(attrView.Columns[:index], attrView.Columns[index+1:]...)
|
||||||
|
for i, column := range attrView.Columns {
|
||||||
|
if column.ID == operation.PreviousID {
|
||||||
|
previousIndex = i + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrView.Columns = util.InsertElem(attrView.Columns, previousIndex, col)
|
||||||
|
|
||||||
|
for _, row := range attrView.Rows {
|
||||||
|
cel := row.Cells[index]
|
||||||
|
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
|
||||||
|
row.Cells = util.InsertElem(row.Cells, previousIndex, cel)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TODO 下面的方法要重写
|
// TODO 下面的方法要重写
|
||||||
|
|
||||||
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
||||||
|
|
@ -496,22 +582,6 @@ func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doSortAttrViewColumn(operation *Operation) (ret *TxErr) {
|
|
||||||
err := sortAttributeViewColumn(operation.ID, operation.PreviousID, operation.ParentID)
|
|
||||||
if nil != err {
|
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Transaction) doSortAttrViewRow(operation *Operation) (ret *TxErr) {
|
|
||||||
err := sortAttributeViewRow(operation.ID, operation.PreviousID, operation.ParentID)
|
|
||||||
if nil != err {
|
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
|
||||||
err := setAttributeView(operation)
|
err := setAttributeView(operation)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -762,76 +832,6 @@ func removeAttributeViewColumn(columnID string, avID string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortAttributeViewColumn(columnID, previousColumnID, avID string) (err error) {
|
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var col *av.Column
|
|
||||||
var index, previousIndex int
|
|
||||||
for i, column := range attrView.Columns {
|
|
||||||
if column.ID == columnID {
|
|
||||||
col = column
|
|
||||||
index = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if nil == col {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
attrView.Columns = append(attrView.Columns[:index], attrView.Columns[index+1:]...)
|
|
||||||
for i, column := range attrView.Columns {
|
|
||||||
if column.ID == previousColumnID {
|
|
||||||
previousIndex = i + 1
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attrView.Columns = util.InsertElem(attrView.Columns, previousIndex, col)
|
|
||||||
|
|
||||||
for _, row := range attrView.Rows {
|
|
||||||
cel := row.Cells[index]
|
|
||||||
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
|
|
||||||
row.Cells = util.InsertElem(row.Cells, previousIndex, cel)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
|
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var row *av.Row
|
|
||||||
var index, previousIndex int
|
|
||||||
for i, r := range attrView.Rows {
|
|
||||||
if r.ID == rowID {
|
|
||||||
row = r
|
|
||||||
index = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if nil == row {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
attrView.Rows = append(attrView.Rows[:index], attrView.Rows[index+1:]...)
|
|
||||||
for i, r := range attrView.Rows {
|
|
||||||
if r.ID == previousRowID {
|
|
||||||
previousIndex = i + 1
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attrView.Rows = util.InsertElem(attrView.Rows, previousIndex, row)
|
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func setAttributeView(operation *Operation) (err error) {
|
func setAttributeView(operation *Operation) (err error) {
|
||||||
avID := operation.ID
|
avID := operation.ID
|
||||||
attrViewMap, err := av.ParseAttributeViewMap(avID)
|
attrViewMap, err := av.ParseAttributeViewMap(avID)
|
||||||
|
|
|
||||||
|
|
@ -229,23 +229,24 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doSetAttrViewColumnWrap(op)
|
ret = tx.doSetAttrViewColumnWrap(op)
|
||||||
case "setAttrViewColHidden":
|
case "setAttrViewColHidden":
|
||||||
ret = tx.doSetAttrViewColumnHidden(op)
|
ret = tx.doSetAttrViewColumnHidden(op)
|
||||||
// TODO 下面的方法要重写
|
case "sortAttrViewRow":
|
||||||
|
ret = tx.doSortAttrViewRow(op)
|
||||||
|
case "sortAttrViewCol":
|
||||||
|
ret = tx.doSortAttrViewColumn(op)
|
||||||
case "insertAttrViewBlock":
|
case "insertAttrViewBlock":
|
||||||
ret = tx.doInsertAttrViewBlock(op)
|
ret = tx.doInsertAttrViewBlock(op)
|
||||||
case "removeAttrViewBlock":
|
case "removeAttrViewBlock":
|
||||||
ret = tx.doRemoveAttrViewBlock(op)
|
ret = tx.doRemoveAttrViewBlock(op)
|
||||||
|
// TODO 下面的方法要重写
|
||||||
|
|
||||||
case "addAttrViewCol":
|
case "addAttrViewCol":
|
||||||
ret = tx.doAddAttrViewColumn(op)
|
ret = tx.doAddAttrViewColumn(op)
|
||||||
case "updateAttrViewCol":
|
case "updateAttrViewCol":
|
||||||
ret = tx.doUpdateAttrViewColumn(op)
|
ret = tx.doUpdateAttrViewColumn(op)
|
||||||
case "removeAttrViewCol":
|
case "removeAttrViewCol":
|
||||||
ret = tx.doRemoveAttrViewColumn(op)
|
ret = tx.doRemoveAttrViewColumn(op)
|
||||||
case "sortAttrViewCol":
|
|
||||||
ret = tx.doSortAttrViewColumn(op)
|
|
||||||
case "updateAttrViewCell":
|
case "updateAttrViewCell":
|
||||||
ret = tx.doUpdateAttrViewCell(op)
|
ret = tx.doUpdateAttrViewCell(op)
|
||||||
case "sortAttrViewRow":
|
|
||||||
ret = tx.doSortAttrViewRow(op)
|
|
||||||
case "setAttrView":
|
case "setAttrView":
|
||||||
ret = tx.doSetAttrView(op)
|
ret = tx.doSetAttrView(op)
|
||||||
case "updateAttrViewColOptions":
|
case "updateAttrViewColOptions":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue