6 changed files with 2998 additions and 0 deletions
@ -0,0 +1,114 @@ |
|||||||
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package umap |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
"net/http" |
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db" |
||||||
|
user_model "code.gitea.io/gitea/models/user" |
||||||
|
"code.gitea.io/gitea/modules/base" |
||||||
|
"code.gitea.io/gitea/modules/context" |
||||||
|
"code.gitea.io/gitea/modules/setting" |
||||||
|
"code.gitea.io/gitea/modules/structs" |
||||||
|
"code.gitea.io/gitea/modules/util" |
||||||
|
) |
||||||
|
|
||||||
|
const ( |
||||||
|
// tplExploreUsers map page template
|
||||||
|
tplExploreUsers base.TplName = "map/umap" |
||||||
|
) |
||||||
|
|
||||||
|
// UserSearchDefaultSortType is the default sort type for user search
|
||||||
|
const UserSearchDefaultSortType = "alphabetically" |
||||||
|
|
||||||
|
var ( |
||||||
|
nullByte = []byte{0x00} |
||||||
|
) |
||||||
|
|
||||||
|
func isKeywordValid(keyword string) bool { |
||||||
|
|||||||
|
return !bytes.Contains([]byte(keyword), nullByte) |
||||||
|
} |
||||||
|
|
||||||
|
// RenderUserSearch render user search page
|
||||||
|
func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName) { |
||||||
|
opts.Page = ctx.FormInt("page") |
||||||
|
if opts.Page <= 1 { |
||||||
|
opts.Page = 1 |
||||||
|
} |
||||||
|
|
||||||
|
var ( |
||||||
|
users []*user_model.User |
||||||
|
count int64 |
||||||
|
err error |
||||||
|
orderBy db.SearchOrderBy |
||||||
|
) |
||||||
|
|
||||||
|
// we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns
|
||||||
redex2000
commented 3 years ago
Review
лишний пробел |
|||||||
|
ctx.Data["SortType"] = ctx.FormString("sort") |
||||||
|
switch ctx.FormString("sort") { |
||||||
|
case "newest": |
||||||
|
orderBy = "`user`.id DESC" |
||||||
|
case "oldest": |
||||||
|
orderBy = "`user`.id ASC" |
||||||
|
case "recentupdate": |
||||||
|
orderBy = "`user`.updated_unix DESC" |
||||||
|
case "leastupdate": |
||||||
|
orderBy = "`user`.updated_unix ASC" |
||||||
|
case "reversealphabetically": |
||||||
|
orderBy = "`user`.name DESC" |
||||||
|
case UserSearchDefaultSortType: // "alphabetically"
|
||||||
|
default: |
||||||
|
orderBy = "`user`.name ASC" |
||||||
|
ctx.Data["SortType"] = UserSearchDefaultSortType |
||||||
|
} |
||||||
|
|
||||||
|
opts.Keyword = ctx.FormTrim("q") |
||||||
|
opts.OrderBy = orderBy |
||||||
|
if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) { |
||||||
|
users, count, err = user_model.SearchUsers(opts) |
||||||
|
if err != nil { |
||||||
|
ctx.ServerError("SearchUsers", err) |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ctx.Data["Keyword"] = opts.Keyword |
||||||
|
ctx.Data["Total"] = count |
||||||
|
ctx.Data["Users"] = users |
||||||
|
ctx.Data["UsersTwoFaStatus"] = user_model.UserList(users).GetTwoFaStatus() |
||||||
|
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail |
||||||
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled |
||||||
|
|
||||||
|
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) |
||||||
|
pager.SetDefaultParams(ctx) |
||||||
|
for paramKey, paramVal := range opts.ExtraParamStrings { |
||||||
|
pager.AddParamString(paramKey, paramVal) |
||||||
|
} |
||||||
|
ctx.Data["Page"] = pager |
||||||
|
|
||||||
|
ctx.HTML(http.StatusOK, tplName) |
||||||
|
} |
||||||
|
|
||||||
|
// Users render explore users page
|
||||||
|
func UsersMap(ctx *context.Context) { |
||||||
|
if setting.Service.Explore.DisableUsersPage { |
||||||
|
ctx.Redirect(setting.AppSubURL + "/map/umap") |
||||||
|
return |
||||||
|
} |
||||||
|
ctx.Data["Title"] = ctx.Tr("map") |
||||||
|
ctx.Data["PageIsMap"] = true |
||||||
|
ctx.Data["PageIsMapUsers"] = true |
||||||
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled |
||||||
|
|
||||||
|
RenderUserSearch(ctx, &user_model.SearchUserOptions{ |
||||||
|
Actor: ctx.User, |
||||||
|
Type: user_model.UserTypeIndividual, |
||||||
|
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, |
||||||
|
IsActive: util.OptionalBoolTrue, |
||||||
|
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, |
||||||
|
}, tplExploreUsers) |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
<div class="ui secondary pointing tabular top attached borderless stackable menu new-menu navbar"> |
||||||
|
<a class="{{if .PageIsMapRepositories}}active{{end}} item" href="{{AppSubUrl}}/map/rmap"> |
||||||
|
{{svg "octicon-repo"}} {{.i18n.Tr "explore.repos"}} |
||||||
|
</a> |
||||||
|
{{if not .UsersIsDisabled}} |
||||||
|
<a class="{{if .PageIsMapUsers}}active{{end}} item" href="{{AppSubUrl}}/map/umap"> |
||||||
|
{{svg "octicon-person"}} {{.i18n.Tr "explore.users"}} |
||||||
|
</a> |
||||||
|
{{end}} |
||||||
|
<a class="{{if .PageIsMapOrganizations}}active{{end}} item" href="{{AppSubUrl}}/map/orgmap"> |
||||||
|
{{svg "octicon-organization"}} {{.i18n.Tr "explore.organizations"}} |
||||||
|
</a> |
||||||
|
{{if .IsRepoIndexerEnabled}} |
||||||
|
<a class="{{if .PageIsMapCode}}active{{end}} item" href="{{AppSubUrl}}/map/codemap"> |
||||||
|
{{svg "octicon-code"}} {{.i18n.Tr "explore.code"}} |
||||||
|
</a> |
||||||
|
{{end}} |
||||||
|
</div> |
Loading…
Reference in new issue
Какой стиль именования для функций используется? lowerCamelCase либо PascalCase?
Почему возник вопрос,
потому что функция isKeywordValid в lowerCamelCase.
А RenderUserSearch в PascalCase.
насколько я понял
isKeywordValid - внутренняя функций в файле (приватная функция)
IsKeywordValid - публичная функция, которая использует в других файлах (Публичная функция)