diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 1e04b72cbb..92793d95a4 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -48,32 +48,12 @@ func Home(ctx *context.Context) { ctx.Data["Title"] = org.DisplayName() var orderBy db.SearchOrderBy - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { - case "newest": - orderBy = db.SearchOrderByNewest - case "oldest": - orderBy = db.SearchOrderByOldest - case "recentupdate": - orderBy = db.SearchOrderByRecentUpdated - case "leastupdate": - orderBy = db.SearchOrderByLeastUpdated - case "reversealphabetically": - orderBy = db.SearchOrderByAlphabeticallyReverse - case "alphabetically": - orderBy = db.SearchOrderByAlphabetically - case "moststars": - orderBy = db.SearchOrderByStarsReverse - case "feweststars": - orderBy = db.SearchOrderByStars - case "mostforks": - orderBy = db.SearchOrderByForksReverse - case "fewestforks": - orderBy = db.SearchOrderByForks - default: - ctx.Data["SortType"] = "recentupdate" - orderBy = db.SearchOrderByRecentUpdated + sortOrder := ctx.FormString("sort") + if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok { + sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home? } + ctx.Data["SortType"] = sortOrder + orderBy = repo_model.OrderByFlatMap[sortOrder] keyword := ctx.FormTrim("q") ctx.Data["Keyword"] = keyword diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 3000792789..57b8d9da2f 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -112,32 +112,12 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb orderBy db.SearchOrderBy ) - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { - case "newest": - orderBy = db.SearchOrderByNewest - case "oldest": - orderBy = db.SearchOrderByOldest - case "recentupdate": - orderBy = db.SearchOrderByRecentUpdated - case "leastupdate": - orderBy = db.SearchOrderByLeastUpdated - case "reversealphabetically": - orderBy = db.SearchOrderByAlphabeticallyReverse - case "alphabetically": - orderBy = db.SearchOrderByAlphabetically - case "moststars": - orderBy = db.SearchOrderByStarsReverse - case "feweststars": - orderBy = db.SearchOrderByStars - case "mostforks": - orderBy = db.SearchOrderByForksReverse - case "fewestforks": - orderBy = db.SearchOrderByForks - default: - ctx.Data["SortType"] = "recentupdate" - orderBy = db.SearchOrderByRecentUpdated + sortOrder := ctx.FormString("sort") + if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok { + sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home? } + ctx.Data["SortType"] = sortOrder + orderBy = repo_model.OrderByFlatMap[sortOrder] keyword := ctx.FormTrim("q") ctx.Data["Keyword"] = keyword