mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 01:21:14 +08:00
🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958
This commit is contained in:
parent
5c8bab48ed
commit
b296771340
@ -475,7 +475,7 @@ type ValueRollup struct {
|
||||
Contents []*Value `json:"contents"`
|
||||
}
|
||||
|
||||
func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) {
|
||||
if nil == calc {
|
||||
return
|
||||
}
|
||||
@ -535,7 +535,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
sum += v.Number.Content
|
||||
}
|
||||
}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(sum)}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(sum, destKey.NumberFormat)}}
|
||||
case CalcOperatorAverage:
|
||||
sum := 0.0
|
||||
count := 0
|
||||
@ -546,7 +546,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
}
|
||||
}
|
||||
if 0 < count {
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(sum / float64(count))}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(sum/float64(count), destKey.NumberFormat)}}
|
||||
}
|
||||
case CalcOperatorMedian:
|
||||
var numbers []float64
|
||||
@ -557,7 +557,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
}
|
||||
sort.Float64s(numbers)
|
||||
if 0 < len(numbers) {
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(numbers[len(numbers)/2])}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(numbers[len(numbers)/2], destKey.NumberFormat)}}
|
||||
}
|
||||
case CalcOperatorMin:
|
||||
min := math.MaxFloat64
|
||||
@ -568,7 +568,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(min)}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(min, destKey.NumberFormat)}}
|
||||
case CalcOperatorMax:
|
||||
max := -math.MaxFloat64
|
||||
for _, v := range r.Contents {
|
||||
@ -578,7 +578,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(max)}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(max, destKey.NumberFormat)}}
|
||||
case CalcOperatorRange:
|
||||
min := math.MaxFloat64
|
||||
max := -math.MaxFloat64
|
||||
@ -592,7 +592,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(max - min)}}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(max-min, destKey.NumberFormat)}}
|
||||
case CalcOperatorChecked:
|
||||
countChecked := 0
|
||||
for _, v := range r.Contents {
|
||||
|
@ -243,13 +243,9 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||
relVal := attrView.GetValue(kv.Key.Rollup.RelationKeyID, kv.Values[0].BlockID)
|
||||
if nil != relVal && nil != relVal.Relation {
|
||||
destAv, _ := av.ParseAttributeView(relKey.Relation.AvID)
|
||||
if nil != destAv {
|
||||
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
|
||||
if nil != destAv && nil != destKey {
|
||||
for _, bID := range relVal.Relation.BlockIDs {
|
||||
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
|
||||
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
|
||||
if nil == destVal {
|
||||
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, blockID, destKey.Type)
|
||||
@ -261,8 +257,8 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||
}
|
||||
|
||||
kv.Values[0].Rollup.Contents = append(kv.Values[0].Rollup.Contents, destVal.Clone())
|
||||
kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc)
|
||||
}
|
||||
kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc, destKey)
|
||||
}
|
||||
}
|
||||
case av.KeyTypeRelation:
|
||||
@ -817,12 +813,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||
break
|
||||
}
|
||||
|
||||
for _, blockID := range relVal.Relation.BlockIDs {
|
||||
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, blockID := range relVal.Relation.BlockIDs {
|
||||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||
if nil == destVal {
|
||||
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
@ -835,7 +831,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||
cell.Value.Rollup.Contents = append(cell.Value.Rollup.Contents, destVal.Clone())
|
||||
}
|
||||
|
||||
cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc)
|
||||
cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey)
|
||||
case av.KeyTypeRelation: // 渲染关联列
|
||||
relKey, _ := attrView.GetKey(cell.Value.KeyID)
|
||||
if nil != relKey && nil != relKey.Relation {
|
||||
|
@ -774,18 +774,14 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||
break
|
||||
}
|
||||
|
||||
for _, blockID := range relVal.Relation.BlockIDs {
|
||||
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, blockID := range relVal.Relation.BlockIDs {
|
||||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||
if nil == destVal {
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
|
||||
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
}
|
||||
if av.KeyTypeNumber == destKey.Type {
|
||||
@ -796,7 +792,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||
cell.Value.Rollup.Contents = append(cell.Value.Rollup.Contents, destVal.Clone())
|
||||
}
|
||||
|
||||
cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc)
|
||||
cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey)
|
||||
case av.KeyTypeRelation: // 渲染关联列
|
||||
relKey, _ := attrView.GetKey(cell.Value.KeyID)
|
||||
if nil != relKey && nil != relKey.Relation {
|
||||
|
Loading…
Reference in New Issue
Block a user