1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Support pagination of organizations on user settings pages (#16083)

* Add pagination for user setting orgs
* Use FindOrgs instead of GetOrgsByUserID
* Remove unnecessary functions and fix test
* remove unnecessary code
This commit is contained in:
Lunny Xiao
2021-11-22 21:51:45 +08:00
committed by GitHub
parent ed23a6c397
commit c2ab19888f
7 changed files with 108 additions and 34 deletions

View File

@@ -214,12 +214,34 @@ func DeleteAvatar(ctx *context.Context) {
func Organization(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsOrganization"] = true
orgs, err := models.GetOrgsByUserID(ctx.User.ID, ctx.IsSigned)
opts := models.FindOrgOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
Page: ctx.FormInt("page"),
},
UserID: ctx.User.ID,
IncludePrivate: ctx.IsSigned,
}
if opts.Page <= 0 {
opts.Page = 1
}
orgs, err := models.FindOrgs(opts)
if err != nil {
ctx.ServerError("GetOrgsByUserID", err)
ctx.ServerError("FindOrgs", err)
return
}
total, err := models.CountOrgs(opts)
if err != nil {
ctx.ServerError("CountOrgs", err)
return
}
ctx.Data["Orgs"] = orgs
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplSettingsOrganization)
}