Skip to content

Commit 3f3d901

Browse files
author
Gusted
committed
Add pagination to fork list
- Resolves go-gitea#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.
1 parent d2163df commit 3f3d901

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
@@ -909,8 +909,18 @@ func Stars(ctx *context.Context) {
909909
func Forks(ctx *context.Context) {
910910
ctx.Data["Title"] = ctx.Tr("repos.forks")
911911

912-
// TODO: need pagination
913-
forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{})
912+
page := ctx.FormInt("page")
913+
if page <= 0 {
914+
page = 1
915+
}
916+
917+
pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5)
918+
ctx.Data["Page"] = pager
919+
920+
forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{
921+
Page: pager.Paginater.Current(),
922+
PageSize: models.ItemsPerPage,
923+
})
914924
if err != nil {
915925
ctx.ServerError("GetForks", err)
916926
return
@@ -922,6 +932,7 @@ func Forks(ctx *context.Context) {
922932
return
923933
}
924934
}
935+
925936
ctx.Data["Forks"] = forks
926937

927938
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)