Skip to content

Change default sort order #2647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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"), " ")
Expand Down Expand Up @@ -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":
Expand All @@ -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"), " ")
Expand Down
7 changes: 1 addition & 6 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), " ")
Expand Down
2 changes: 1 addition & 1 deletion templates/explore/search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down