You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "math"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/middleware"
  10. )
  11. const (
  12. REPOS base.TplName = "admin/repo/list"
  13. )
  14. func pagination(ctx *middleware.Context, count int64, pageNum int) int {
  15. p := ctx.QueryInt("p")
  16. if p < 1 {
  17. p = 1
  18. }
  19. curCount := int64((p-1)*pageNum + pageNum)
  20. if curCount >= count {
  21. p = int(math.Ceil(float64(count) / float64(pageNum)))
  22. } else {
  23. ctx.Data["NextPageNum"] = p + 1
  24. }
  25. if p > 1 {
  26. ctx.Data["LastPageNum"] = p - 1
  27. }
  28. return p
  29. }
  30. func Repositories(ctx *middleware.Context) {
  31. ctx.Data["Title"] = ctx.Tr("admin.repositories")
  32. ctx.Data["PageIsAdmin"] = true
  33. ctx.Data["PageIsAdminRepositories"] = true
  34. pageNum := 50
  35. p := pagination(ctx, models.CountRepositories(), pageNum)
  36. var err error
  37. ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum)
  38. if err != nil {
  39. ctx.Handle(500, "GetRepositoriesWithUsers", err)
  40. return
  41. }
  42. ctx.HTML(200, REPOS)
  43. }