From dfc16d08790f446e321df24c01ae2800507e2a22 Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Sat, 26 Sep 2015 00:38:43 +0200 Subject: [PATCH] Fix admin repos new ui --- conf/app.ini | 2 + models/repo.go | 13 ++-- modules/setting/setting.go | 2 + routers/admin/repos.go | 22 ++++-- templates/admin/repo/list.tmpl | 126 ++++++++++++++++++--------------- 5 files changed, 95 insertions(+), 70 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 21464edd0f..049e6d860b 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 diff --git a/models/repo.go b/models/repo.go index 8b80533813..c05c0098f2 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 1d6bf4d62b..23f54fadda 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 // Markdown sttings. @@ -371,6 +372,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) sec = Cfg.Section("picture") diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 3f63887139..d1d97b279b 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 5747ccecd2..e350ad8f86 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