Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to fork list #17639

Merged
merged 13 commits into from
Nov 18, 2021
15 changes: 13 additions & 2 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -948,6 +958,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" .}}