Skip to content

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

:art: Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695

Daniel8c999c5957aa
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index e4d1272d00..c3f42ca900 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -167,6 +167,14 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
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) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {
err := updateAttributeViewColumnOptions(operation.Data, operation.ID, operation.ParentID)
if nil != err {
@@ -299,6 +307,64 @@ func updateAttributeViewColumn(id, name string, typ string, avID string) (err er
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 _, opt := range col.Options {
+ if opt.Name != optName {
+ continue
+ }
+
+ col.Options = append(col.Options[:i], col.Options[i+1:]...)
+ break
+ }
+ break
+ }
+
+ for _, row := range attrView.Rows {
+ for k, cell := range row.Cells {
+ if colIndex != k {
+ continue
+ }
+
+ if nil != cell.Value {
+ if nil != cell.Value.Select {
+ if optName == cell.Value.Select.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 {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index eecb31d1dd..956f525657 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -243,6 +243,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrView(op)
case "updateAttrViewColOptions":
ret = tx.doUpdateAttrViewColOptions(op)
+ case "removeAttrViewColOption":
+ ret = tx.doRemoveAttrViewColOption(op)
}
if nil != ret {