mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
54f2d8599e
commit
684286fc8a
4 changed files with 26 additions and 19 deletions
|
|
@ -191,15 +191,14 @@ type View struct {
|
||||||
Gallery *LayoutGallery `json:"gallery,omitempty"` // 卡片布局
|
Gallery *LayoutGallery `json:"gallery,omitempty"` // 卡片布局
|
||||||
ItemIDs []string `json:"itemIds,omitempty"` // 项目 ID 列表,用于维护所有项目
|
ItemIDs []string `json:"itemIds,omitempty"` // 项目 ID 列表,用于维护所有项目
|
||||||
|
|
||||||
Group *ViewGroup `json:"group,omitempty"` // 分组规则
|
Group *ViewGroup `json:"group,omitempty"` // 分组规则
|
||||||
GroupUpdated int64 `json:"groupUpdated"` // 分组规则更新时间戳
|
GroupUpdated int64 `json:"groupUpdated"` // 分组规则更新时间戳
|
||||||
Groups []*View `json:"groups,omitempty"` // 分组视图列表
|
Groups []*View `json:"groups,omitempty"` // 分组视图列表
|
||||||
GroupItemIDs []string `json:"groupItemIds,omitempty"` // 分组项目 ID 列表,用于维护分组中的所有项目
|
GroupItemIDs []string `json:"groupItemIds,omitempty"` // 分组项目 ID 列表,用于维护分组中的所有项目
|
||||||
GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则
|
GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则
|
||||||
GroupName string `json:"groupName,omitempty"` // 分组名称
|
GroupName string `json:"groupName,omitempty"` // 分组名称
|
||||||
GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
|
GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
|
||||||
GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
|
GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
|
||||||
GroupHideEmpty bool `json:"groupHideEmpty,omitempty"` // 分组是否隐藏空分组
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupCalc 描述了分组计算规则和结果的结构。
|
// GroupCalc 描述了分组计算规则和结果的结构。
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@ package av
|
||||||
|
|
||||||
// ViewGroup 描述了视图分组规则的结构。
|
// ViewGroup 描述了视图分组规则的结构。
|
||||||
type ViewGroup struct {
|
type ViewGroup struct {
|
||||||
Field string `json:"field"` // 分组字段 ID
|
Field string `json:"field"` // 分组字段 ID
|
||||||
Method GroupMethod `json:"method"` // 分组方式
|
Method GroupMethod `json:"method"` // 分组方式
|
||||||
Range *GroupRange `json:"range,omitempty"` // 分组范围
|
Range *GroupRange `json:"range,omitempty"` // 分组范围
|
||||||
Order GroupOrder `json:"order"` // 分组排序规则
|
Order GroupOrder `json:"order"` // 分组排序规则
|
||||||
|
HideEmpty bool `json:"hideEmpty,omitempty"` // 是否隐藏空分组
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupMethod 描述了分组方式。
|
// GroupMethod 描述了分组方式。
|
||||||
|
|
|
||||||
|
|
@ -93,14 +93,14 @@ func syncAttrViewTableColWidth(operation *Operation) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doSetGroupHideEmpty(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doSetAttrViewHideEmptyGroup(operation *Operation) (ret *TxErr) {
|
||||||
if err := SetGroupHideEmpty(operation.AvID, operation.BlockID, operation.Data.(bool)); nil != err {
|
if err := setAttrViewHideEmptyGroup(operation.AvID, operation.BlockID, operation.Data.(bool)); nil != err {
|
||||||
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetGroupHideEmpty(avID, blockID string, hidden bool) (err error) {
|
func setAttrViewHideEmptyGroup(avID, blockID string, hidden bool) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -115,7 +115,14 @@ func SetGroupHideEmpty(avID, blockID string, hidden bool) (err error) {
|
||||||
return
|
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)
|
err = av.SaveAttributeView(attrView)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -301,8 +301,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doSetAttrViewGroup(op)
|
ret = tx.doSetAttrViewGroup(op)
|
||||||
case "hideAttrViewGroup":
|
case "hideAttrViewGroup":
|
||||||
ret = tx.doHideAttrViewGroup(op)
|
ret = tx.doHideAttrViewGroup(op)
|
||||||
case "setGroupHideEmpty":
|
case "setAttrViewHideEmptyGroup":
|
||||||
ret = tx.doSetGroupHideEmpty(op)
|
ret = tx.doSetAttrViewHideEmptyGroup(op)
|
||||||
case "syncAttrViewTableColWidth":
|
case "syncAttrViewTableColWidth":
|
||||||
ret = tx.doSyncAttrViewTableColWidth(op)
|
ret = tx.doSyncAttrViewTableColWidth(op)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue