summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Sawada <kazuki@6715.jp>2017-10-05 14:02:43 +0900
committerLauris BH <lauris@nix.lv>2017-10-05 08:02:43 +0300
commit43253202e9e9b82f04e7726d5719cfc7d0fc5e65 (patch)
tree1c6699207700cb49cd82d41cf0b00485014ed79c
parentaa962deec037375a7cfae3b96094becdfe48e778 (diff)
downloadgitea-43253202e9e9b82f04e7726d5719cfc7d0fc5e65.tar.gz
gitea-43253202e9e9b82f04e7726d5719cfc7d0fc5e65.zip
Change default sort order (#2647)
* sort repositories by `updated_unix` in Explore * Fix UI problem * Added missing sort order "newest" * Change default sort order * fmt
-rw-r--r--routers/home.go12
-rw-r--r--routers/user/profile.go7
-rw-r--r--templates/explore/search.tmpl2
3 files changed, 11 insertions, 10 deletions
diff --git a/routers/home.go b/routers/home.go
index 381bdd20ae..94c570b6ce 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -88,9 +88,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
err error
orderBy models.SearchOrderBy
)
- ctx.Data["SortType"] = ctx.Query("sort")
+ ctx.Data["SortType"] = ctx.Query("sort")
switch ctx.Query("sort") {
+ case "newest":
+ orderBy = models.SearchOrderByNewest
case "oldest":
orderBy = models.SearchOrderByOldest
case "recentupdate":
@@ -106,7 +108,8 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
case "size":
orderBy = models.SearchOrderBySize
default:
- orderBy = models.SearchOrderByNewest
+ ctx.Data["SortType"] = "recentupdate"
+ orderBy = models.SearchOrderByRecentUpdated
}
keyword := strings.Trim(ctx.Query("q"), " ")
@@ -188,6 +191,8 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
ctx.Data["SortType"] = ctx.Query("sort")
switch ctx.Query("sort") {
+ case "newest":
+ orderBy = "id DESC"
case "oldest":
orderBy = "id ASC"
case "recentupdate":
@@ -199,7 +204,8 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
case "alphabetically":
orderBy = "name ASC"
default:
- orderBy = "id DESC"
+ ctx.Data["SortType"] = "alphabetically"
+ orderBy = "name ASC"
}
keyword := strings.Trim(ctx.Query("q"), " ")
diff --git a/routers/user/profile.go b/routers/user/profile.go
index 50d0c2397f..b0eab09333 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -126,12 +126,7 @@ func Profile(ctx *context.Context) {
orderBy = models.SearchOrderByAlphabetically
default:
ctx.Data["SortType"] = "recentupdate"
- orderBy = models.SearchOrderByNewest
- }
-
- // set default sort value if sort is empty.
- if ctx.Query("sort") == "" {
- ctx.Data["SortType"] = "recentupdate"
+ orderBy = models.SearchOrderByRecentUpdated
}
keyword := strings.Trim(ctx.Query("q"), " ")
diff --git a/templates/explore/search.tmpl b/templates/explore/search.tmpl
index 8cd6f9b2f5..dbf0b15e7a 100644
--- a/templates/explore/search.tmpl
+++ b/templates/explore/search.tmpl
@@ -6,7 +6,7 @@
<i class="dropdown icon"></i>
</span>
<div class="menu">
- <a class="{{if or (eq .SortType "newest") (not .SortType)}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
+ <a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .SortType "oldest"}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>