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
3595312920
commit
724db336c8
4 changed files with 47 additions and 11 deletions
|
@ -27,6 +27,40 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func setAttrViewGroup(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
avID := arg["avID"].(string)
|
||||
blockID := arg["blockID"].(string)
|
||||
groupArg := arg["group"].(map[string]interface{})
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(groupArg)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
group := &av.ViewGroup{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, group); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
err = model.SetAttributeViewGroup(avID, blockID, group)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func changeAttrViewLayout(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
|
|
|
@ -455,6 +455,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/av/appendAttributeViewDetachedBlocksWithValues", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, appendAttributeViewDetachedBlocksWithValues)
|
||||
ginServer.Handle("POST", "/api/av/getCurrentAttrViewImages", model.CheckAuth, getCurrentAttrViewImages)
|
||||
ginServer.Handle("POST", "/api/av/changeAttrViewLayout", model.CheckAuth, changeAttrViewLayout)
|
||||
ginServer.Handle("POST", "/api/av/setAttrViewGroup", model.CheckAuth, setAttrViewGroup)
|
||||
|
||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckAdminRole, chatGPT)
|
||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckAdminRole, chatGPTWithAction)
|
||||
|
|
|
@ -44,10 +44,10 @@ type GroupRange struct {
|
|||
}
|
||||
|
||||
// GroupOrder 描述了分组排序规则。
|
||||
type GroupOrder string
|
||||
type GroupOrder int
|
||||
|
||||
const (
|
||||
GroupOrderAsc GroupOrder = "ASC" // 升序
|
||||
GroupOrderDesc GroupOrder = "DESC" // 降序
|
||||
GroupOrderMan GroupOrder = "Man" // 手动排序
|
||||
GroupOrderAsc = iota // 升序
|
||||
GroupOrderDesc // 降序
|
||||
GroupOrderMan // 手动排序
|
||||
)
|
||||
|
|
|
@ -45,26 +45,26 @@ import (
|
|||
)
|
||||
|
||||
func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
|
||||
err := setAttrViewGroup(operation)
|
||||
err := SetAttributeViewGroup(operation.AvID, operation.BlockID, operation.Data.(*av.ViewGroup))
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttrViewGroup(operation *Operation) error {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) error {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)
|
||||
view, err := getAttrViewViewByBlockID(attrView, blockID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
group := operation.Data.(*av.ViewGroup)
|
||||
view.Group = group
|
||||
view.Groups = nil
|
||||
|
||||
// TODO Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
|
||||
// 生成分组数据
|
||||
|
@ -1288,6 +1288,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|||
if nil != view.Group && 0 < len(view.Groups) {
|
||||
var instances []av.Viewable
|
||||
for _, groupView := range view.Groups {
|
||||
groupView.Table.Columns = view.Table.Columns
|
||||
groupViewable := sql.RenderView(groupView, attrView, query)
|
||||
err = renderViewableInstance(groupViewable, view, attrView, page, pageSize)
|
||||
if nil != err {
|
||||
|
@ -1300,11 +1301,11 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|||
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...)
|
||||
viewable.(*av.Table).Groups = append(viewable.(*av.Table).Groups, instances[i].(*av.Table))
|
||||
}
|
||||
case av.LayoutTypeGallery:
|
||||
for i := 1; i < len(instances); i++ {
|
||||
viewable.(*av.Gallery).Groups = append(viewable.(*av.Gallery).Groups, instances[i].(*av.Gallery).Groups...)
|
||||
viewable.(*av.Gallery).Groups = append(viewable.(*av.Gallery).Groups, instances[i].(*av.Gallery))
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue