Skip to content

Commit c3e020c

Browse files
author
Gusted
authored
Add pagination to fork list (#17639)
- 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.
1 parent 257b717 commit c3e020c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

routers/web/repo/view.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,18 @@ func Stars(ctx *context.Context) {
935935
func Forks(ctx *context.Context) {
936936
ctx.Data["Title"] = ctx.Tr("repos.forks")
937937

938-
// TODO: need pagination
939-
forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{})
938+
page := ctx.FormInt("page")
939+
if page <= 0 {
940+
page = 1
941+
}
942+
943+
pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5)
944+
ctx.Data["Page"] = pager
945+
946+
forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{
947+
Page: pager.Paginater.Current(),
948+
PageSize: models.ItemsPerPage,
949+
})
940950
if err != nil {
941951
ctx.ServerError("GetForks", err)
942952
return
@@ -948,6 +958,7 @@ func Forks(ctx *context.Context) {
948958
return
949959
}
950960
}
961+
951962
ctx.Data["Forks"] = forks
952963

953964
ctx.HTML(http.StatusOK, tplForks)

templates/repo/forks.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
{{end}}
1919
</div>
2020
</div>
21+
22+
{{ template "base/paginate" . }}
2123
</div>
2224
{{template "base/footer" .}}

0 commit comments

Comments
 (0)