1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Rename repo_model.SearchOrderByMap to repo_model.OrderByMap (#31359)

https://github.com/go-gitea/gitea/pull/30876#discussion_r1637112394
(cherry picked from commit 78e8296e113e2fd9259ec05fe87035427821ea0b)
This commit is contained in:
6543 2024-06-15 08:45:02 +02:00 committed by Earl Warren
parent 5d10c3446a
commit 3246e83251
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 22 additions and 22 deletions

View file

@ -5,8 +5,8 @@ package repo
import "code.gitea.io/gitea/models/db" import "code.gitea.io/gitea/models/db"
// SearchOrderByMap represents all possible search order // OrderByMap represents all possible search order
var SearchOrderByMap = map[string]map[string]db.SearchOrderBy{ var OrderByMap = map[string]map[string]db.SearchOrderBy{
"asc": { "asc": {
"alpha": "owner_name ASC, name ASC", "alpha": "owner_name ASC, name ASC",
"created": db.SearchOrderByOldest, "created": db.SearchOrderByOldest,
@ -31,22 +31,22 @@ var SearchOrderByMap = map[string]map[string]db.SearchOrderBy{
}, },
} }
// SearchOrderByFlatMap is similar to SearchOrderByMap but use human language keywords // OrderByFlatMap is similar to OrderByMap but use human language keywords
// to decide between asc and desc // to decide between asc and desc
var SearchOrderByFlatMap = map[string]db.SearchOrderBy{ var OrderByFlatMap = map[string]db.SearchOrderBy{
"newest": SearchOrderByMap["desc"]["created"], "newest": OrderByMap["desc"]["created"],
"oldest": SearchOrderByMap["asc"]["created"], "oldest": OrderByMap["asc"]["created"],
"leastupdate": SearchOrderByMap["asc"]["updated"], "leastupdate": OrderByMap["asc"]["updated"],
"reversealphabetically": SearchOrderByMap["desc"]["alpha"], "reversealphabetically": OrderByMap["desc"]["alpha"],
"alphabetically": SearchOrderByMap["asc"]["alpha"], "alphabetically": OrderByMap["asc"]["alpha"],
"reversesize": SearchOrderByMap["desc"]["size"], "reversesize": OrderByMap["desc"]["size"],
"size": SearchOrderByMap["asc"]["size"], "size": OrderByMap["asc"]["size"],
"reversegitsize": SearchOrderByMap["desc"]["git_size"], "reversegitsize": OrderByMap["desc"]["git_size"],
"gitsize": SearchOrderByMap["asc"]["git_size"], "gitsize": OrderByMap["asc"]["git_size"],
"reverselfssize": SearchOrderByMap["desc"]["lfs_size"], "reverselfssize": OrderByMap["desc"]["lfs_size"],
"lfssize": SearchOrderByMap["asc"]["lfs_size"], "lfssize": OrderByMap["asc"]["lfs_size"],
"moststars": SearchOrderByMap["desc"]["stars"], "moststars": OrderByMap["desc"]["stars"],
"feweststars": SearchOrderByMap["asc"]["stars"], "feweststars": OrderByMap["asc"]["stars"],
"mostforks": SearchOrderByMap["desc"]["forks"], "mostforks": OrderByMap["desc"]["forks"],
"fewestforks": SearchOrderByMap["asc"]["forks"], "fewestforks": OrderByMap["asc"]["forks"],
} }

View file

@ -184,7 +184,7 @@ func Search(ctx *context.APIContext) {
if len(sortOrder) == 0 { if len(sortOrder) == 0 {
sortOrder = "asc" sortOrder = "asc"
} }
if searchModeMap, ok := repo_model.SearchOrderByMap[sortOrder]; ok { if searchModeMap, ok := repo_model.OrderByMap[sortOrder]; ok {
if orderBy, ok := searchModeMap[sortMode]; ok { if orderBy, ok := searchModeMap[sortMode]; ok {
opts.OrderBy = orderBy opts.OrderBy = orderBy
} else { } else {

View file

@ -63,7 +63,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
sortOrder = setting.UI.ExploreDefaultSort sortOrder = setting.UI.ExploreDefaultSort
} }
if order, ok := repo_model.SearchOrderByFlatMap[sortOrder]; ok { if order, ok := repo_model.OrderByFlatMap[sortOrder]; ok {
orderBy = order orderBy = order
} else { } else {
sortOrder = "recentupdate" sortOrder = "recentupdate"

View file

@ -629,7 +629,7 @@ func SearchRepo(ctx *context.Context) {
if len(sortOrder) == 0 { if len(sortOrder) == 0 {
sortOrder = "asc" sortOrder = "asc"
} }
if searchModeMap, ok := repo_model.SearchOrderByMap[sortOrder]; ok { if searchModeMap, ok := repo_model.OrderByMap[sortOrder]; ok {
if orderBy, ok := searchModeMap[sortMode]; ok { if orderBy, ok := searchModeMap[sortMode]; ok {
opts.OrderBy = orderBy opts.OrderBy = orderBy
} else { } else {