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

Daniel684286fc8afa
diff --git a/kernel/av/av.go b/kernel/av/av.go
index b036728757..f8e8db5989 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -191,15 +191,14 @@ type View struct {
Gallery *LayoutGallery `json:"gallery,omitempty"` // 卡片布局
ItemIDs []string `json:"itemIds,omitempty"` // 项目 ID 列表,用于维护所有项目
- Group *ViewGroup `json:"group,omitempty"` // 分组规则
- GroupUpdated int64 `json:"groupUpdated"` // 分组规则更新时间戳
- 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"` // 分组是否隐藏
- GroupHideEmpty bool `json:"groupHideEmpty,omitempty"` // 分组是否隐藏空分组
+ Group *ViewGroup `json:"group,omitempty"` // 分组规则
+ GroupUpdated int64 `json:"groupUpdated"` // 分组规则更新时间戳
+ 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"` // 分组是否隐藏
}
// GroupCalc 描述了分组计算规则和结果的结构。
diff --git a/kernel/av/group.go b/kernel/av/group.go
index 37685b8bb5..a5f91fbf71 100644
--- a/kernel/av/group.go
+++ b/kernel/av/group.go
@@ -18,10 +18,11 @@ package av
// ViewGroup 描述了视图分组规则的结构。
type ViewGroup struct {
- Field string `json:"field"` // 分组字段 ID
- Method GroupMethod `json:"method"` // 分组方式
- Range *GroupRange `json:"range,omitempty"` // 分组范围
- Order GroupOrder `json:"order"` // 分组排序规则
+ Field string `json:"field"` // 分组字段 ID
+ Method GroupMethod `json:"method"` // 分组方式
+ Range *GroupRange `json:"range,omitempty"` // 分组范围
+ Order GroupOrder `json:"order"` // 分组排序规则
+ HideEmpty bool `json:"hideEmpty,omitempty"` // 是否隐藏空分组
}
// GroupMethod 描述了分组方式。
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 9ee356c38c..64015b3e99 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -93,14 +93,14 @@ func syncAttrViewTableColWidth(operation *Operation) (err error) {
return
}
-func (tx *Transaction) doSetGroupHideEmpty(operation *Operation) (ret *TxErr) {
- if err := SetGroupHideEmpty(operation.AvID, operation.BlockID, operation.Data.(bool)); nil != err {
+func (tx *Transaction) doSetAttrViewHideEmptyGroup(operation *Operation) (ret *TxErr) {
+ if err := setAttrViewHideEmptyGroup(operation.AvID, operation.BlockID, operation.Data.(bool)); nil != err {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
-func SetGroupHideEmpty(avID, blockID string, hidden bool) (err error) {
+func setAttrViewHideEmptyGroup(avID, blockID string, hidden bool) (err error) {
attrView, err := av.ParseAttributeView(avID)
if err != nil {
return err
@@ -115,7 +115,14 @@ func SetGroupHideEmpty(avID, blockID string, hidden bool) (err error) {
return
}
- view.GroupHideEmpty = hidden
+ view.Group.HideEmpty = hidden
+ for _, group := range view.Groups {
+ if hidden {
+ group.GroupHidden = true
+ } else {
+ group.GroupHidden = false
+ }
+ }
err = av.SaveAttributeView(attrView)
if err != nil {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index b49f6b78ef..8bf6182b9e 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -301,8 +301,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewGroup(op)
case "hideAttrViewGroup":
ret = tx.doHideAttrViewGroup(op)
- case "setGroupHideEmpty":
- ret = tx.doSetGroupHideEmpty(op)
+ case "setAttrViewHideEmptyGroup":
+ ret = tx.doSetAttrViewHideEmptyGroup(op)
case "syncAttrViewTableColWidth":
ret = tx.doSyncAttrViewTableColWidth(op)
}