mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
🎨 Attribute View columns calculate https://github.com/siyuan-note/siyuan/issues/8699
This commit is contained in:
parent
eb69659faa
commit
3a7e0cd014
2 changed files with 46 additions and 0 deletions
|
|
@ -258,6 +258,50 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColCalc(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColumnCalc(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
operationData := operation.Data.([]interface{})
|
||||
data, err := gulu.JSON.MarshalJSON(operationData)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
calc := &av.ColumnCalc{}
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
if err = gulu.JSON.UnmarshalJSON(data, calc); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, column := range view.Table.Columns {
|
||||
if column.ID == operation.ID {
|
||||
column.Calc = calc
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
firstSrcID := operation.SrcIDs[0]
|
||||
tree, err := tx.loadTree(firstSrcID)
|
||||
|
|
|
|||
|
|
@ -251,6 +251,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doRemoveAttrViewColOption(op)
|
||||
case "updateAttrViewColOption":
|
||||
ret = tx.doUpdateAttrViewColOption(op)
|
||||
case "setAttrViewColCalc":
|
||||
ret = tx.doSetAttrViewColCalc(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue