Skip to content

Commit 5667d4d

Browse files
authored
Merge pull request #73 from bkcsoft/gt/2164-release-pagination
Add Pagination to Releases-page (and de-duplicate pagination templates)
2 parents 864d1b1 + 562f9b6 commit 5667d4d

File tree

13 files changed

+25
-35
lines changed

13 files changed

+25
-35
lines changed

models/release.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ func GetReleaseByID(id int64) (*Release, error) {
138138
}
139139

140140
// GetReleasesByRepoID returns a list of releases of repository.
141-
func GetReleasesByRepoID(repoID int64) (rels []*Release, err error) {
142-
err = x.Desc("created_unix").Find(&rels, Release{RepoID: repoID})
141+
func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) {
142+
if page <= 0 {
143+
page = 1
144+
}
145+
err = x.Desc("created_unix").Limit(pageSize, (page-1)*pageSize).Find(&rels, Release{RepoID: repoID})
143146
return rels, err
144147
}
145148

routers/repo/release.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package repo
77
import (
88
"fmt"
99

10+
"github.com/Unknwon/paginater"
1011
"github.com/go-gitea/gitea/models"
1112
"github.com/go-gitea/gitea/modules/auth"
1213
"github.com/go-gitea/gitea/modules/base"
@@ -58,7 +59,11 @@ func Releases(ctx *context.Context) {
5859
return
5960
}
6061

61-
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID)
62+
page := ctx.QueryInt("page")
63+
if page <= 1 {
64+
page = 1
65+
}
66+
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, 10)
6267
if err != nil {
6368
ctx.Handle(500, "GetReleasesByRepoID", err)
6469
return
@@ -141,6 +146,8 @@ func Releases(ctx *context.Context) {
141146
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
142147
tags = append(tags, r)
143148
}
149+
pager := paginater.New(ctx.Repo.Repository.NumTags, 10, page, 5)
150+
ctx.Data["Page"] = pager
144151
models.SortReleases(tags)
145152
ctx.Data["Releases"] = tags
146153
ctx.HTML(200, RELEASES)

templates/admin/base/page.tmpl

Lines changed: 0 additions & 23 deletions
This file was deleted.

templates/admin/org/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</table>
4141
</div>
4242

43-
{{template "admin/base/page" .}}
43+
{{template "base/paginate" .}}
4444
</div>
4545
</div>
4646
</div>

templates/admin/repo/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</table>
4545
</div>
4646

47-
{{template "admin/base/page" .}}
47+
{{template "base/paginage" .}}
4848
</div>
4949
</div>
5050
</div>

templates/admin/user/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</table>
4646
</div>
4747

48-
{{template "admin/base/page" .}}
48+
{{template "base/paginate" .}}
4949
</div>
5050
</div>
5151
</div>

templates/explore/page.tmpl renamed to templates/base/paginate.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{if gt .TotalPages 1}}
33
<div class="center page buttons">
44
<div class="ui borderless pagination menu">
5+
<a class="{{if .IsFirst}}disabled{{end}} item" href="{{$.Link}}?q={{$.Keyword}}"><i class="angle double left icon"></i> {{$.i18n.Tr "admin.first_page"}}</a>
56
<a class="{{if not .HasPrevious}}disabled{{end}} item" {{if .HasPrevious}}href="{{$.Link}}?page={{.Previous}}&q={{$.Keyword}}"{{end}}>
67
<i class="left arrow icon"></i> {{$.i18n.Tr "repo.issues.previous"}}
78
</a>
@@ -13,8 +14,9 @@
1314
{{end}}
1415
{{end}}
1516
<a class="{{if not .HasNext}}disabled{{end}} item" {{if .HasNext}}href="{{$.Link}}?page={{.Next}}&q={{$.Keyword}}"{{end}}>
16-
{{$.i18n.Tr "repo.issues.next"}} <i class="icon right arrow"></i>
17+
{{$.i18n.Tr "repo.issues.next"}}&nbsp;<i class="icon right arrow"></i>
1718
</a>
19+
<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>
1820
</div>
1921
</div>
2022
{{end}}

templates/explore/organizations.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{end}}
2828
</div>
2929

30-
{{template "explore/page" .}}
30+
{{template "base/paginate" .}}
3131
</div>
3232
</div>
3333
</div>

templates/explore/repos.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="twelve wide column content">
77
{{template "explore/search" .}}
88
{{template "explore/repo_list" .}}
9-
{{template "explore/page" .}}
9+
{{template "base/paginate" .}}
1010
</div>
1111
</div>
1212
</div>

templates/explore/users.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{end}}
2828
</div>
2929

30-
{{template "explore/page" .}}
30+
{{template "base/paginate" .}}
3131
</div>
3232
</div>
3333
</div>

templates/org/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<div class="ui divider"></div>
3333
{{end}}
3434
{{template "explore/repo_list" .}}
35-
{{template "explore/page" .}}
35+
{{template "base/paginate" .}}
3636
</div>
3737

3838
<div class="ui five wide column">

templates/repo/release/list.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</li>
7676
{{end}}
7777
</ul>
78+
{{template "base/paginage" .}}
7879
</div>
7980
</div>
8081
{{template "base/footer" .}}

templates/user/profile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</div>
8787
{{if ne .TabName "activity"}}
8888
{{template "explore/repo_list" .}}
89-
{{template "explore/page" .}}
89+
{{template "base/paginate" .}}
9090
{{else}}
9191
<br>
9292
<div class="feeds">

0 commit comments

Comments
 (0)