Skip to content

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

:recycle: Refactor av data structure

Danielc605c496ee8a
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 18e5ba9dc8..c31114270f 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -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)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 26a41c366c..9800db0a66 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -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 // 用于标识是否在事务合并中丢弃
}