diff --git a/conf/app.ini b/conf/app.ini index f767be551864..1ea4bf68da1f 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -21,6 +21,8 @@ ISSUE_PAGING_NUM = 10 [ui.admin] ; Number of users that are showed in one page USER_PAGING_NUM = 50 +; Number of repos that are showed in one page +REPO_PAGING_NUM = 50 ; Number of notices that are showed in one page NOTICE_PAGING_NUM = 50 ; Number of organization that are showed in one page diff --git a/models/repo.go b/models/repo.go index 8b80533813b2..c05c0098f272 100644 --- a/models/repo.go +++ b/models/repo.go @@ -775,15 +775,13 @@ func CountRepositories() int64 { func CountPublicRepositories() int64 { return countRepositories(false) } - -// GetRepositoriesWithUsers returns given number of repository objects with offset. -// It also auto-gets corresponding users. -func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) { - repos := make([]*Repository, 0, num) - if err := x.Limit(num, offset).Asc("id").Find(&repos); err != nil { +// RepositoriesWithUsers returns number of repos in given page. +func RepositoriesWithUsers(page, pageSize int) ([]*Repository, error) { + repos := make([]*Repository, 0, pageSize) + if err := x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos); err != nil { return nil, err } - + for _, repo := range repos { repo.Owner = &User{Id: repo.OwnerID} has, err := x.Get(repo.Owner) @@ -795,6 +793,7 @@ func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) { } return repos, nil + } // RepoPath returns repository path by given user and repository name. diff --git a/modules/setting/setting.go b/modules/setting/setting.go index e004b35b4708..23c41b6e9245 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -94,6 +94,7 @@ var ( ExplorePagingNum int IssuePagingNum int AdminUserPagingNum int + AdminRepoPagingNum int AdminNoticePagingNum int AdminOrgPagingNum int @@ -372,6 +373,7 @@ func NewContext() { sec = Cfg.Section("ui.admin") AdminUserPagingNum = sec.Key("USER_PAGING_NUM").MustInt(50) + AdminRepoPagingNum = sec.Key("REPO_PAGING_NUM").MustInt(50) AdminNoticePagingNum = sec.Key("NOTICE_PAGING_NUM").MustInt(50) AdminOrgPagingNum = sec.Key("ORG_PAGING_NUM").MustInt(50) diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 3f638871399f..d1d97b279b66 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -5,17 +5,20 @@ package admin import ( + "github.com/Unknwon/paginater" "math" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( REPOS base.TplName = "admin/repo/list" ) +//* TODO Remove after general using of github.com/Unknwon/paginater func pagination(ctx *middleware.Context, count int64, pageNum int) int { p := ctx.QueryInt("p") if p < 1 { @@ -33,19 +36,28 @@ func pagination(ctx *middleware.Context, count int64, pageNum int) int { return p } +//*/ func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.repositories") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRepositories"] = true - pageNum := 50 - p := pagination(ctx, models.CountRepositories(), pageNum) + total := models.CountRepositories() + page := ctx.QueryInt("page") + if page <= 1 { + page = 1 + } + ctx.Data["Page"] = paginater.New(int(total), setting.AdminRepoPagingNum, page, 5) + + repos, err := models.RepositoriesWithUsers(page, setting.AdminRepoPagingNum) - var err error - ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum) if err != nil { - ctx.Handle(500, "GetRepositoriesWithUsers", err) + ctx.Handle(500, "RepositoriesWithUsers", err) return } + + ctx.Data["Repos"] = repos + ctx.Data["Total"] = total + ctx.HTML(200, REPOS) } diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 5747ccecd205..e350ad8f8600 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -1,60 +1,70 @@ -{{template "ng/base/head" .}} -{{template "ng/base/header" .}} -
-
-
- {{template "admin/nav" .}} -
-
- {{template "ng/base/alert" .}} -
-
-
- {{.i18n.Tr "admin.repos.repo_manage_panel"}} -
-
-
- - - - - - - - - - - - - - - {{range .Repos}} - - - - - - - - - - - {{end}} - -
ID{{.i18n.Tr "admin.repos.owner"}}{{.i18n.Tr "admin.repos.name"}}{{.i18n.Tr "admin.repos.private"}}{{.i18n.Tr "admin.repos.watches"}}{{.i18n.Tr "admin.repos.stars"}}{{.i18n.Tr "admin.repos.issues"}}{{.i18n.Tr "admin.users.created"}}
{{.ID}}{{.Owner.Name}}{{.Name}}{{.NumWatches}}{{.NumStars}}{{.NumIssues}}{{DateFmtShort .Created}}
- {{if or .LastPageNum .NextPageNum}} -
    - {{if .LastPageNum}}
  • « Prev.
  • {{end}} - {{if .NextPageNum}}
  • » Next
  • {{end}} -
- {{end}} -
-
-
-
-
-
-
+{{template "base/head" .}} +
+
+
+ {{template "admin/navbar" .}} +
+ {{template "base/alert" .}} +

+ {{.i18n.Tr "admin.repos.repo_manage_panel"}} ({{.i18n.Tr "admin.total" .Total}}) +

+
+ + + + + + + + + + + + + + + {{range .Repos}} + + + + + + + + + + + {{end}} + +
ID{{.i18n.Tr "admin.repos.owner"}}{{.i18n.Tr "admin.repos.name"}}{{.i18n.Tr "admin.repos.private"}}{{.i18n.Tr "admin.repos.watches"}}{{.i18n.Tr "admin.repos.stars"}}{{.i18n.Tr "admin.repos.issues"}}{{.i18n.Tr "admin.users.created"}}
{{.ID}}{{.Owner.Name}}{{.Name}}{{.NumWatches}}{{.NumStars}}{{.NumIssues}}{{DateFmtShort .Created}}
+
+ + {{with .Page}} + {{if gt .TotalPages 1}} + + {{end}} + {{end}} + +
+
-{{template "ng/base/footer" .}} +{{template "base/footer" .}} \ No newline at end of file