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

Daniel8ade9ddb5f19
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 71431bca7f..56fa399c9e 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -192,13 +192,14 @@ 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 列表,用于维护分组中的所有项目
- 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"` // 是否为默认分组
+ 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"` // 分组是否隐藏空分组
+ GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
}
// GroupCalc 描述了分组计算规则和结果的结构。
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 1f7bf9a495..32582e0e3e 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -44,6 +44,75 @@ import (
"github.com/xrash/smetrics"
)
+func (tx *Transaction) doSetGroupHideEmpty(operation *Operation) (ret *TxErr) {
+ if err := SetGroupHideEmpty(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) {
+ attrView, err := av.ParseAttributeView(avID)
+ if err != nil {
+ return err
+ }
+
+ view, err := getAttrViewViewByBlockID(attrView, blockID)
+ if err != nil {
+ return err
+ }
+
+ if nil == view.Group {
+ return
+ }
+
+ view.GroupHideEmpty = hidden
+
+ err = av.SaveAttributeView(attrView)
+ if err != nil {
+ logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
+ return err
+ }
+ return nil
+}
+
+func (tx *Transaction) doHideAttrViewGroup(operation *Operation) (ret *TxErr) {
+ if err := HideAttributeViewGroup(operation.AvID, operation.BlockID, operation.ID, operation.Data.(bool)); nil != err {
+ return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
+ }
+ return
+}
+
+func HideAttributeViewGroup(avID, blockID, groupID string, hidden bool) (err error) {
+ attrView, err := av.ParseAttributeView(avID)
+ if err != nil {
+ return err
+ }
+
+ view, err := getAttrViewViewByBlockID(attrView, blockID)
+ if err != nil {
+ return err
+ }
+
+ if nil == view.Group {
+ return
+ }
+
+ for _, group := range view.Groups {
+ if group.ID == groupID {
+ group.GroupHidden = hidden
+ break
+ }
+ }
+
+ err = av.SaveAttributeView(attrView)
+ if err != nil {
+ logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
+ return err
+ }
+ return nil
+}
+
func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
data, err := gulu.JSON.MarshalJSON(operation.Data)
if nil != err {
@@ -62,7 +131,7 @@ func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
return
}
-func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) error {
+func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error) {
attrView, err := av.ParseAttributeView(avID)
if err != nil {
return err
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index ad9d3acf44..adaebd97d2 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -299,6 +299,10 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewCardAspectRatio(op)
case "setAttrViewGroup":
ret = tx.doSetAttrViewGroup(op)
+ case "hideAttrViewGroup":
+ ret = tx.doHideAttrViewGroup(op)
+ case "setGroupHideEmpty":
+ ret = tx.doSetGroupHideEmpty(op)
}
if nil != ret {