]> source.dussan.org Git - gitea.git/commitdiff
Add pagination to fork list (#17639)
authorGusted <williamzijl7@hotmail.com>
Thu, 18 Nov 2021 14:45:56 +0000 (14:45 +0000)
committerGitHub <noreply@github.com>
Thu, 18 Nov 2021 14:45:56 +0000 (22:45 +0800)
- Resolves #14574
- Adds the necessary code to have pagination working in the forks list of
a repo. The code is mostly in par with the stars/watcher implementation.

routers/web/repo/view.go
templates/repo/forks.tmpl

index d455dc1039a34a24dded5c42a3a25978c6ee2645..72726f0545f02c07b8c17b7c6717fb565b355bad 100644 (file)
@@ -935,8 +935,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
@@ -948,6 +958,7 @@ func Forks(ctx *context.Context) {
                        return
                }
        }
+
        ctx.Data["Forks"] = forks
 
        ctx.HTML(http.StatusOK, tplForks)
index ff6e9949d35b7ead671112bcb5f644ef4c7df6f1..d28dc0aff8524f34ace5ad426215783fdeb87b37 100644 (file)
@@ -18,5 +18,7 @@
                        {{end}}
                </div>
        </div>
+
+       {{ template "base/paginate" . }}
 </div>
 {{template "base/footer" .}}