🎨 Add select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8694

This commit is contained in:
Daniel 2023-07-09 17:27:42 +08:00
parent b85d6e97cf
commit 2a8de9733e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 36 additions and 0 deletions

View file

@ -167,6 +167,14 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
return return
} }
func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *TxErr) {
err := updateAttributeViewColumnOptions(operation.Data, operation.ID, operation.ParentID)
if nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
}
return
}
func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) { func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) {
err := addAttributeViewColumn(operation.Name, operation.Typ, operation.ParentID) err := addAttributeViewColumn(operation.Name, operation.Typ, operation.ParentID)
if nil != err { if nil != err {
@ -291,6 +299,32 @@ func updateAttributeViewColumn(id, name string, typ string, avID string) (err er
return 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
}
func removeAttributeViewColumn(columnID string, avID string) (err error) { func removeAttributeViewColumn(columnID string, avID string) (err error) {
attrView, err := av.ParseAttributeView(avID) attrView, err := av.ParseAttributeView(avID)
if nil != err { if nil != err {

View file

@ -241,6 +241,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewColumnWidth(op) ret = tx.doSetAttrViewColumnWidth(op)
case "setAttrView": case "setAttrView":
ret = tx.doSetAttrView(op) ret = tx.doSetAttrView(op)
case "updateAttrViewColOptions":
ret = tx.doUpdateAttrViewColOptions(op)
} }
if nil != ret { if nil != ret {