1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Add Pagination to Releases-page

This commit is contained in:
Kim "BKC" Carlbäcker 2016-11-04 20:28:07 +01:00
parent be5607e510
commit 86fb1a0cb1
3 changed files with 14 additions and 3 deletions

View file

@ -138,8 +138,11 @@ func GetReleaseByID(id int64) (*Release, error) {
} }
// GetReleasesByRepoID returns a list of releases of repository. // GetReleasesByRepoID returns a list of releases of repository.
func GetReleasesByRepoID(repoID int64) (rels []*Release, err error) { func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) {
err = x.Desc("created_unix").Find(&rels, Release{RepoID: repoID}) if page <= 0 {
page = 1
}
err = x.Desc("created_unix").Limit(pageSize, (page-1)*pageSize).Find(&rels, Release{RepoID: repoID})
return rels, err return rels, err
} }

View file

@ -7,6 +7,7 @@ package repo
import ( import (
"fmt" "fmt"
"github.com/Unknwon/paginater"
"github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/models"
"github.com/go-gitea/gitea/modules/auth" "github.com/go-gitea/gitea/modules/auth"
"github.com/go-gitea/gitea/modules/base" "github.com/go-gitea/gitea/modules/base"
@ -58,7 +59,11 @@ func Releases(ctx *context.Context) {
return 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 { if err != nil {
ctx.Handle(500, "GetReleasesByRepoID", err) ctx.Handle(500, "GetReleasesByRepoID", err)
return return
@ -141,6 +146,8 @@ func Releases(ctx *context.Context) {
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
tags = append(tags, r) tags = append(tags, r)
} }
pager := paginater.New(ctx.Repo.Repository.NumTags, 10, page, 5)
ctx.Data["Page"] = pager
models.SortReleases(tags) models.SortReleases(tags)
ctx.Data["Releases"] = tags ctx.Data["Releases"] = tags
ctx.HTML(200, RELEASES) ctx.HTML(200, RELEASES)

View file

@ -75,6 +75,7 @@
</li> </li>
{{end}} {{end}}
</ul> </ul>
{{template "admin/base/page" .}}
</div> </div>
</div> </div>
{{template "base/footer" .}} {{template "base/footer" .}}