An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Refactor av data structure
Daniel74d10b7e9702
diff --git a/kernel/av/table.go b/kernel/av/table.goindex e3856ffdcd..4622ec5e42 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -17,7 +17,6 @@package avimport (- "github.com/88250/lute/ast""math""sort""strings"@@ -259,13 +258,6 @@ type TableRow struct {Cells []*TableCell `json:"cells"`}-func NewTableRow() *TableRow {- return &TableRow{- ID: ast.NewNodeID(),- Cells: []*TableCell{},- }-}-func (table *Table) GetType() LayoutType {return LayoutTypeTable}diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex af2507c1b3..f9635b5ec7 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -101,7 +101,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a}}- for _, row := range rows {+ for rowID, row := range rows {var tableRow av.TableRowfor _, col := range ret.Columns {var tableCell *av.TableCell@@ -121,6 +121,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *aValueType: col.Type,}}+ tableRow.ID = rowIDtableRow.Cells = append(tableRow.Cells, tableCell)}ret.Rows = append(ret.Rows, &tableRow)@@ -715,31 +716,100 @@ func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error)return}-// TODO 下面的方法要重写+func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {+ err := updateAttributeViewColumnOptions(operation)+ if nil != err {+ return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}+ }+ return+}-//func (tx *Transaction) doUpdateAttrViewColOption(operation *Operation) (ret *TxErr) {-// err := updateAttributeViewColumnOption(operation)+func updateAttributeViewColumnOptions(operation *Operation) (err error) {+ attrView, err := av.ParseAttributeView(operation.AvID)+ if nil != err {+ return+ }++ jsonData, err := gulu.JSON.MarshalJSON(operation.Data)+ if nil != err {+ return+ }++ options := []*av.KeySelectOption{}+ if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {+ return+ }++ for _, keyValues := range attrView.KeyValues {+ if keyValues.Key.ID == operation.ID {+ keyValues.Key.Options = options+ err = av.SaveAttributeView(attrView)+ return+ }+ }+ return+}++//func (tx *Transaction) doRemoveAttrViewColOption(operation *Operation) (ret *TxErr) {+// err := removeAttributeViewColumnOption(operation)// if nil != err {// return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}// }// return//}//-//func (tx *Transaction) doRemoveAttrViewColOption(operation *Operation) (ret *TxErr) {-// err := removeAttributeViewColumnOption(operation)+//func removeAttributeViewColumnOption(operation *Operation) (err error) {+// avID := operation.ParentID+// attrView, err := av.ParseAttributeView(avID)// if nil != err {-// return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}+// return// }+//+// optName := operation.Data.(string)+//+// key := attrView.GetKey(operation.ID)+// key.+//+// for _, row := range attrView.Rows {+// for i, cell := range row.Cells {+// if colIndex != i {+// continue+// }+//+// if nil != cell.Value {+// if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {+// if optName == cell.Value.MSelect[0].Content {+// cell.Value = nil+// break+// }+// } else if nil != cell.Value.MSelect {+// for j, opt := range cell.Value.MSelect {+// if optName == opt.Content {+// cell.Value.MSelect = append(cell.Value.MSelect[:j], cell.Value.MSelect[j+1:]...)+// break+// }+// }+// }+// }+// break+// }+// }+//+// err = av.SaveAttributeView(attrView)// return//}-//-//func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {-// err := updateAttributeViewColumnOptions(operation.Data, operation.ID, operation.ParentID)++// TODO 下面的方法要重写++//func (tx *Transaction) doUpdateAttrViewColOption(operation *Operation) (ret *TxErr) {+// err := updateAttributeViewColumnOption(operation)// if nil != err {// return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}// }// return//}+//+////func updateAttributeViewColumnOption(operation *Operation) (err error) {// avID := operation.ParentID@@ -823,89 +893,6 @@ func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error)// return//}//-//func removeAttributeViewColumnOption(operation *Operation) (err error) {-// avID := operation.ParentID-// attrView, err := av.ParseAttributeView(avID)-// if nil != err {-// return-// }-//-// colID := operation.ID-// optName := operation.Data.(string)-//-// var colIndex int-// for i, col := range attrView.Columns {-// if col.ID != colID {-// continue-// }-//-// colIndex = i-//-// for j, opt := range col.Options {-// if opt.Name != optName {-// continue-// }-//-// col.Options = append(col.Options[:j], col.Options[j+1:]...)-// break-// }-// break-// }-//-// for _, row := range attrView.Rows {-// for i, cell := range row.Cells {-// if colIndex != i {-// continue-// }-//-// if nil != cell.Value {-// if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {-// if optName == cell.Value.MSelect[0].Content {-// cell.Value = nil-// break-// }-// } else if nil != cell.Value.MSelect {-// for j, opt := range cell.Value.MSelect {-// if optName == opt.Content {-// cell.Value.MSelect = append(cell.Value.MSelect[:j], cell.Value.MSelect[j+1:]...)-// break-// }-// }-// }-// }-// break-// }-// }-//-// err = av.SaveAttributeView(attrView)-// return-//}-//-//func updateAttributeViewColumnOptions(data interface{}, id, avID string) (err error) {-// attrView, err := av.ParseAttributeView(avID)-// if nil != err {-// return-// }-//-// jsonData, err := gulu.JSON.MarshalJSON(data)-// if nil != err {-// return-// }-//-// options := []*av.ColumnSelectOption{}-// if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {-// return-// }-//-// for _, col := range attrView.Columns {-// if col.ID == id {-// col.Options = options-// err = av.SaveAttributeView(attrView)-// return-// }-// }-// return-//}const (NodeAttrNameAVs = "custom-avs"diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex 50be537871..d61c60825f 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -245,11 +245,10 @@ func performTx(tx *Transaction) (ret *TxErr) {ret = tx.doSortAttrViewColumn(op)case "updateAttrViewCell":ret = tx.doUpdateAttrViewCell(op)- // TODO 下面的方法要重写- //case "updateAttrViewColOptions":- // ret = tx.doUpdateAttrViewColOptions(op)- //case "removeAttrViewColOption":- // ret = tx.doRemoveAttrViewColOption(op)+ case "updateAttrViewColOptions":+ ret = tx.doUpdateAttrViewColOptions(op)+ //case "removeAttrViewColOption":+ //ret = tx.doRemoveAttrViewColOption(op)//case "updateAttrViewColOption":// ret = tx.doUpdateAttrViewColOption(op)}