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
445a738e74
commit
008cce474a
1 changed files with 81 additions and 17 deletions
|
@ -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,7 +1755,8 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
|||
}
|
||||
}
|
||||
|
||||
// 恢复分组视图的顺序
|
||||
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 {
|
||||
|
@ -1766,8 +1767,70 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if av.GroupOrderMan != view.Group.Order {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if nil != next30Days {
|
||||
util.InsertElem(monthGroups, idx, next30Days)
|
||||
}
|
||||
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 {
|
||||
|
@ -1776,6 +1839,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
|
|||
return util.NaturalCompare(jVal, iVal)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isGroupByDate(view *av.View) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue