diff options
author | Unknwon <u@gogs.io> | 2015-11-16 23:28:46 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-16 23:28:46 -0500 |
commit | 9ab96172fc41c5a10f88045d6a19e83641e3b859 (patch) | |
tree | 9bf80165cadf7d63dc942a4241740c8c0656462e /routers/repo | |
parent | e06558e2083e6281500cc1c91ac54425b91390fe (diff) | |
download | gitea-9ab96172fc41c5a10f88045d6a19e83641e3b859.tar.gz gitea-9ab96172fc41c5a10f88045d6a19e83641e3b859.zip |
new watchers, stars and forks UI
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/stars.go | 44 | ||||
-rw-r--r-- | routers/repo/view.go | 35 | ||||
-rw-r--r-- | routers/repo/watchers.go | 44 |
3 files changed, 34 insertions, 89 deletions
diff --git a/routers/repo/stars.go b/routers/repo/stars.go deleted file mode 100644 index 93854886c0..0000000000 --- a/routers/repo/stars.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package repo - -import ( - "github.com/Unknwon/paginater" - - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/middleware" -) - -const ( - STARS base.TplName = "repo/stars" -) - -func Stars(ctx *middleware.Context) { - ctx.Data["Title"] = ctx.Tr("repos.stars") - - page := ctx.QueryInt("page") - if page <= 0 { - page = 1 - } - - ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5) - - stars, err := ctx.Repo.Repository.GetStars(ctx.QueryInt("page")) - - if err != nil { - ctx.Handle(500, "GetStars", err) - return - } - - if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars { - ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil) - return - } - - ctx.Data["Stars"] = stars - - ctx.HTML(200, STARS) -} diff --git a/routers/repo/view.go b/routers/repo/view.go index e9cb7b3390..8c62b7e4a0 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -11,6 +11,8 @@ import ( "path/filepath" "strings" + "github.com/Unknwon/paginater" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" @@ -20,7 +22,8 @@ import ( ) const ( - HOME base.TplName = "repo/home" + HOME base.TplName = "repo/home" + WATCHERS base.TplName = "repo/watchers" ) func Home(ctx *middleware.Context) { @@ -245,3 +248,33 @@ func Home(ctx *middleware.Context) { ctx.Data["BranchLink"] = branchLink ctx.HTML(200, HOME) } + +func renderItems(ctx *middleware.Context, total int, getter func(page int) ([]*models.User, error)) { + page := ctx.QueryInt("page") + if page <= 0 { + page = 1 + } + pager := paginater.New(total, models.ItemsPerPage, page, 5) + ctx.Data["Page"] = pager + + items, err := getter(pager.Current()) + if err != nil { + ctx.Handle(500, "getter", err) + return + } + ctx.Data["Watchers"] = items + + ctx.HTML(200, WATCHERS) +} + +func Watchers(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.watchers") + ctx.Data["PageIsWatchers"] = true + renderItems(ctx, ctx.Repo.Repository.NumWatches, ctx.Repo.Repository.GetWatchers) +} + +func Stars(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.stargazers") + ctx.Data["PageIsStargazers"] = true + renderItems(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers) +} diff --git a/routers/repo/watchers.go b/routers/repo/watchers.go deleted file mode 100644 index 8626fa2371..0000000000 --- a/routers/repo/watchers.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package repo - -import ( - "github.com/Unknwon/paginater" - - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/middleware" -) - -const ( - WATCHERS base.TplName = "repo/watchers" -) - -func Watchers(ctx *middleware.Context) { - ctx.Data["Title"] = ctx.Tr("repos.watches") - - page := ctx.QueryInt("page") - if page <= 0 { - page = 1 - } - - ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumWatches, models.ItemsPerPage, page, 5) - - watchers, err := ctx.Repo.Repository.GetWatchers(ctx.QueryInt("page")) - - if err != nil { - ctx.Handle(500, "GetWatchers", err) - return - } - - if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumWatches { - ctx.Handle(404, "ctx.Repo.Repository.NumWatches", nil) - return - } - - ctx.Data["Watchers"] = watchers - - ctx.HTML(200, WATCHERS) -} |