From b8ad909ef15921e37b5877d0e1eb3eea4669f0cc Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Tue, 15 May 2018 20:54:47 +0300 Subject: [PATCH 1/2] Added repository search order by stars or forks. Added Forks column to admin repository list. Signed-off-by: Alexey Terentyev --- models/repo_list.go | 4 ++++ models/user.go | 4 ++-- options/locale/locale_en-US.ini | 5 +++++ routers/home.go | 24 ++++++++++++++++-------- routers/user/profile.go | 8 ++++++++ templates/admin/base/search.tmpl | 2 -- templates/admin/repo/list.tmpl | 4 +++- templates/admin/repo/search.tmpl | 29 +++++++++++++++++++++++++++++ templates/explore/repos.tmpl | 2 +- templates/explore/search_repo.tmpl | 29 +++++++++++++++++++++++++++++ templates/user/profile.tmpl | 4 ++-- 11 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 templates/admin/repo/search.tmpl create mode 100644 templates/explore/search_repo.tmpl diff --git a/models/repo_list.go b/models/repo_list.go index df6b81cb8dcf..b1527b73c9f4 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -152,6 +152,10 @@ const ( SearchOrderBySizeReverse = "size DESC" SearchOrderByID = "id ASC" SearchOrderByIDReverse = "id DESC" + SearchOrderByStars = "num_stars ASC" + SearchOrderByStarsReverse = "num_stars DESC" + SearchOrderByForks = "num_forks ASC" + SearchOrderByForksReverse = "num_forks DESC" ) // SearchRepositoryByName takes keyword and part of repository name to search, diff --git a/models/user.go b/models/user.go index 8f5ee6e5a7e1..d64205497945 100644 --- a/models/user.go +++ b/models/user.go @@ -1272,7 +1272,7 @@ func GetUser(user *User) (bool, error) { type SearchUserOptions struct { Keyword string Type UserType - OrderBy string + OrderBy SearchOrderBy Page int PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum IsActive util.OptionalBool @@ -1322,7 +1322,7 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) { users = make([]*User, 0, opts.PageSize) return users, count, x.Where(cond). Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). - OrderBy(opts.OrderBy). + OrderBy(opts.OrderBy.String()). Find(&users) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8ef00566081a..b309633129b8 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -671,6 +671,10 @@ issues.filter_sort.recentupdate = Recently updated issues.filter_sort.leastupdate = Least recently updated issues.filter_sort.mostcomment = Most commented issues.filter_sort.leastcomment = Least commented +issues.filter_sort.moststars = Most stars +issues.filter_sort.feweststars = Fewest stars +issues.filter_sort.mostforks = Most forks +issues.filter_sort.fewestforks = Fewest forks issues.action_open = Open issues.action_close = Close issues.action_label = Label @@ -1327,6 +1331,7 @@ repos.name = Name repos.private = Private repos.watches = Watches repos.stars = Stars +repos.forks = Forks repos.issues = Issues repos.size = Size diff --git a/routers/home.go b/routers/home.go index 4810eb4e6f7e..5bb353c7e176 100644 --- a/routers/home.go +++ b/routers/home.go @@ -104,6 +104,14 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { orderBy = models.SearchOrderBySizeReverse case "size": orderBy = models.SearchOrderBySize + case "moststars": + orderBy = models.SearchOrderByStarsReverse + case "feweststars": + orderBy = models.SearchOrderByStars + case "mostforks": + orderBy = models.SearchOrderByForksReverse + case "fewestforks": + orderBy = models.SearchOrderByForks default: ctx.Data["SortType"] = "recentupdate" orderBy = models.SearchOrderByRecentUpdated @@ -164,26 +172,26 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN users []*models.User count int64 err error - orderBy string + orderBy models.SearchOrderBy ) ctx.Data["SortType"] = ctx.Query("sort") switch ctx.Query("sort") { case "newest": - orderBy = "id DESC" + orderBy = models.SearchOrderByIDReverse case "oldest": - orderBy = "id ASC" + orderBy = models.SearchOrderByID case "recentupdate": - orderBy = "updated_unix DESC" + orderBy = models.SearchOrderByRecentUpdated case "leastupdate": - orderBy = "updated_unix ASC" + orderBy = models.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = "name DESC" + orderBy = models.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = "name ASC" + orderBy = models.SearchOrderByAlphabetically default: ctx.Data["SortType"] = "alphabetically" - orderBy = "name ASC" + orderBy = models.SearchOrderByAlphabetically } opts.Keyword = strings.Trim(ctx.Query("q"), " ") diff --git a/routers/user/profile.go b/routers/user/profile.go index 4c5cbf508197..4e622c9a65e0 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -125,6 +125,14 @@ func Profile(ctx *context.Context) { orderBy = models.SearchOrderByAlphabeticallyReverse case "alphabetically": orderBy = models.SearchOrderByAlphabetically + case "moststars": + orderBy = models.SearchOrderByStarsReverse + case "feweststars": + orderBy = models.SearchOrderByStars + case "mostforks": + orderBy = models.SearchOrderByForksReverse + case "fewestforks": + orderBy = models.SearchOrderByForks default: ctx.Data["SortType"] = "recentupdate" orderBy = models.SearchOrderByRecentUpdated diff --git a/templates/admin/base/search.tmpl b/templates/admin/base/search.tmpl index 7d23e51c890a..b817a8ad796c 100644 --- a/templates/admin/base/search.tmpl +++ b/templates/admin/base/search.tmpl @@ -12,8 +12,6 @@ {{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}} {{.i18n.Tr "repo.issues.filter_sort.recentupdate"}} {{.i18n.Tr "repo.issues.filter_sort.leastupdate"}} - {{.i18n.Tr "repo.issues.label.filter_sort.by_size"}} - {{.i18n.Tr "repo.issues.label.filter_sort.reverse_by_size"}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 86d6b8042631..f706eaa1c891 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -7,7 +7,7 @@ {{.i18n.Tr "admin.repos.repo_manage_panel"}} ({{.i18n.Tr "admin.total" .Total}})
- {{template "admin/base/search" .}} + {{template "admin/repo/search" .}}
@@ -19,6 +19,7 @@ + @@ -34,6 +35,7 @@ + diff --git a/templates/admin/repo/search.tmpl b/templates/admin/repo/search.tmpl new file mode 100644 index 000000000000..8e69f7c388b7 --- /dev/null +++ b/templates/admin/repo/search.tmpl @@ -0,0 +1,29 @@ + + +
+ + +
+ diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index 9ca9879103c1..ac31d43cdd4c 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -2,7 +2,7 @@
{{template "explore/navbar" .}}
- {{template "explore/search" .}} + {{template "explore/search_repo" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
diff --git a/templates/explore/search_repo.tmpl b/templates/explore/search_repo.tmpl new file mode 100644 index 000000000000..de0b63e07792 --- /dev/null +++ b/templates/explore/search_repo.tmpl @@ -0,0 +1,29 @@ + +
+
+ + + +
+ +
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 837f8bd94905..e03e15d0c245 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -100,12 +100,12 @@
{{else if eq .TabName "stars"}}
- {{template "explore/search" .}} + {{template "explore/search_repo" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
{{else}} - {{template "explore/search" .}} + {{template "explore/search_repo" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}} {{end}} From db4fccf75aa2973437d3c7ff08c97c5f92115796 Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Wed, 23 May 2018 23:50:10 +0300 Subject: [PATCH 2/2] Renamed search repo template Signed-off-by: Alexey Terentyev --- templates/explore/{search_repo.tmpl => repo_search.tmpl} | 0 templates/explore/repos.tmpl | 2 +- templates/user/profile.tmpl | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename templates/explore/{search_repo.tmpl => repo_search.tmpl} (100%) diff --git a/templates/explore/search_repo.tmpl b/templates/explore/repo_search.tmpl similarity index 100% rename from templates/explore/search_repo.tmpl rename to templates/explore/repo_search.tmpl diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index ac31d43cdd4c..c728219d3ea6 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -2,7 +2,7 @@
{{template "explore/navbar" .}}
- {{template "explore/search_repo" .}} + {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index e03e15d0c245..915da555be62 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -100,12 +100,12 @@
{{else if eq .TabName "stars"}}
- {{template "explore/search_repo" .}} + {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
{{else}} - {{template "explore/search_repo" .}} + {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}} {{end}}
{{.i18n.Tr "admin.repos.private"}} {{.i18n.Tr "admin.repos.watches"}} {{.i18n.Tr "admin.repos.stars"}}{{.i18n.Tr "admin.repos.forks"}} {{.i18n.Tr "admin.repos.issues"}} {{.i18n.Tr "admin.repos.size"}} {{.i18n.Tr "admin.users.created"}} {{.NumWatches}} {{.NumStars}}{{.NumForks}} {{.NumIssues}} {{SizeFmt .Size}} {{.CreatedUnix.FormatShort}}