Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Update av

Danielef362685cb43
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index ccb773bb30..7373b01eb2 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -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 {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index d88b0c20e5..ab78b8331e 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -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)
}