mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
513d439b9f
4 changed files with 38 additions and 29 deletions
|
|
@ -196,6 +196,7 @@ type View struct {
|
|||
GroupName string `json:"groupName,omitempty"` // 分组名称
|
||||
GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
|
||||
GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
|
||||
GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
|
||||
}
|
||||
|
||||
// LayoutType 描述了视图布局类型。
|
||||
|
|
|
|||
|
|
@ -27,31 +27,34 @@ type ViewGroup struct {
|
|||
Field string `json:"field"` // 分组字段 ID
|
||||
Method GroupMethod `json:"method"` // 分组方式
|
||||
Range *GroupRange `json:"range,omitempty"` // 分组范围
|
||||
Order GroupOrder `json:"order"` // 分组顺序
|
||||
Order GroupOrder `json:"order"` // 分组排序规则
|
||||
}
|
||||
|
||||
// GroupMethod 描述了分组方式。
|
||||
type GroupMethod int
|
||||
|
||||
const (
|
||||
GroupMethodValue GroupMethod = iota // 按值分组
|
||||
GroupMethodRangeNum // 按数字范围分组
|
||||
GroupMethodDateRelative // 按相对日期日期分组
|
||||
GroupMethodDateRelative // 按相对日期分组
|
||||
GroupMethodDateDay // 按天日期分组
|
||||
GroupMethodDateWeek // 按周日期分组
|
||||
GroupMethodDateMonth // 按月日期分组
|
||||
GroupMethodDateYear // 按年日期分组
|
||||
)
|
||||
|
||||
// GroupRange 定义了分组范围的结构。
|
||||
// GroupRange 描述了分组范围的结构。
|
||||
type GroupRange struct {
|
||||
NumStart float64 `json:"numStart"` // 数字范围起始值
|
||||
NumEnd float64 `json:"numEnd"` // 数字范围结束值
|
||||
NumStep float64 `json:"numStep"` // 数字范围步长
|
||||
}
|
||||
|
||||
// GroupOrder 描述了分组排序规则。
|
||||
type GroupOrder string
|
||||
|
||||
const (
|
||||
GroupOrderAsc GroupOrder = "ASC"
|
||||
GroupOrderDesc GroupOrder = "DESC"
|
||||
GroupOrderAsc GroupOrder = "ASC" // 升序
|
||||
GroupOrderDesc GroupOrder = "DESC" // 降序
|
||||
GroupOrderMan GroupOrder = "Man" // 手动排序
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1229,26 +1229,9 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|||
}
|
||||
|
||||
// 做一些数据兼容和订正处理
|
||||
checkViewInstance(attrView)
|
||||
checkAttrView(attrView, view)
|
||||
upgradeAttributeViewSpec(attrView)
|
||||
|
||||
// 字段删除以后需要删除设置的过滤和排序
|
||||
tmpFilters := []*av.ViewFilter{}
|
||||
for _, f := range view.Filters {
|
||||
if k, _ := attrView.GetKey(f.Column); nil != k {
|
||||
tmpFilters = append(tmpFilters, f)
|
||||
}
|
||||
}
|
||||
view.Filters = tmpFilters
|
||||
|
||||
tmpSorts := []*av.ViewSort{}
|
||||
for _, s := range view.Sorts {
|
||||
if k, _ := attrView.GetKey(s.Column); nil != k {
|
||||
tmpSorts = append(tmpSorts, s)
|
||||
}
|
||||
}
|
||||
view.Sorts = tmpSorts
|
||||
|
||||
viewable = sql.RenderView(view, attrView, query)
|
||||
if nil == viewable {
|
||||
err = av.ErrViewNotFound
|
||||
|
|
|
|||
|
|
@ -23,13 +23,34 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
)
|
||||
|
||||
func checkViewInstance(attrView *av.AttributeView) {
|
||||
changed := false
|
||||
for i, view := range attrView.Views {
|
||||
if av.LayoutTypeGallery == view.LayoutType && nil == view.Gallery {
|
||||
func checkAttrView(attrView *av.AttributeView, view *av.View) {
|
||||
// 字段删除以后需要删除设置的过滤和排序
|
||||
tmpFilters := []*av.ViewFilter{}
|
||||
for _, f := range view.Filters {
|
||||
if k, _ := attrView.GetKey(f.Column); nil != k {
|
||||
tmpFilters = append(tmpFilters, f)
|
||||
}
|
||||
}
|
||||
changed := len(tmpFilters) != len(view.Filters)
|
||||
view.Filters = tmpFilters
|
||||
|
||||
tmpSorts := []*av.ViewSort{}
|
||||
for _, s := range view.Sorts {
|
||||
if k, _ := attrView.GetKey(s.Column); nil != k {
|
||||
tmpSorts = append(tmpSorts, s)
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
changed = len(tmpSorts) != len(view.Sorts)
|
||||
}
|
||||
view.Sorts = tmpSorts
|
||||
|
||||
// 视图类型不匹配时需要订正
|
||||
for i, v := range attrView.Views {
|
||||
if av.LayoutTypeGallery == v.LayoutType && nil == v.Gallery {
|
||||
// 切换为画廊视图时可能没有初始化画廊实例 https://github.com/siyuan-note/siyuan/issues/15122
|
||||
if nil != view.Table {
|
||||
view.LayoutType = av.LayoutTypeTable
|
||||
if nil != v.Table {
|
||||
v.LayoutType = av.LayoutTypeTable
|
||||
changed = true
|
||||
} else {
|
||||
attrView.Views = append(attrView.Views[:i], attrView.Views[i+1:]...)
|
||||
|
|
@ -37,6 +58,7 @@ func checkViewInstance(attrView *av.AttributeView) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
av.SaveAttributeView(attrView)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue