diff options
author | Unknown <joe2010xtmf@163.com> | 2014-07-07 04:15:08 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-07-07 04:15:08 -0400 |
commit | 63cc14062a891a99a429f2eef0ee90a3f5795f47 (patch) | |
tree | 5149f44074323e55763a0ca4c880177399f74b06 /routers/admin/admin.go | |
parent | 7ffdabb28f65b9e4414cd19c0c1f1a400b16b1f3 (diff) | |
download | gitea-63cc14062a891a99a429f2eef0ee90a3f5795f47.tar.gz gitea-63cc14062a891a99a429f2eef0ee90a3f5795f47.zip |
Paging function for users and repositories
Diffstat (limited to 'routers/admin/admin.go')
-rw-r--r-- | routers/admin/admin.go | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 50a3823a0f..2a40792a18 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -30,7 +30,9 @@ const ( MONITOR_CRON base.TplName = "admin/monitor/cron" ) -var startTime = time.Now() +var ( + startTime = time.Now() +) var sysStatus struct { Uptime string @@ -157,8 +159,24 @@ func Users(ctx *middleware.Context) { ctx.Data["Title"] = "User Management" ctx.Data["PageIsUsers"] = true + p := base.StrTo(ctx.Query("p")).MustInt() + if p < 1 { + p = 1 + } + pageNum := 100 + count := models.CountUsers() + curCount := int64((p-1)*pageNum + pageNum) + if curCount > count { + p = int(count) / pageNum + } else if count > curCount { + ctx.Data["NextPageNum"] = p + 1 + } + if p > 1 { + ctx.Data["LastPageNum"] = p - 1 + } + var err error - ctx.Data["Users"], err = models.GetUsers(200, 0) + ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "admin.Users(GetUsers)", err) return @@ -170,8 +188,24 @@ func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = "Repository Management" ctx.Data["PageIsRepos"] = true + p := base.StrTo(ctx.Query("p")).MustInt() + if p < 1 { + p = 1 + } + pageNum := 2 + count := models.CountRepositories() + curCount := int64((p-1)*pageNum + pageNum) + if curCount > count { + p = int(count) / pageNum + } else if count > curCount { + ctx.Data["NextPageNum"] = p + 1 + } + if p > 1 { + ctx.Data["LastPageNum"] = p - 1 + } + var err error - ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(200, 0) + ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "admin.Repositories", err) return |