diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2016-11-08 10:39:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-08 10:39:03 +0800 |
commit | 5667d4daae2df8c648d3c30cd7f6aadd5cb0e698 (patch) | |
tree | 24b739896a721abb794a9a9bc0a97ea16c25ed79 | |
parent | 864d1b1f9f6a72589d77ec0f08b21c476b8e13d4 (diff) | |
parent | 562f9b6eae72e3f952a2ce1e74249bcd44e69272 (diff) | |
download | gitea-5667d4daae2df8c648d3c30cd7f6aadd5cb0e698.tar.gz gitea-5667d4daae2df8c648d3c30cd7f6aadd5cb0e698.zip |
Merge pull request #73 from bkcsoft/gt/2164-release-pagination
Add Pagination to Releases-page (and de-duplicate pagination templates)
-rw-r--r-- | models/release.go | 7 | ||||
-rw-r--r-- | routers/repo/release.go | 9 | ||||
-rw-r--r-- | templates/admin/base/page.tmpl | 23 | ||||
-rw-r--r-- | templates/admin/org/list.tmpl | 2 | ||||
-rw-r--r-- | templates/admin/repo/list.tmpl | 2 | ||||
-rw-r--r-- | templates/admin/user/list.tmpl | 2 | ||||
-rw-r--r-- | templates/base/paginate.tmpl (renamed from templates/explore/page.tmpl) | 4 | ||||
-rw-r--r-- | templates/explore/organizations.tmpl | 2 | ||||
-rw-r--r-- | templates/explore/repos.tmpl | 2 | ||||
-rw-r--r-- | templates/explore/users.tmpl | 2 | ||||
-rw-r--r-- | templates/org/home.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/release/list.tmpl | 1 | ||||
-rw-r--r-- | templates/user/profile.tmpl | 2 |
13 files changed, 25 insertions, 35 deletions
diff --git a/models/release.go b/models/release.go index 0e1edd121b..4841ae7ba3 100644 --- a/models/release.go +++ b/models/release.go @@ -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 } diff --git a/routers/repo/release.go b/routers/repo/release.go index 9d87f0967e..afdc61a22a 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -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" @@ -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 @@ -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) diff --git a/templates/admin/base/page.tmpl b/templates/admin/base/page.tmpl deleted file mode 100644 index 564d7dec34..0000000000 --- a/templates/admin/base/page.tmpl +++ /dev/null @@ -1,23 +0,0 @@ - {{with .Page}} - {{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> - {{range .Pages}} - {{if eq .Num -1}} - <a class="disabled item">...</a> - {{else}} - <a class="{{if .IsCurrent}}active{{end}} item" {{if not .IsCurrent}}href="{{$.Link}}?page={{.Num}}&q={{$.Keyword}}"{{end}}>{{.Num}}</a> - {{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> - </a> - <a class="{{if .IsLast}}disabled{{end}} item" href="{{$.Link}}?page={{.TotalPages}}&q={{$.Keyword}}">{{$.i18n.Tr "admin.last_page"}} <i class="angle double right icon"></i></a> - </div> - </div> - {{end}} - {{end}} diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 6b9423d03e..244f915c97 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -40,7 +40,7 @@ </table> </div> - {{template "admin/base/page" .}} + {{template "base/paginate" .}} </div> </div> </div> diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 4b1d98b94b..8db51489d7 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -44,7 +44,7 @@ </table> </div> - {{template "admin/base/page" .}} + {{template "base/paginage" .}} </div> </div> </div> diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 8c7a0c9a90..f1ebf4a340 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -45,7 +45,7 @@ </table> </div> - {{template "admin/base/page" .}} + {{template "base/paginate" .}} </div> </div> </div> diff --git a/templates/explore/page.tmpl b/templates/base/paginate.tmpl index fd3e7a7a82..afe34c632f 100644 --- a/templates/explore/page.tmpl +++ b/templates/base/paginate.tmpl @@ -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> @@ -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"}} <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"}} <i class="angle double right icon"></i></a> </div> </div> {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 6953414e85..c44456be4c 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -27,7 +27,7 @@ {{end}} </div> - {{template "explore/page" .}} + {{template "base/paginate" .}} </div> </div> </div> diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index 080a5076f1..eac3f1d26c 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -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> diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl index c13ccc6977..ce356f4fde 100644 --- a/templates/explore/users.tmpl +++ b/templates/explore/users.tmpl @@ -27,7 +27,7 @@ {{end}} </div> - {{template "explore/page" .}} + {{template "base/paginate" .}} </div> </div> </div> diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 17b0ade8c9..69de8d3481 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -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"> diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index b9b1b7c2f4..477ab6b524 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -75,6 +75,7 @@ </li> {{end}} </ul> + {{template "base/paginage" .}} </div> </div> {{template "base/footer" .}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 4bcc92d95d..a7edd88c6d 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -86,7 +86,7 @@ </div> {{if ne .TabName "activity"}} {{template "explore/repo_list" .}} - {{template "explore/page" .}} + {{template "base/paginate" .}} {{else}} <br> <div class="feeds"> |