From a8e49709bb243d53a0e668782edacbb0a55236f2 Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Fri, 10 Jun 2022 20:12:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B7=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B3=D1=80=D1=83=D0=B1=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D1=8B=20=D1=81=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=D0=BC=D0=B8=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_ru-RU.ini | 1 + routers/web/map/umap.go | 114 ++ routers/web/web.go | 4 + templates/base/head_navbar.tmpl | 1 + templates/map/umap.tmpl | 2859 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 2979 insertions(+) create mode 100644 routers/web/map/umap.go create mode 100644 templates/map/umap.tmpl diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index 0111dfe434..53806d44ee 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -63,6 +63,7 @@ settings=Настройки your_profile=Профиль your_starred=Избранные your_settings=Настройки +map=Карта all=Все sources=Собственные diff --git a/routers/web/map/umap.go b/routers/web/map/umap.go new file mode 100644 index 0000000000..7032b70909 --- /dev/null +++ b/routers/web/map/umap.go @@ -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 + 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) +} diff --git a/routers/web/web.go b/routers/web/web.go index e18ed8f8ee..ef1b83ed7d 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -28,6 +28,7 @@ import ( "code.gitea.io/gitea/routers/web/dev" "code.gitea.io/gitea/routers/web/events" "code.gitea.io/gitea/routers/web/explore" + "code.gitea.io/gitea/routers/web/map" "code.gitea.io/gitea/routers/web/org" "code.gitea.io/gitea/routers/web/repo" "code.gitea.io/gitea/routers/web/user" @@ -254,6 +255,9 @@ func RegisterRoutes(m *web.Route) { m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) }, ignExploreSignIn) + m.Group("/map", func() { + m.Get("/umap", umap.UsersMap) + }, ignExploreSignIn) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/milestones", reqSignIn, reqMilestonesDashboardPageEnabled, user.Milestones) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 5ce1d0b888..ad8843f4b8 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -21,6 +21,7 @@ {{if .ShowMilestonesDashboardPage}}{{.i18n.Tr "milestones"}}{{end}} {{end}} {{.i18n.Tr "explore"}} + {{.i18n.Tr "map"}} {{else if .IsLandingPageOrganizations}} {{.i18n.Tr "explore"}} {{else}} diff --git a/templates/map/umap.tmpl b/templates/map/umap.tmpl new file mode 100644 index 0000000000..7e014f1f6a --- /dev/null +++ b/templates/map/umap.tmpl @@ -0,0 +1,2859 @@ +{{template "base/head" .}} +
+ {{template "explore/navbar" .}} + + + + + + + + + + + + + + +
+ Mouse over a cluster to see the bounds of its children and click a cluster to zoom to those bounds + + +
+{{template "base/footer" .}}