Skip to content

Commit 445a738

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents 89f32a4 + 77fd025 commit 445a738

2 files changed

Lines changed: 49 additions & 56 deletions

File tree

kernel/av/av.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ type View struct {
202202
GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏
203203
}
204204

205-
const (
206-
GroupValueDefault = "_@default@_" // 默认分组值(值为空的默认分组)
207-
GroupValueNotInRange = "_@notInRange@_" // 不再范围内的分组值(只有数字类型的分组才可能是该值)
208-
)
209-
210205
// GetGroup 获取指定分组 ID 的分组视图。
211206
func (view *View) GetGroup(groupID string) *View {
212207
if nil == view.Groups {

kernel/model/attribute_view.go

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,11 @@ func RenderAttributeView(blockID, avID, viewID, query string, page, pageSize int
14571457
}
14581458

14591459
const (
1460-
groupNameLast30Days, groupNameLast7Days = "_@last30Days@_", "_@last7Days@_"
1461-
groupNameYesterday, groupNameToday, groupNameTomorrow = "_@yesterday@_", "_@today@_", "_@tomorrow@_"
1462-
groupNameNext7Days, groupNameNext30Days = "_@next7Days@_", "_@next30Days@_"
1460+
groupValueDefault = "_@default@_" // 默认分组值(值为空的默认分组)
1461+
groupValueNotInRange = "_@notInRange@_" // 不再范围内的分组值(只有数字类型的分组才可能是该值)
1462+
groupValueLast30Days, groupValueLast7Days = "_@last30Days@_", "_@last7Days@_"
1463+
groupValueYesterday, groupValueToday, groupValueTomorrow = "_@yesterday@_", "_@today@_", "_@tomorrow@_"
1464+
groupValueNext7Days, groupValueNext30Days = "_@next7Days@_", "_@next30Days@_"
14631465
)
14641466

14651467
func renderAttributeView(attrView *av.AttributeView, blockID, viewID, query string, page, pageSize int) (viewable av.Viewable, err error) {
@@ -1518,22 +1520,29 @@ func renderAttributeView(attrView *av.AttributeView, blockID, viewID, query stri
15181520
av.SaveAttributeView(attrView)
15191521
}
15201522

1523+
groupKey := view.GetGroupKey(attrView)
15211524
for _, groupView := range view.Groups {
1522-
switch groupView.Name {
1523-
case groupNameLast30Days:
1525+
switch groupView.GroupValue {
1526+
case groupValueDefault:
1527+
groupView.Name = fmt.Sprintf(Conf.language(264), groupKey.Name)
1528+
case groupValueNotInRange:
1529+
groupView.Name = Conf.language(265)
1530+
case groupValueLast30Days:
15241531
groupView.Name = fmt.Sprintf(Conf.language(259), 30)
1525-
case groupNameLast7Days:
1532+
case groupValueLast7Days:
15261533
groupView.Name = fmt.Sprintf(Conf.language(259), 7)
1527-
case groupNameYesterday:
1534+
case groupValueYesterday:
15281535
groupView.Name = Conf.language(260)
1529-
case groupNameToday:
1536+
case groupValueToday:
15301537
groupView.Name = Conf.language(261)
1531-
case groupNameTomorrow:
1538+
case groupValueTomorrow:
15321539
groupView.Name = Conf.language(262)
1533-
case groupNameNext7Days:
1540+
case groupValueNext7Days:
15341541
groupView.Name = fmt.Sprintf(Conf.language(263), 7)
1535-
case groupNameNext30Days:
1542+
case groupValueNext30Days:
15361543
groupView.Name = fmt.Sprintf(Conf.language(263), 30)
1544+
default:
1545+
groupView.Name = groupView.GroupValue
15371546
}
15381547
}
15391548
}
@@ -1573,7 +1582,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
15731582
}
15741583
groupStates := map[string]*GroupState{}
15751584
for i, groupView := range view.Groups {
1576-
groupStates[groupView.Name] = &GroupState{
1585+
groupStates[groupView.GroupValue] = &GroupState{
15771586
Folded: groupView.GroupFolded,
15781587
Hidden: groupView.GroupHidden,
15791588
Sort: i,
@@ -1629,22 +1638,22 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
16291638
todayStart := time.Now()
16301639
todayStart = time.Date(todayStart.Year(), todayStart.Month(), todayStart.Day(), 0, 0, 0, 0, time.Local)
16311640

1632-
var groupName string
1641+
var groupVal string
16331642
groupItemsMap := map[string][]av.Item{}
16341643
for _, item := range items {
16351644
value := item.GetValue(group.Field)
16361645
if value.IsEmpty() {
1637-
groupName = av.GroupValueDefault
1638-
groupItemsMap[groupName] = append(groupItemsMap[groupName], item)
1646+
groupVal = groupValueDefault
1647+
groupItemsMap[groupVal] = append(groupItemsMap[groupVal], item)
16391648
continue
16401649
}
16411650

16421651
switch group.Method {
16431652
case av.GroupMethodValue:
1644-
groupName = value.String(false)
1653+
groupVal = value.String(false)
16451654
case av.GroupMethodRangeNum:
16461655
if group.Range.NumStart > value.Number.Content || group.Range.NumEnd < value.Number.Content {
1647-
groupName = av.GroupValueNotInRange
1656+
groupVal = groupValueNotInRange
16481657
break
16491658
}
16501659

@@ -1654,7 +1663,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
16541663
}
16551664

16561665
if rangeStart <= value.Number.Content && rangeEnd > value.Number.Content {
1657-
groupName = fmt.Sprintf("%s - %s", strconv.FormatFloat(rangeStart, 'f', -1, 64), strconv.FormatFloat(rangeEnd, 'f', -1, 64))
1666+
groupVal = fmt.Sprintf("%s - %s", strconv.FormatFloat(rangeStart, 'f', -1, 64), strconv.FormatFloat(rangeEnd, 'f', -1, 64))
16581667
}
16591668
case av.GroupMethodDateDay, av.GroupMethodDateWeek, av.GroupMethodDateMonth, av.GroupMethodDateYear, av.GroupMethodDateRelative:
16601669
var contentTime time.Time
@@ -1668,40 +1677,40 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
16681677
}
16691678
switch group.Method {
16701679
case av.GroupMethodDateDay:
1671-
groupName = contentTime.Format("2006-01-02")
1680+
groupVal = contentTime.Format("2006-01-02")
16721681
case av.GroupMethodDateWeek:
16731682
year, week := contentTime.ISOWeek()
1674-
groupName = fmt.Sprintf("%d-W%02d", year, week)
1683+
groupVal = fmt.Sprintf("%d-W%02d", year, week)
16751684
case av.GroupMethodDateMonth:
1676-
groupName = contentTime.Format("2006-01")
1685+
groupVal = contentTime.Format("2006-01")
16771686
case av.GroupMethodDateYear:
1678-
groupName = contentTime.Format("2006")
1687+
groupVal = contentTime.Format("2006")
16791688
case av.GroupMethodDateRelative:
16801689
// 过去 30 天之前的按月分组
16811690
// 过去 30 天、过去 7 天、昨天、今天、明天、未来 7 天、未来 30 天
16821691
// 未来 30 天之后的按月分组
16831692
if contentTime.Before(todayStart.AddDate(0, 0, -30)) {
1684-
groupName = "0" + contentTime.Format("2006-01") // 开头的数字用于排序,下同
1693+
groupVal = contentTime.Format("2006-01") // 开头的数字用于排序,下同
16851694
} else if contentTime.Before(todayStart.AddDate(0, 0, -7)) {
1686-
groupName = "1" + groupNameLast30Days
1695+
groupVal = groupValueLast30Days
16871696
} else if contentTime.Before(todayStart.AddDate(0, 0, -1)) {
1688-
groupName = "2" + groupNameLast7Days
1697+
groupVal = groupValueLast7Days
16891698
} else if contentTime.Before(todayStart) {
1690-
groupName = "3" + groupNameYesterday
1699+
groupVal = groupValueYesterday
16911700
} else if (contentTime.After(todayStart) || contentTime.Equal(todayStart)) && contentTime.Before(todayStart.AddDate(0, 0, 1)) {
1692-
groupName = "4" + groupNameToday
1701+
groupVal = groupValueToday
16931702
} else if contentTime.After(todayStart.AddDate(0, 0, 30)) {
1694-
groupName = "8" + contentTime.Format("2006-01")
1703+
groupVal = contentTime.Format("2006-01")
16951704
} else if contentTime.After(todayStart.AddDate(0, 0, 7)) {
1696-
groupName = "7" + groupNameNext30Days
1705+
groupVal = groupValueNext30Days
16971706
} else if contentTime.Equal(todayStart.AddDate(0, 0, 2)) || contentTime.After(todayStart.AddDate(0, 0, 2)) {
1698-
groupName = "6" + groupNameNext7Days
1707+
groupVal = groupValueNext7Days
16991708
} else {
1700-
groupName = "5" + groupNameTomorrow
1709+
groupVal = groupValueTomorrow
17011710
}
17021711
}
17031712
}
1704-
groupItemsMap[groupName] = append(groupItemsMap[groupName], item)
1713+
groupItemsMap[groupVal] = append(groupItemsMap[groupVal], item)
17051714
}
17061715

17071716
if av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type {
@@ -1731,21 +1740,16 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
17311740
v.GroupItemIDs = append(v.GroupItemIDs, item.GetID())
17321741
}
17331742

1743+
v.Name = ""
17341744
v.GroupValue = name
1735-
if av.GroupValueDefault == name {
1736-
name = fmt.Sprintf(Conf.language(264), groupKey.Name)
1737-
} else if av.GroupValueNotInRange == name {
1738-
name = fmt.Sprintf(Conf.language(265))
1739-
}
1740-
v.Name = name
17411745
view.Groups = append(view.Groups, v)
17421746
}
17431747

17441748
view.GroupUpdated = time.Now().UnixMilli()
17451749

17461750
// 恢复分组视图状态
17471751
for _, groupView := range view.Groups {
1748-
if state, ok := groupStates[groupView.Name]; ok {
1752+
if state, ok := groupStates[groupView.GroupValue]; ok {
17491753
groupView.GroupFolded = state.Folded
17501754
groupView.GroupHidden = state.Hidden
17511755
}
@@ -1754,8 +1758,8 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
17541758
// 恢复分组视图的顺序
17551759
if len(groupStates) > 0 {
17561760
sort.SliceStable(view.Groups, func(i, j int) bool {
1757-
if stateI, ok := groupStates[view.Groups[i].Name]; ok {
1758-
if stateJ, ok := groupStates[view.Groups[j].Name]; ok {
1761+
if stateI, ok := groupStates[view.Groups[i].GroupValue]; ok {
1762+
if stateJ, ok := groupStates[view.Groups[j].GroupValue]; ok {
17591763
return stateI.Sort < stateJ.Sort
17601764
}
17611765
}
@@ -1765,19 +1769,13 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
17651769

17661770
if av.GroupOrderMan != view.Group.Order {
17671771
sort.SliceStable(view.Groups, func(i, j int) bool {
1768-
iName, jName := view.Groups[i].Name, view.Groups[j].Name
1772+
iVal, jVal := view.Groups[i].GroupValue, view.Groups[j].GroupValue
17691773
if av.GroupOrderAsc == view.Group.Order {
1770-
return util.NaturalCompare(iName, jName)
1774+
return util.NaturalCompare(iVal, jVal)
17711775
}
1772-
return util.NaturalCompare(jName, iName)
1776+
return util.NaturalCompare(jVal, iVal)
17731777
})
17741778
}
1775-
1776-
if group.Method == av.GroupMethodDateRelative {
1777-
for _, v := range view.Groups {
1778-
v.Name = v.Name[1:] // 去掉前缀排序数字
1779-
}
1780-
}
17811779
}
17821780

17831781
func isGroupByDate(view *av.View) bool {
@@ -3095,7 +3093,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
30953093

30963094
if av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type {
30973095
// 因为单选或多选只能按选项分组,并且可能存在空白分组(前面可能找不到临近项) ,所以单选或多选类型的分组字段使用分组值内容对应的选项
3098-
if opt := groupKey.GetOption(groupView.GroupValue); nil != opt && av.GroupValueDefault != groupView.GroupValue {
3096+
if opt := groupKey.GetOption(groupView.GroupValue); nil != opt && groupValueDefault != groupView.GroupValue {
30993097
newValue.MSelect[0].Content = opt.Name
31003098
newValue.MSelect[0].Color = opt.Color
31013099
}

0 commit comments

Comments
 (0)