Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964

Daniel99db625cf7c0
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 50d9926880..bf6bfe1731 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -192,13 +192,19 @@ type View struct {
Gallery *LayoutGallery `json:"gallery,omitempty"` // 卡片布局
ItemIDs []string `json:"itemIds,omitempty"` // 项目 ID 列表,用于维护所有项目
- Groups []*View `json:"groups,omitempty"` // 分组视图列表
- GroupItemIDs []string `json:"groupItemIds,omitempty"` // 分组项目 ID 列表,用于维护分组中的所有项目
- GroupCalcSum bool `json:"groupCalcSum,omitempty"` // 分组是否计算总和
- GroupName string `json:"groupName,omitempty"` // 分组名称
- GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
- GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
- GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
+ Groups []*View `json:"groups,omitempty"` // 分组视图列表
+ GroupItemIDs []string `json:"groupItemIds,omitempty"` // 分组项目 ID 列表,用于维护分组中的所有项目
+ GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则
+ GroupName string `json:"groupName,omitempty"` // 分组名称
+ GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
+ GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
+ GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
+}
+
+// GroupCalc 描述了分组计算规则和结果的结构。
+type GroupCalc struct {
+ Field string `json:"field"` // 字段 ID
+ FieldCalc `json:"calc"` // 计算规则和结果
}
// LayoutType 描述了视图布局类型。
diff --git a/kernel/av/calc.go b/kernel/av/calc.go
index c20989e0a2..012e9a0e78 100644
--- a/kernel/av/calc.go
+++ b/kernel/av/calc.go
@@ -16,8 +16,8 @@
package av
-// ColumnCalc 描述了列(字段)计算操作和结果的结构。
-type ColumnCalc struct {
+// FieldCalc 描述了字段计算操作和结果的结构。
+type FieldCalc struct {
Operator CalcOperator `json:"operator"` // 计算操作符
Result *Value `json:"result"` // 计算结果
}
diff --git a/kernel/av/layout.go b/kernel/av/layout.go
index 717482539c..8ea45a24c0 100644
--- a/kernel/av/layout.go
+++ b/kernel/av/layout.go
@@ -67,7 +67,8 @@ type BaseInstance struct {
Folded bool `json:"folded,omitempty"` // 是否折叠
Hidden bool `json:"hidden,omitempty"` // 是否隐藏
- Groups []Viewable `json:"groups,omitempty"` // 分组实例列表
+ Groups []Viewable `json:"groups,omitempty"` // 分组实例列表
+ GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则和结果
}
func (baseInstance *BaseInstance) GetSorts() []*ViewSort {
diff --git a/kernel/av/layout_table.go b/kernel/av/layout_table.go
index 4be212cad4..f1b26d67bb 100644
--- a/kernel/av/layout_table.go
+++ b/kernel/av/layout_table.go
@@ -45,9 +45,9 @@ func NewLayoutTable() *LayoutTable {
type ViewTableColumn struct {
*BaseField
- Pin bool `json:"pin"` // 是否固定
- Width string `json:"width"` // 列宽度
- Calc *ColumnCalc `json:"calc,omitempty"` // 计算
+ Pin bool `json:"pin"` // 是否固定
+ Width string `json:"width"` // 列宽度
+ Calc *FieldCalc `json:"calc,omitempty"` // 计算规则
}
// Table 描述了表格视图实例的结构。
@@ -63,9 +63,9 @@ type Table struct {
type TableColumn struct {
*BaseInstanceField
- Pin bool `json:"pin"` // 是否固定
- Width string `json:"width"` // 列宽度
- Calc *ColumnCalc `json:"calc"` // 计算
+ Pin bool `json:"pin"` // 是否固定
+ Width string `json:"width"` // 列宽度
+ Calc *FieldCalc `json:"calc"` // 计算规则和结果
}
// TableRow 描述了表格实例行的结构。
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 99710488da..95f27f7fb3 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -2346,7 +2346,7 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
return
}
- calc := &av.ColumnCalc{}
+ calc := &av.FieldCalc{}
switch view.LayoutType {
case av.LayoutTypeTable:
if err = gulu.JSON.UnmarshalJSON(data, calc); err != nil {