🎨 Improve database template field grouping https://github.com/siyuan-note/siyuan/issues/15687

This commit is contained in:
Daniel 2025-09-01 17:36:32 +08:00
parent afdd605dd1
commit 2de55d2e63
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -88,6 +88,11 @@ func renderAttributeView(attrView *av.AttributeView, nodeID, viewID, query strin
} }
func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView, view *av.View, query string, page, pageSize int, groupPaging map[string]interface{}) (err error) { func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView, view *av.View, query string, page, pageSize int, groupPaging map[string]interface{}) (err error) {
groupKey := view.GetGroupKey(attrView)
if nil == groupKey {
return
}
// 当前日期可能会变,所以如果是按日期分组则需要重新生成分组 // 当前日期可能会变,所以如果是按日期分组则需要重新生成分组
if isGroupByDate(view) { if isGroupByDate(view) {
createdDate := time.UnixMilli(view.GroupCreated).Format("2006-01-02") createdDate := time.UnixMilli(view.GroupCreated).Format("2006-01-02")
@ -97,9 +102,10 @@ func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView,
} }
} }
groupKey := view.GetGroupKey(attrView) // 如果是按模板分组则需要重新生成分组
if nil == groupKey { if isGroupByTemplate(attrView, view) {
return regenAttrViewGroups(attrView)
av.SaveAttributeView(attrView)
} }
// 如果存在分组的话渲染分组视图 // 如果存在分组的话渲染分组视图
@ -352,6 +358,18 @@ func isGroupByDate(view *av.View) bool {
return av.GroupMethodDateDay == view.Group.Method || av.GroupMethodDateWeek == view.Group.Method || av.GroupMethodDateMonth == view.Group.Method || av.GroupMethodDateYear == view.Group.Method || av.GroupMethodDateRelative == view.Group.Method return av.GroupMethodDateDay == view.Group.Method || av.GroupMethodDateWeek == view.Group.Method || av.GroupMethodDateMonth == view.Group.Method || av.GroupMethodDateYear == view.Group.Method || av.GroupMethodDateRelative == view.Group.Method
} }
func isGroupByTemplate(attrView *av.AttributeView, view *av.View) bool {
if nil == view.Group {
return false
}
groupKey := view.GetGroupKey(attrView)
if nil == groupKey {
return false
}
return av.KeyTypeTemplate == groupKey.Type
}
func renderViewableInstance(viewable av.Viewable, view *av.View, attrView *av.AttributeView, page, pageSize int) (err error) { func renderViewableInstance(viewable av.Viewable, view *av.View, attrView *av.AttributeView, page, pageSize int) (err error) {
if nil == viewable { if nil == viewable {
err = av.ErrViewNotFound err = av.ErrViewNotFound