From 3f3d9017623218a4d4e883a5e71d3e49911f285a Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 14 Nov 2021 20:16:54 +0100 Subject: [PATCH] Add pagination to fork list - Resolves #14574 - Adds the necessary code to have pagination workin in the forks list of a repo. The code is mostly in par with the stars/watcher implementation. --- routers/web/repo/view.go | 15 +++++++++++++-- templates/repo/forks.tmpl | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index cecd8437b6962..7a06e44428dd0 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -909,8 +909,18 @@ func Stars(ctx *context.Context) { func Forks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repos.forks") - // TODO: need pagination - forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{}) + page := ctx.FormInt("page") + if page <= 0 { + page = 1 + } + + pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5) + ctx.Data["Page"] = pager + + forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{ + Page: pager.Paginater.Current(), + PageSize: models.ItemsPerPage, + }) if err != nil { ctx.ServerError("GetForks", err) return @@ -922,6 +932,7 @@ func Forks(ctx *context.Context) { return } } + ctx.Data["Forks"] = forks ctx.HTML(http.StatusOK, tplForks) diff --git a/templates/repo/forks.tmpl b/templates/repo/forks.tmpl index 192291275f34a..d8ad82c64286f 100644 --- a/templates/repo/forks.tmpl +++ b/templates/repo/forks.tmpl @@ -18,5 +18,7 @@ {{end}} + + {{ template "base/paginate" . }} {{template "base/footer" .}}