Skip to content

Commit

Permalink
Merge pull request #73 from bkcsoft/gt/2164-release-pagination
Browse files Browse the repository at this point in the history
Add Pagination to Releases-page (and de-duplicate pagination templates)
  • Loading branch information
lunny committed Nov 8, 2016
2 parents 864d1b1 + 562f9b6 commit 5667d4d
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 35 deletions.
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/go-gitea/gitea/models"
"github.com/go-gitea/gitea/modules/auth"
"github.com/go-gitea/gitea/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
23 changes: 0 additions & 23 deletions templates/admin/base/page.tmpl

This file was deleted.

2 changes: 1 addition & 1 deletion templates/admin/org/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</table>
</div>

{{template "admin/base/page" .}}
{{template "base/paginate" .}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/repo/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</table>
</div>

{{template "admin/base/page" .}}
{{template "base/paginage" .}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/user/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</table>
</div>

{{template "admin/base/page" .}}
{{template "base/paginate" .}}
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion templates/explore/page.tmpl → templates/base/paginate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{if gt .TotalPages 1}}
<div class="center page buttons">
<div class="ui borderless pagination menu">
<a class="{{if .IsFirst}}disabled{{end}} item" href="{{$.Link}}?q={{$.Keyword}}"><i class="angle double left icon"></i> {{$.i18n.Tr "admin.first_page"}}</a>
<a class="{{if not .HasPrevious}}disabled{{end}} item" {{if .HasPrevious}}href="{{$.Link}}?page={{.Previous}}&q={{$.Keyword}}"{{end}}>
<i class="left arrow icon"></i> {{$.i18n.Tr "repo.issues.previous"}}
</a>
Expand All @@ -13,8 +14,9 @@
{{end}}
{{end}}
<a class="{{if not .HasNext}}disabled{{end}} item" {{if .HasNext}}href="{{$.Link}}?page={{.Next}}&q={{$.Keyword}}"{{end}}>
{{$.i18n.Tr "repo.issues.next"}} <i class="icon right arrow"></i>
{{$.i18n.Tr "repo.issues.next"}}&nbsp;<i class="icon right arrow"></i>
</a>
<a class="{{if .IsLast}}disabled{{end}} item" href="{{$.Link}}?page={{.TotalPages}}&q={{$.Keyword}}">{{$.i18n.Tr "admin.last_page"}}&nbsp;<i class="angle double right icon"></i></a>
</div>
</div>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/explore/organizations.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{{end}}
</div>

{{template "explore/page" .}}
{{template "base/paginate" .}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/explore/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="twelve wide column content">
{{template "explore/search" .}}
{{template "explore/repo_list" .}}
{{template "explore/page" .}}
{{template "base/paginate" .}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/explore/users.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{{end}}
</div>

{{template "explore/page" .}}
{{template "base/paginate" .}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="ui divider"></div>
{{end}}
{{template "explore/repo_list" .}}
{{template "explore/page" .}}
{{template "base/paginate" .}}
</div>

<div class="ui five wide column">
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 "base/paginage" .}}
</div>
</div>
{{template "base/footer" .}}
2 changes: 1 addition & 1 deletion templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</div>
{{if ne .TabName "activity"}}
{{template "explore/repo_list" .}}
{{template "explore/page" .}}
{{template "base/paginate" .}}
{{else}}
<br>
<div class="feeds">
Expand Down

0 comments on commit 5667d4d

Please sign in to comment.