From 86fb1a0cb13de00a5ba49e29efa35573c01c9821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Fri, 4 Nov 2016 20:28:07 +0100 Subject: [PATCH 1/2] Add Pagination to Releases-page --- models/release.go | 7 +++++-- routers/repo/release.go | 9 ++++++++- templates/repo/release/list.tmpl | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models/release.go b/models/release.go index 0e1edd121b2e..4841ae7ba3b5 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 9d87f0967e0a..afdc61a22a67 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/repo/release/list.tmpl b/templates/repo/release/list.tmpl index b9b1b7c2f46b..c22897c51ebb 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -75,6 +75,7 @@ {{end}} + {{template "admin/base/page" .}} {{template "base/footer" .}} From 562f9b6eae72e3f952a2ce1e74249bcd44e69272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Mon, 7 Nov 2016 11:44:49 +0100 Subject: [PATCH 2/2] Merge all pagination-templates into 'base/paginate' to reduce code-duplicity --- templates/admin/base/page.tmpl | 23 ------------------- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/admin/user/list.tmpl | 2 +- .../{explore/page.tmpl => base/paginate.tmpl} | 4 +++- templates/explore/organizations.tmpl | 2 +- templates/explore/repos.tmpl | 2 +- templates/explore/users.tmpl | 2 +- templates/org/home.tmpl | 2 +- templates/repo/release/list.tmpl | 2 +- templates/user/profile.tmpl | 2 +- 11 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 templates/admin/base/page.tmpl rename templates/{explore/page.tmpl => base/paginate.tmpl} (64%) diff --git a/templates/admin/base/page.tmpl b/templates/admin/base/page.tmpl deleted file mode 100644 index 564d7dec340d..000000000000 --- a/templates/admin/base/page.tmpl +++ /dev/null @@ -1,23 +0,0 @@ - {{with .Page}} - {{if gt .TotalPages 1}} - - {{end}} - {{end}} diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 6b9423d03e57..244f915c974e 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -40,7 +40,7 @@ - {{template "admin/base/page" .}} + {{template "base/paginate" .}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 4b1d98b94b92..8db51489d7c1 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -44,7 +44,7 @@ - {{template "admin/base/page" .}} + {{template "base/paginage" .}} diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 8c7a0c9a905d..f1ebf4a3406b 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -45,7 +45,7 @@ - {{template "admin/base/page" .}} + {{template "base/paginate" .}} diff --git a/templates/explore/page.tmpl b/templates/base/paginate.tmpl similarity index 64% rename from templates/explore/page.tmpl rename to templates/base/paginate.tmpl index fd3e7a7a82d2..afe34c632f10 100644 --- a/templates/explore/page.tmpl +++ b/templates/base/paginate.tmpl @@ -2,6 +2,7 @@ {{if gt .TotalPages 1}} {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 6953414e8512..c44456be4c70 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -27,7 +27,7 @@ {{end}} - {{template "explore/page" .}} + {{template "base/paginate" .}} diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index 080a5076f110..eac3f1d26ca6 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -6,7 +6,7 @@
{{template "explore/search" .}} {{template "explore/repo_list" .}} - {{template "explore/page" .}} + {{template "base/paginate" .}}
diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl index c13ccc697715..ce356f4fdebb 100644 --- a/templates/explore/users.tmpl +++ b/templates/explore/users.tmpl @@ -27,7 +27,7 @@ {{end}} - {{template "explore/page" .}} + {{template "base/paginate" .}} diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 17b0ade8c997..69de8d348101 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -32,7 +32,7 @@
{{end}} {{template "explore/repo_list" .}} - {{template "explore/page" .}} + {{template "base/paginate" .}}
diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index c22897c51ebb..477ab6b5243c 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -75,7 +75,7 @@ {{end}} - {{template "admin/base/page" .}} + {{template "base/paginage" .}}
{{template "base/footer" .}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 4bcc92d95d50..a7edd88c6dcd 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -86,7 +86,7 @@ {{if ne .TabName "activity"}} {{template "explore/repo_list" .}} - {{template "explore/page" .}} + {{template "base/paginate" .}} {{else}}