aboutsummaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-03-17 19:17:40 -0400
committerUnknwon <u@gogs.io>2017-03-17 19:17:40 -0400
commitcac7af2c783e12b68e8263b57a150d19f085f4da (patch)
tree102491e2450d81a414e464523768337c495e6f8c /routers
parent2d4dc544bea95239f620246610ccd9ed0a0ffd46 (diff)
explore: able list and search for private but accessible repositories (#3088)
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/repos.go53
-rw-r--r--routers/home.go81
2 files changed, 63 insertions, 71 deletions
diff --git a/routers/admin/repos.go b/routers/admin/repos.go
index 11448a3e..4f688a92 100644
--- a/routers/admin/repos.go
+++ b/routers/admin/repos.go
@@ -5,13 +5,13 @@
package admin
import (
+ "github.com/Unknwon/paginater"
log "gopkg.in/clog.v1"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
- "github.com/gogits/gogs/routers"
)
const (
@@ -23,14 +23,49 @@ func Repos(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminRepositories"] = true
- routers.RenderRepoSearch(ctx, &routers.RepoSearchOptions{
- Counter: models.CountRepositories,
- Ranger: models.Repositories,
- Private: true,
- PageSize: setting.UI.Admin.RepoPagingNum,
- OrderBy: "id ASC",
- TplName: REPOS,
- })
+ page := ctx.QueryInt("page")
+ if page <= 0 {
+ page = 1
+ }
+
+ var (
+ repos []*models.Repository
+ count int64
+ err error
+ )
+
+ keyword := ctx.Query("q")
+ if len(keyword) == 0 {
+ repos, err = models.Repositories(page, setting.UI.Admin.RepoPagingNum)
+ if err != nil {
+ ctx.Handle(500, "Repositories", err)
+ return
+ }
+ count = models.CountRepositories(true)
+ } else {
+ repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
+ Keyword: keyword,
+ OrderBy: "id ASC",
+ Private: true,
+ Page: page,
+ PageSize: setting.UI.Admin.RepoPagingNum,
+ })
+ if err != nil {
+ ctx.Handle(500, "SearchRepositoryByName", err)
+ return
+ }
+ }
+ ctx.Data["Keyword"] = keyword
+ ctx.Data["Total"] = count
+ ctx.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
+
+ if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+ ctx.Handle(500, "LoadAttributes", err)
+ return
+ }
+ ctx.Data["Repos"] = repos
+
+ ctx.HTML(200, REPOS)
}
func DeleteRepo(ctx *context.Context) {
diff --git a/routers/home.go b/routers/home.go
index 3c1aa6d5..b928bc60 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -5,8 +5,6 @@
package routers
import (
- "fmt"
-
"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models"
@@ -45,80 +43,39 @@ func Home(ctx *context.Context) {
ctx.HTML(200, HOME)
}
-type RepoSearchOptions struct {
- Counter func(bool) int64
- Ranger func(int, int) ([]*models.Repository, error)
- Private bool
- PageSize int
- OrderBy string
- TplName base.TplName
-}
+func ExploreRepos(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("explore")
+ ctx.Data["PageIsExplore"] = true
+ ctx.Data["PageIsExploreRepositories"] = true
-func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
- var (
- repos []*models.Repository
- count int64
- err error
- )
-
keyword := ctx.Query("q")
- if len(keyword) == 0 {
- repos, err = opts.Ranger(page, opts.PageSize)
- if err != nil {
- ctx.Handle(500, "opts.Ranger", err)
- return
- }
- count = opts.Counter(opts.Private)
- } else {
- var ctxUserID int64
- if ctx.IsSigned {
- ctxUserID = ctx.User.ID
- }
- repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
- Keyword: keyword,
- UserID: ctxUserID,
- OrderBy: opts.OrderBy,
- Private: opts.Private,
- Page: page,
- PageSize: opts.PageSize,
- })
- if err != nil {
- ctx.Handle(500, "SearchRepositoryByName", err)
- return
- }
+ repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
+ Keyword: keyword,
+ UserID: ctx.UserID(),
+ OrderBy: "updated_unix DESC",
+ Page: page,
+ PageSize: setting.UI.ExplorePagingNum,
+ })
+ if err != nil {
+ ctx.Handle(500, "SearchRepositoryByName", err)
+ return
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
- ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
+ ctx.Data["Page"] = paginater.New(int(count), setting.UI.ExplorePagingNum, page, 5)
- for _, repo := range repos {
- if err = repo.GetOwner(); err != nil {
- ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
- return
- }
+ if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+ ctx.Handle(500, "LoadAttributes", err)
+ return
}
ctx.Data["Repos"] = repos
- ctx.HTML(200, opts.TplName)
-}
-
-func ExploreRepos(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("explore")
- ctx.Data["PageIsExplore"] = true
- ctx.Data["PageIsExploreRepositories"] = true
-
- RenderRepoSearch(ctx, &RepoSearchOptions{
- Counter: models.CountRepositories,
- Ranger: models.GetRecentUpdatedRepositories,
- PageSize: setting.UI.ExplorePagingNum,
- OrderBy: "updated_unix DESC",
- TplName: EXPLORE_REPOS,
- })
+ ctx.HTML(200, EXPLORE_REPOS)
}
type UserSearchOptions struct {