From 077944bb43786db5e5dd0a79045b8d8f7428b36a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 14 Apr 2024 13:02:06 +0800 Subject: [PATCH] :art: Improve database template field to use relation/rollup field Fix https://github.com/siyuan-note/siyuan/issues/11029 --- kernel/model/attribute_view.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index d0731f417..17051cb59 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -905,11 +905,30 @@ func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues [] dataModel[rowValue.Key.Name] = time.UnixMilli(v.Date.Content) } } else if av.KeyTypeRollup == v.Type { - if 0 < len(v.Rollup.Contents) && av.KeyTypeNumber == v.Rollup.Contents[0].Type { - // 模板使用汇总时支持数字计算 - // Template supports numerical calculations when using rollup https://github.com/siyuan-note/siyuan/issues/10810 - // 汇总数字时仅取第一个数字填充模板 - dataModel[rowValue.Key.Name] = v.Rollup.Contents[0].Number.Content + if 0 < len(v.Rollup.Contents) { + var numbers []float64 + var contents []string + for _, content := range v.Rollup.Contents { + if av.KeyTypeNumber == content.Type { + numbers = append(numbers, content.Number.Content) + } else { + contents = append(contents, content.String(true)) + } + } + + if 0 < len(numbers) { + dataModel[rowValue.Key.Name] = numbers + } else { + dataModel[rowValue.Key.Name] = contents + } + } + } else if av.KeyTypeRelation == v.Type { + if 0 < len(v.Relation.Contents) { + var contents []string + for _, content := range v.Relation.Contents { + contents = append(contents, content.String(true)) + } + dataModel[rowValue.Key.Name] = contents } } else { dataModel[rowValue.Key.Name] = v.String(true)