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 release-page #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package repo
import (
"fmt"

"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions templates/repo/release/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</li>
{{end}}
</ul>
{{template "admin/base/page" .}}
</div>
</div>
{{template "base/footer" .}}