feat: add server-side search, filter and sorter for all pages (#388)

Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com>

Co-authored-by: Yang Luo <hsluoyz@qq.com>
This commit is contained in:
Yixiang Zhao
2021-12-25 10:55:10 +08:00
committed by GitHub
parent 0d13512eb1
commit 10a85f2386
43 changed files with 929 additions and 610 deletions

View File

@ -33,8 +33,12 @@ type Webhook struct {
Organization string `xorm:"varchar(100) index" json:"organization"`
}
func GetWebhookCount(owner string) int {
count, err := adapter.Engine.Count(&Webhook{Owner: owner})
func GetWebhookCount(owner, field, value string) int {
session := adapter.Engine.Where("owner=?", owner)
if field != "" && value != "" {
session = session.And(fmt.Sprintf("%s like ?", util.SnakeString(field)), fmt.Sprintf("%%%s%%", value))
}
count, err := session.Count(&Webhook{})
if err != nil {
panic(err)
}
@ -52,9 +56,10 @@ func GetWebhooks(owner string) []*Webhook {
return webhooks
}
func GetPaginationWebhooks(owner string, offset, limit int) []*Webhook {
func GetPaginationWebhooks(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Webhook {
webhooks := []*Webhook{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&webhooks, &Webhook{Owner: owner})
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
err := session.Find(&webhooks)
if err != nil {
panic(err)
}