Skip to content

Commit 86fb1a0

Browse files
committed
Add Pagination to Releases-page
1 parent be5607e commit 86fb1a0

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

models/release.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ func GetReleaseByID(id int64) (*Release, error) {
138138
}
139139

140140
// GetReleasesByRepoID returns a list of releases of repository.
141-
func GetReleasesByRepoID(repoID int64) (rels []*Release, err error) {
142-
err = x.Desc("created_unix").Find(&rels, Release{RepoID: repoID})
141+
func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) {
142+
if page <= 0 {
143+
page = 1
144+
}
145+
err = x.Desc("created_unix").Limit(pageSize, (page-1)*pageSize).Find(&rels, Release{RepoID: repoID})
143146
return rels, err
144147
}
145148

routers/repo/release.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package repo
77
import (
88
"fmt"
99

10+
"github.com/Unknwon/paginater"
1011
"github.com/go-gitea/gitea/models"
1112
"github.com/go-gitea/gitea/modules/auth"
1213
"github.com/go-gitea/gitea/modules/base"
@@ -58,7 +59,11 @@ func Releases(ctx *context.Context) {
5859
return
5960
}
6061

61-
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID)
62+
page := ctx.QueryInt("page")
63+
if page <= 1 {
64+
page = 1
65+
}
66+
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, 10)
6267
if err != nil {
6368
ctx.Handle(500, "GetReleasesByRepoID", err)
6469
return
@@ -141,6 +146,8 @@ func Releases(ctx *context.Context) {
141146
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
142147
tags = append(tags, r)
143148
}
149+
pager := paginater.New(ctx.Repo.Repository.NumTags, 10, page, 5)
150+
ctx.Data["Page"] = pager
144151
models.SortReleases(tags)
145152
ctx.Data["Releases"] = tags
146153
ctx.HTML(200, RELEASES)

templates/repo/release/list.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</li>
7676
{{end}}
7777
</ul>
78+
{{template "admin/base/page" .}}
7879
</div>
7980
</div>
8081
{{template "base/footer" .}}

0 commit comments

Comments
 (0)