mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Add Relation and Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9888
This commit is contained in:
parent
46c82acf6c
commit
de73ca8c3b
3 changed files with 32 additions and 8 deletions
|
|
@ -80,7 +80,7 @@ type Key struct {
|
||||||
// 以下是某些列类型的特有属性
|
// 以下是某些列类型的特有属性
|
||||||
|
|
||||||
// 单选/多选列
|
// 单选/多选列
|
||||||
Options []*KeySelectOption `json:"options,omitempty"` // 选项列表
|
Options []*SelectOption `json:"options,omitempty"` // 选项列表
|
||||||
|
|
||||||
// 数字列
|
// 数字列
|
||||||
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
||||||
|
|
@ -114,7 +114,7 @@ type Relation struct {
|
||||||
BackKeyID string `json:"backKeyID"` // 双向关联时回链关联列的 ID
|
BackKeyID string `json:"backKeyID"` // 双向关联时回链关联列的 ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeySelectOption struct {
|
type SelectOption struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -651,11 +651,11 @@ type TableColumn struct {
|
||||||
|
|
||||||
// 以下是某些列类型的特有属性
|
// 以下是某些列类型的特有属性
|
||||||
|
|
||||||
Options []*KeySelectOption `json:"options,omitempty"` // 选项列表
|
Options []*SelectOption `json:"options,omitempty"` // 选项列表
|
||||||
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
||||||
Template string `json:"template"` // 模板内容
|
Template string `json:"template"` // 模板内容
|
||||||
Relation *Relation `json:"relation,omitempty"` // 关联列
|
Relation *Relation `json:"relation,omitempty"` // 关联列
|
||||||
Rollup *Rollup `json:"rollup,omitempty"` // 汇总列
|
Rollup *Rollup `json:"rollup,omitempty"` // 汇总列
|
||||||
}
|
}
|
||||||
|
|
||||||
type TableCell struct {
|
type TableCell struct {
|
||||||
|
|
|
||||||
|
|
@ -751,6 +751,30 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||||
|
|
||||||
for _, keyValues := range srcAv.KeyValues {
|
for _, keyValues := range srcAv.KeyValues {
|
||||||
if keyValues.Key.ID == operation.KeyID {
|
if keyValues.Key.ID == operation.KeyID {
|
||||||
|
// 已经设置过双向关联的话需要先断开双向关联
|
||||||
|
if nil != keyValues.Key.Relation && keyValues.Key.Relation.IsTwoWay {
|
||||||
|
oldDestAv, parseErr := av.ParseAttributeView(keyValues.Key.Relation.AvID)
|
||||||
|
if nil == parseErr {
|
||||||
|
isOldSameAv := oldDestAv.ID == destAv.ID
|
||||||
|
if isOldSameAv {
|
||||||
|
oldDestAv = destAv
|
||||||
|
}
|
||||||
|
|
||||||
|
oldDestKey, _ := oldDestAv.GetKey(keyValues.Key.Relation.BackKeyID)
|
||||||
|
if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
|
||||||
|
oldDestKey.Relation.IsTwoWay = false
|
||||||
|
oldDestKey.Relation.BackKeyID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isOldSameAv {
|
||||||
|
err = av.SaveAttributeView(oldDestAv)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
keyValues.Key.Relation = &av.Relation{
|
keyValues.Key.Relation = &av.Relation{
|
||||||
AvID: operation.ID,
|
AvID: operation.ID,
|
||||||
IsTwoWay: operation.IsTwoWay,
|
IsTwoWay: operation.IsTwoWay,
|
||||||
|
|
@ -2086,7 +2110,7 @@ func updateAttributeViewColumnOptions(operation *Operation) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []*av.KeySelectOption{}
|
options := []*av.SelectOption{}
|
||||||
if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {
|
if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue