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 Releases-page (and de-duplicate pagination templates) #73

Merged
merged 2 commits into from
Nov 8, 2016
Merged
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/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