Pagination on releases page (#2035)

* Added count to GetReleasesByRepoID so pagination will work

* Separated it out to a new function, can then also leave the API part unaffected

* Remove extra whitespace added in untouched function

* Added comment and corrected name in error handler

* Account for if the user is owner or not in the count

* Also check if repo is draft

* revert back to the correct count in the ReleasesToDisplay loop

* Fixed lint error regarding else with return statement

* Use Cond struct instead of string, corrected name in error handler

* Removed unused return variable names
This commit is contained in:
iszla 2017-06-28 16:47:00 +02:00 committed by Lunny Xiao
parent 1f4d84b7b2
commit 3f9016430f
2 changed files with 22 additions and 2 deletions

View file

@ -67,7 +67,13 @@ func Releases(ctx *context.Context) {
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, limit)
if err != nil {
ctx.Handle(500, "GetReleasesByRepoIDAndNames", err)
ctx.Handle(500, "GetReleasesByRepoID", err)
return
}
count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, ctx.Repo.IsOwner())
if err != nil {
ctx.Handle(500, "GetReleaseCountByRepoID", err)
return
}
@ -110,7 +116,7 @@ func Releases(ctx *context.Context) {
releasesToDisplay = append(releasesToDisplay, r)
}
pager := paginater.New(len(releasesToDisplay), limit, page, 5)
pager := paginater.New(int(count), limit, page, 5)
ctx.Data["Page"] = pager
ctx.Data["Releases"] = releasesToDisplay
ctx.HTML(200, tplReleases)