Remove redudant functions and code (#2652)

* Remove redudant functions and code
This commit is contained in:
Morlinest 2017-10-10 22:37:18 +02:00 committed by Kim "BKC" Carlbäcker
parent c2346e4469
commit dff26e25ca
5 changed files with 57 additions and 117 deletions

View file

@ -24,7 +24,6 @@ func Repos(ctx *context.Context) {
ctx.Data["PageIsAdminRepositories"] = true
routers.RenderRepoSearch(ctx, &routers.RepoSearchOptions{
Ranger: models.Repositories,
Private: true,
PageSize: setting.UI.Admin.RepoPagingNum,
TplName: tplRepos,

View file

@ -60,8 +60,7 @@ func Swagger(ctx *context.Context) {
// RepoSearchOptions when calling search repositories
type RepoSearchOptions struct {
Ranger func(*models.SearchRepoOptions) (models.RepositoryList, int64, error)
Searcher *models.User
OwnerID int64
Private bool
PageSize int
TplName base.TplName
@ -113,35 +112,21 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
}
keyword := strings.Trim(ctx.Query("q"), " ")
if len(keyword) == 0 {
repos, count, err = opts.Ranger(&models.SearchRepoOptions{
Page: page,
PageSize: opts.PageSize,
Searcher: ctx.User,
OrderBy: orderBy,
Private: opts.Private,
Collaborate: true,
})
if err != nil {
ctx.Handle(500, "opts.Ranger", err)
return
}
} else {
if isKeywordValid(keyword) {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: orderBy,
Private: opts.Private,
Page: page,
PageSize: opts.PageSize,
Searcher: ctx.User,
Collaborate: true,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
}
}
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Page: page,
PageSize: opts.PageSize,
OrderBy: orderBy,
Private: opts.Private,
Keyword: keyword,
OwnerID: opts.OwnerID,
Searcher: ctx.User,
Collaborate: true,
AllPublic: true,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
@ -157,11 +142,15 @@ func ExploreRepos(ctx *context.Context) {
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreRepositories"] = true
var ownerID int64
if ctx.User != nil && !ctx.User.IsAdmin {
ownerID = ctx.User.ID
}
RenderRepoSearch(ctx, &RepoSearchOptions{
Ranger: models.GetRecentUpdatedRepositories,
PageSize: setting.UI.ExplorePagingNum,
Searcher: ctx.User,
Private: ctx.User != nil && ctx.User.IsAdmin,
OwnerID: ownerID,
Private: ctx.User != nil,
TplName: tplExploreRepos,
})
}