mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
e7a8a9906e
commit
0e8ce9ddf9
3 changed files with 33 additions and 9 deletions
|
@ -199,7 +199,7 @@ type View struct {
|
|||
GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则
|
||||
GroupName string `json:"groupName,omitempty"` // 分组名称
|
||||
GroupFolded bool `json:"groupFolded"` // 分组是否折叠
|
||||
GroupHidden bool `json:"groupHidden"` // 分组是否隐藏
|
||||
GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏
|
||||
}
|
||||
|
||||
// GroupCalc 描述了分组计算规则和结果的结构。
|
||||
|
@ -290,7 +290,8 @@ type Viewable interface {
|
|||
SetGroupFolded(folded bool)
|
||||
|
||||
// SetGroupHidden 设置分组是否隐藏。
|
||||
SetGroupHidden(hidden bool)
|
||||
// hidden 0:显示,1:空白隐藏,2:手动隐藏
|
||||
SetGroupHidden(hidden int)
|
||||
}
|
||||
|
||||
func NewAttributeView(id string) (ret *AttributeView) {
|
||||
|
|
|
@ -68,7 +68,7 @@ type BaseInstance struct {
|
|||
GroupCalc *GroupCalc `json:"groupCalc,omitempty"` // 分组计算规则和结果
|
||||
GroupName string `json:"groupName,omitempty"` // 分组名称
|
||||
GroupFolded bool `json:"groupFolded"` // 分组是否折叠
|
||||
GroupHidden bool `json:"groupHidden"` // 分组是否隐藏
|
||||
GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏
|
||||
}
|
||||
|
||||
func NewViewBaseInstance(view *View) *BaseInstance {
|
||||
|
@ -127,7 +127,7 @@ func (baseInstance *BaseInstance) SetGroupFolded(folded bool) {
|
|||
baseInstance.GroupFolded = folded
|
||||
}
|
||||
|
||||
func (baseInstance *BaseInstance) SetGroupHidden(hidden bool) {
|
||||
func (baseInstance *BaseInstance) SetGroupHidden(hidden int) {
|
||||
baseInstance.GroupHidden = hidden
|
||||
}
|
||||
|
||||
|
|
|
@ -121,13 +121,13 @@ func syncAttrViewTableColWidth(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
func (tx *Transaction) doHideAttrViewGroup(operation *Operation) (ret *TxErr) {
|
||||
if err := hideAttributeViewGroup(operation.AvID, operation.BlockID, operation.ID, operation.Data.(bool)); nil != err {
|
||||
if err := hideAttributeViewGroup(operation.AvID, operation.BlockID, operation.ID, int(operation.Data.(float64))); nil != err {
|
||||
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hideAttributeViewGroup(avID, blockID, groupID string, hidden bool) (err error) {
|
||||
func hideAttributeViewGroup(avID, blockID, groupID string, hidden int) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -186,8 +186,29 @@ func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error
|
|||
return err
|
||||
}
|
||||
|
||||
oldHideEmpty := false
|
||||
if nil != view.Group {
|
||||
oldHideEmpty = view.Group.HideEmpty
|
||||
}
|
||||
|
||||
view.Group = group
|
||||
genAttrViewViewGroups(view, attrView)
|
||||
|
||||
if view.Group.HideEmpty != oldHideEmpty {
|
||||
for _, g := range view.Groups {
|
||||
if view.Group.HideEmpty {
|
||||
if 2 != g.GroupHidden && 1 > len(g.GroupItemIDs) {
|
||||
g.GroupHidden = 1
|
||||
}
|
||||
} else {
|
||||
if 2 != g.GroupHidden {
|
||||
g.GroupHidden = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1406,6 +1427,7 @@ func renderAttributeView(attrView *av.AttributeView, blockID, viewID, query stri
|
|||
updatedDate := time.UnixMilli(view.GroupUpdated).Format("2006-01-02")
|
||||
if time.Now().Format("2006-01-02") != updatedDate {
|
||||
genAttrViewViewGroups(view, attrView)
|
||||
av.SaveAttributeView(attrView)
|
||||
}
|
||||
|
||||
for _, groupView := range view.Groups {
|
||||
|
@ -1468,7 +1490,10 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
|||
}
|
||||
|
||||
// 如果是按日期分组,则需要记录每个分组视图的一些状态字段,以便后面重新计算分组后可以恢复这些状态
|
||||
type GroupState struct{ Folded, Hidden bool }
|
||||
type GroupState struct {
|
||||
Folded bool
|
||||
Hidden int
|
||||
}
|
||||
groupStates := map[string]*GroupState{}
|
||||
if isGroupByDate(view) {
|
||||
for _, groupView := range view.Groups {
|
||||
|
@ -1637,8 +1662,6 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
av.SaveAttributeView(attrView)
|
||||
}
|
||||
|
||||
func isGroupByDate(view *av.View) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue