From 86fb1a0cb13de00a5ba49e29efa35573c01c9821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Fri, 4 Nov 2016 20:28:07 +0100 Subject: [PATCH] Add Pagination to Releases-page --- models/release.go | 7 +++++-- routers/repo/release.go | 9 ++++++++- templates/repo/release/list.tmpl | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models/release.go b/models/release.go index 0e1edd121..4841ae7ba 100644 --- a/models/release.go +++ b/models/release.go @@ -138,8 +138,11 @@ func GetReleaseByID(id int64) (*Release, error) { } // GetReleasesByRepoID returns a list of releases of repository. -func GetReleasesByRepoID(repoID int64) (rels []*Release, err error) { - err = x.Desc("created_unix").Find(&rels, Release{RepoID: repoID}) +func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) { + if page <= 0 { + page = 1 + } + err = x.Desc("created_unix").Limit(pageSize, (page-1)*pageSize).Find(&rels, Release{RepoID: repoID}) return rels, err } diff --git a/routers/repo/release.go b/routers/repo/release.go index 9d87f0967..afdc61a22 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -7,6 +7,7 @@ package repo import ( "fmt" + "github.com/Unknwon/paginater" "github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/modules/auth" "github.com/go-gitea/gitea/modules/base" @@ -58,7 +59,11 @@ func Releases(ctx *context.Context) { return } - releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID) + page := ctx.QueryInt("page") + if page <= 1 { + page = 1 + } + releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, 10) if err != nil { ctx.Handle(500, "GetReleasesByRepoID", err) return @@ -141,6 +146,8 @@ func Releases(ctx *context.Context) { r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) tags = append(tags, r) } + pager := paginater.New(ctx.Repo.Repository.NumTags, 10, page, 5) + ctx.Data["Page"] = pager models.SortReleases(tags) ctx.Data["Releases"] = tags ctx.HTML(200, RELEASES) diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index b9b1b7c2f..c22897c51 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -75,6 +75,7 @@ {{end}} + {{template "admin/base/page" .}} {{template "base/footer" .}}