mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
✨ Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
0ca321f8d4
commit
e98dcf65b6
6 changed files with 30 additions and 20 deletions
|
|
@ -254,7 +254,6 @@ func NewGalleryView() (ret *View) {
|
|||
type Viewable interface {
|
||||
Filterable
|
||||
Sortable
|
||||
Groupable
|
||||
Calculable
|
||||
|
||||
GetType() LayoutType
|
||||
|
|
|
|||
|
|
@ -16,13 +16,6 @@
|
|||
|
||||
package av
|
||||
|
||||
// Groupable 定义了可分组的视图类型。
|
||||
type Groupable interface {
|
||||
|
||||
// Group 根据视图中设置的分组规则进行分组。
|
||||
Group(attrView *AttributeView)
|
||||
}
|
||||
|
||||
type ViewGroup struct {
|
||||
Field string `json:"field"` // 分组字段 ID
|
||||
Method GroupMethod `json:"method"` // 分组方式
|
||||
|
|
|
|||
|
|
@ -316,7 +316,3 @@ func filter0(collection Collection, attrView *AttributeView) {
|
|||
}
|
||||
collection.SetItems(items)
|
||||
}
|
||||
|
||||
func group0(collection Collection, attrView *AttributeView) {
|
||||
// TODO 分组 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,3 @@ func (gallery *Gallery) Sort(attrView *AttributeView) {
|
|||
func (gallery *Gallery) Filter(attrView *AttributeView) {
|
||||
filter0(gallery, attrView)
|
||||
}
|
||||
|
||||
func (gallery *Gallery) Group(attrView *AttributeView) {
|
||||
group0(gallery, attrView)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,3 @@ func (table *Table) Sort(attrView *AttributeView) {
|
|||
func (table *Table) Filter(attrView *AttributeView) {
|
||||
filter0(table, attrView)
|
||||
}
|
||||
|
||||
func (table *Table) Group(attrView *AttributeView) {
|
||||
group0(table, attrView)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1232,7 +1232,37 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|||
checkAttrView(attrView, view)
|
||||
upgradeAttributeViewSpec(attrView)
|
||||
|
||||
if nil != view.Group && 0 < len(view.Groups) {
|
||||
var instances []av.Viewable
|
||||
for _, groupView := range view.Groups {
|
||||
groupViewable := sql.RenderView(groupView, attrView, query)
|
||||
err = renderViewableInstance(groupViewable, view, attrView, page, pageSize)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
instances = append(instances, groupViewable)
|
||||
}
|
||||
|
||||
viewable = instances[0]
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for i := 1; i < len(instances); i++ {
|
||||
viewable.(*av.Table).Groups = append(viewable.(*av.Table).Groups, instances[i].(*av.Table).Groups...)
|
||||
}
|
||||
case av.LayoutTypeGallery:
|
||||
for i := 1; i < len(instances); i++ {
|
||||
viewable.(*av.Gallery).Groups = append(viewable.(*av.Gallery).Groups, instances[i].(*av.Gallery).Groups...)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
viewable = sql.RenderView(view, attrView, query)
|
||||
err = renderViewableInstance(viewable, view, attrView, page, pageSize)
|
||||
return
|
||||
}
|
||||
|
||||
func renderViewableInstance(viewable av.Viewable, view *av.View, attrView *av.AttributeView, page, pageSize int) (err error) {
|
||||
if nil == viewable {
|
||||
err = av.ErrViewNotFound
|
||||
logging.LogErrorf("render attribute view [%s] failed", attrView.ID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue