mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
2bbe0933b0
commit
9d59e84d76
1 changed files with 23 additions and 3 deletions
|
|
@ -143,7 +143,7 @@ func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error
|
||||||
}
|
}
|
||||||
|
|
||||||
view.Group = group
|
view.Group = group
|
||||||
genGroup(view, attrView)
|
genAttrViewViewGroups(view, attrView)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1351,7 +1351,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
||||||
if isGroupByDate(view) {
|
if isGroupByDate(view) {
|
||||||
updatedDate := time.UnixMilli(view.GroupUpdated).Format("2006-01-02")
|
updatedDate := time.UnixMilli(view.GroupUpdated).Format("2006-01-02")
|
||||||
if time.Now().Format("2006-01-02") != updatedDate {
|
if time.Now().Format("2006-01-02") != updatedDate {
|
||||||
genGroup(view, attrView)
|
genAttrViewViewGroups(view, attrView)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, groupView := range view.Groups {
|
for _, groupView := range view.Groups {
|
||||||
|
|
@ -1395,7 +1395,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func genGroup(view *av.View, attrView *av.AttributeView) {
|
func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
||||||
if nil == view.Group {
|
if nil == view.Group {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1413,6 +1413,18 @@ func genGroup(view *av.View, attrView *av.AttributeView) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是按日期分组,则需要记录每个分组视图的一些状态字段,以便后面重新计算分组后可以恢复这些状态
|
||||||
|
type GroupState struct{ Folded, Hidden bool }
|
||||||
|
groupStates := map[string]*GroupState{}
|
||||||
|
if isGroupByDate(view) {
|
||||||
|
for _, groupView := range view.Groups {
|
||||||
|
groupStates[groupView.Name] = &GroupState{
|
||||||
|
Folded: groupView.GroupFolded,
|
||||||
|
Hidden: groupView.GroupHidden,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rangeStart, rangeEnd float64
|
var rangeStart, rangeEnd float64
|
||||||
switch group.Method {
|
switch group.Method {
|
||||||
case av.GroupMethodValue:
|
case av.GroupMethodValue:
|
||||||
|
|
@ -1548,6 +1560,14 @@ func genGroup(view *av.View, attrView *av.AttributeView) {
|
||||||
|
|
||||||
if isGroupByDate(view) {
|
if isGroupByDate(view) {
|
||||||
view.GroupUpdated = time.Now().UnixMilli()
|
view.GroupUpdated = time.Now().UnixMilli()
|
||||||
|
|
||||||
|
// 则恢复分组视图状态
|
||||||
|
for _, groupView := range view.Groups {
|
||||||
|
if state, ok := groupStates[groupView.Name]; ok {
|
||||||
|
groupView.GroupFolded = state.Folded
|
||||||
|
groupView.GroupHidden = state.Hidden
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av.SaveAttributeView(attrView)
|
av.SaveAttributeView(attrView)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue