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

Daniel008cce474a7b
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 4c5cef3caf..7b6babf0c1 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1740,7 +1740,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
v.GroupItemIDs = append(v.GroupItemIDs, item.GetID())
}
- v.Name = ""
+ v.Name = "" // 分组视图的名称在渲染时才填充
v.GroupValue = name
view.Groups = append(view.Groups, v)
}
@@ -1755,26 +1755,90 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
}
}
- // 恢复分组视图的顺序
- if len(groupStates) > 0 {
- sort.SliceStable(view.Groups, func(i, j int) bool {
- if stateI, ok := groupStates[view.Groups[i].GroupValue]; ok {
- if stateJ, ok := groupStates[view.Groups[j].GroupValue]; ok {
- return stateI.Sort < stateJ.Sort
+ if av.GroupOrderMan == view.Group.Order {
+ // 恢复分组视图的自定义顺序
+ if len(groupStates) > 0 {
+ sort.SliceStable(view.Groups, func(i, j int) bool {
+ if stateI, ok := groupStates[view.Groups[i].GroupValue]; ok {
+ if stateJ, ok := groupStates[view.Groups[j].GroupValue]; ok {
+ return stateI.Sort < stateJ.Sort
+ }
+ }
+ return false
+ })
+ }
+ } else {
+ if av.GroupMethodDateRelative == view.Group.Method {
+ var monthGroups []*av.View
+ var last30Days, last7Days, yesterday, today, tomorrow, next7Days, next30Days *av.View
+ for _, groupView := range view.Groups {
+ _, err := time.Parse("2006-01", groupView.GroupValue)
+ if nil == err { // 如果能解析出来说明是 30 天之前或 30 天之后的分组形式
+ monthGroups = append(monthGroups, groupView)
+ } else { // 否则是相对日期分组形式
+ switch groupView.GroupValue {
+ case groupValueLast30Days:
+ last30Days = groupView
+ case groupValueLast7Days:
+ last7Days = groupView
+ case groupValueYesterday:
+ yesterday = groupView
+ case groupValueToday:
+ today = groupView
+ case groupValueTomorrow:
+ tomorrow = groupView
+ case groupValueNext7Days:
+ next7Days = groupView
+ case groupValueNext30Days:
+ next30Days = groupView
+ }
+ }
+ }
+
+ sort.SliceStable(monthGroups, func(i, j int) bool {
+ return monthGroups[i].GroupValue < monthGroups[j].GroupValue
+ })
+
+ var idx int
+ thisMonth := todayStart.Format("2006-01")
+ for i, monthGroup := range monthGroups {
+ if monthGroup.GroupValue > thisMonth {
+ idx = i
+ break
}
}
- return false
- })
- }
- if av.GroupOrderMan != view.Group.Order {
- sort.SliceStable(view.Groups, func(i, j int) bool {
- iVal, jVal := view.Groups[i].GroupValue, view.Groups[j].GroupValue
- if av.GroupOrderAsc == view.Group.Order {
- return util.NaturalCompare(iVal, jVal)
+ if nil != next30Days {
+ util.InsertElem(monthGroups, idx, next30Days)
}
- return util.NaturalCompare(jVal, iVal)
- })
+ if nil != next7Days {
+ util.InsertElem(monthGroups, idx, next7Days)
+ }
+ if nil != tomorrow {
+ util.InsertElem(monthGroups, idx, tomorrow)
+ }
+ if nil != today {
+ util.InsertElem(monthGroups, idx, today)
+ }
+ if nil != yesterday {
+ util.InsertElem(monthGroups, idx, yesterday)
+ }
+ if nil != last7Days {
+ util.InsertElem(monthGroups, idx, last7Days)
+ }
+ if nil != last30Days {
+ util.InsertElem(monthGroups, idx, last30Days)
+ }
+ view.Groups = monthGroups
+ } else {
+ sort.SliceStable(view.Groups, func(i, j int) bool {
+ iVal, jVal := view.Groups[i].GroupValue, view.Groups[j].GroupValue
+ if av.GroupOrderAsc == view.Group.Order {
+ return util.NaturalCompare(iVal, jVal)
+ }
+ return util.NaturalCompare(jVal, iVal)
+ })
+ }
}
}