Skip to content

Commit

Permalink
Add pagination to fork list
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Gusted committed Nov 14, 2021
1 parent d2163df commit 3f3d901
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -922,6 +932,7 @@ func Forks(ctx *context.Context) {
return
}
}

ctx.Data["Forks"] = forks

ctx.HTML(http.StatusOK, tplForks)
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/forks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
{{end}}
</div>
</div>

{{ template "base/paginate" . }}
</div>
{{template "base/footer" .}}

0 comments on commit 3f3d901

Please sign in to comment.