repos.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. "github.com/Unknwon/paginater"
  7. "math"
  8. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/middleware"
  11. "github.com/gogits/gogs/modules/setting"
  12. )
  13. const (
  14. REPOS base.TplName = "admin/repo/list"
  15. )
  16. //* TODO Remove after general using of github.com/Unknwon/paginater
  17. func pagination(ctx *middleware.Context, count int64, pageNum int) int {
  18. p := ctx.QueryInt("p")
  19. if p < 1 {
  20. p = 1
  21. }
  22. curCount := int64((p-1)*pageNum + pageNum)
  23. if curCount >= count {
  24. p = int(math.Ceil(float64(count) / float64(pageNum)))
  25. } else {
  26. ctx.Data["NextPageNum"] = p + 1
  27. }
  28. if p > 1 {
  29. ctx.Data["LastPageNum"] = p - 1
  30. }
  31. return p
  32. }
  33. //*/
  34. func Repositories(ctx *middleware.Context) {
  35. ctx.Data["Title"] = ctx.Tr("admin.repositories")
  36. ctx.Data["PageIsAdmin"] = true
  37. ctx.Data["PageIsAdminRepositories"] = true
  38. total := models.CountRepositories()
  39. page := ctx.QueryInt("page")
  40. if page <= 1 {
  41. page = 1
  42. }
  43. ctx.Data["Page"] = paginater.New(int(total), setting.AdminRepoPagingNum, page, 5)
  44. repos, err := models.RepositoriesWithUsers(page, setting.AdminRepoPagingNum)
  45. if err != nil {
  46. ctx.Handle(500, "RepositoriesWithUsers", err)
  47. return
  48. }
  49. ctx.Data["Repos"] = repos
  50. ctx.Data["Total"] = total
  51. ctx.HTML(200, REPOS)
  52. }