mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🎨 Update av
This commit is contained in:
parent
53ded6b7e7
commit
ef362685cb
2 changed files with 45 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue