🎨 Update av

This commit is contained in:
Daniel 2023-07-01 10:54:14 +08:00
parent 53ded6b7e7
commit ef362685cb
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 45 additions and 0 deletions

View file

@ -221,6 +221,14 @@ func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr)
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 addAttributeViewColumn(name string, typ string, avID string) (err error) {
attrView, err := av.ParseAttributeView(avID)
if nil != err {
@ -297,6 +305,41 @@ func removeAttributeViewColumn(columnID string, avID string) (err error) {
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 column.ID == previousColumnID {
previousIndex = i
}
}
if nil == col {
return
}
attrView.Columns = append(attrView.Columns[:index], attrView.Columns[index+1:]...)
attrView.Columns = append(attrView.Columns[:previousIndex], append([]*av.Column{col}, attrView.Columns[previousIndex:]...)...)
for _, row := range attrView.Rows {
cel := row.Cells[index]
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
row.Cells = append(row.Cells[:previousIndex], append([]*av.Cell{cel}, row.Cells[previousIndex:]...)...)
}
err = av.SaveAttributeView(attrView)
return
}
func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (ret *av.AttributeView, err error) {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {

View file

@ -226,6 +226,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doUpdateAttrViewColumn(op)
case "removeAttrViewCol":
ret = tx.doRemoveAttrViewColumn(op)
case "sortAttrViewCol":
ret = tx.doSortAttrViewColumn(op)
case "updateAttrViewCell":
ret = tx.doUpdateAttrViewCell(op)
}