mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Add Relation and Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9888
This commit is contained in:
parent
a41eac8659
commit
87096f9671
3 changed files with 50 additions and 9 deletions
|
@ -90,7 +90,6 @@ type Key struct {
|
|||
|
||||
// 关联列
|
||||
RelationAvID string `json:"relationAvID"` // 关联的属性视图 ID
|
||||
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
||||
IsBiRelation bool `json:"isBiRelation"` // 是否双向关联
|
||||
BackRelationKeyID string `json:"backRelationKeyID"` // 双向关联时回链关联列的 ID
|
||||
|
||||
|
|
|
@ -655,6 +655,44 @@ func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColRelation(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColRelation(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||
err = updateAttributeViewColRelation0(operation.AvID, operation.KeyID, operation.ID, operation.IsBiRelation, operation.BackRelationKeyID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if operation.IsBiRelation {
|
||||
err = updateAttributeViewColRelation0(operation.ID, operation.BackRelationKeyID, operation.AvID, operation.IsBiRelation, operation.KeyID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColRelation0(avID, relKeyID, destAvID string, isBiRel bool, backRelKeyID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
if keyValues.Key.ID == relKeyID {
|
||||
keyValues.Key.RelationAvID = destAvID
|
||||
keyValues.Key.IsBiRelation = isBiRel
|
||||
keyValues.Key.BackRelationKeyID = backRelKeyID
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSortAttrViewView(operation *Operation) (ret *TxErr) {
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
|
|
|
@ -258,6 +258,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doDuplicateAttrViewView(op)
|
||||
case "sortAttrViewView":
|
||||
ret = tx.doSortAttrViewView(op)
|
||||
case "updateAttrViewColRelation":
|
||||
ret = tx.doUpdateAttrViewColRelation(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
@ -1181,14 +1183,16 @@ type Operation struct {
|
|||
|
||||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
Format string `json:"format"` // 属性视图列格式化
|
||||
KeyID string `json:"keyID"` // 属性视列 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
Format string `json:"format"` // 属性视图列格式化
|
||||
KeyID string `json:"keyID"` // 属性视列 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID
|
||||
IsBiRelation bool `json:"isBiRelation"` // 属性视图关联列是否是双向关系
|
||||
BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
|
||||
}
|
||||
|
||||
type Transaction struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue