From ed2c6571a8f88c4f67cca5c3a0eaf253ac4abada Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 31 Aug 2022 17:36:09 +0500 Subject: [PATCH 1/9] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=B1=D1=83=D0=B4=D1=83=D1=89=D0=B5=D0=B3=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D1=8F=D0=BC=20?= =?UTF-8?q?#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_ru-RU.ini | 1 + routers/web/explore/competence.go | 22 ++++++++++++++++++++++ routers/web/web.go | 1 + templates/explore/competences.tmpl | 1 + templates/explore/navbar.tmpl | 3 +++ 5 files changed, 28 insertions(+) create mode 100644 routers/web/explore/competence.go create mode 100644 templates/explore/competences.tmpl diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index c7a318409c..27f9c4fa72 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -259,6 +259,7 @@ users=Пользователи organizations=Сообщества search=Поиск code=Файлы +competences=Компетенции search.fuzzy=Неточный search.match=Соответствие repo_no_results=Подходящие проекты не найдены. diff --git a/routers/web/explore/competence.go b/routers/web/explore/competence.go new file mode 100644 index 0000000000..d65ecc453d --- /dev/null +++ b/routers/web/explore/competence.go @@ -0,0 +1,22 @@ +package explore + +import ( + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" + "net/http" +) + +const ( + tplExploreCompetences base.TplName = "explore/competences" +) + +func Competences(ctx *context.Context) { + ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage + ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + ctx.Data["Title"] = ctx.Tr("explore") + ctx.Data["PageIsExplore"] = true + ctx.Data["PageIsExploreCompetences"] = true + + ctx.HTML(http.StatusOK, tplExploreCompetences) +} diff --git a/routers/web/web.go b/routers/web/web.go index aa946dd343..1851333e92 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -254,6 +254,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/users", explore.Users) m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) + m.Get("/competences", explore.Competences) }, ignExploreSignIn) m.Group("/map", func() { m.Get("/umap", umap.UsersMap) diff --git a/templates/explore/competences.tmpl b/templates/explore/competences.tmpl new file mode 100644 index 0000000000..15bd99afda --- /dev/null +++ b/templates/explore/competences.tmpl @@ -0,0 +1 @@ +

Competences

diff --git a/templates/explore/navbar.tmpl b/templates/explore/navbar.tmpl index 5b1e6b5d06..8ab195895b 100644 --- a/templates/explore/navbar.tmpl +++ b/templates/explore/navbar.tmpl @@ -15,4 +15,7 @@ {{svg "octicon-code"}} {{.i18n.Tr "explore.code"}} {{end}} + + {{svg "octicon-book"}} {{.i18n.Tr "explore.competences"}} + From 04e65b78545f5f341e93ba911eacf8193737bf6d Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 31 Aug 2022 17:55:24 +0500 Subject: [PATCH 2/9] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BB=D0=B8=D1=86=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=D0=BC=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/explore/competences.tmpl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/templates/explore/competences.tmpl b/templates/explore/competences.tmpl index 15bd99afda..730e194328 100644 --- a/templates/explore/competences.tmpl +++ b/templates/explore/competences.tmpl @@ -1 +1,16 @@ -

Competences

+{{template "base/head" .}} + +
+ {{template "explore/navbar" .}} +
+ {{template "explore/search" .}} + +
+ Здесь будет список пользователей заложен +
+ + {{template "base/paginate" .}} +
+
+ +{{template "base/footer" .}} From f29b079f3c939395623ff7e9faf112a4a9433d88 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 31 Aug 2022 18:19:53 +0500 Subject: [PATCH 3/9] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BB=D0=B8=D1=87=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= =?UTF-8?q?,=20=D1=83=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BE=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=20=D0=B0=D0=BB=D1=84?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=82=D1=83=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/explore/competence.go | 14 ++++++++++++-- templates/explore/competences.tmpl | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/routers/web/explore/competence.go b/routers/web/explore/competence.go index d65ecc453d..0fb9d90067 100644 --- a/routers/web/explore/competence.go +++ b/routers/web/explore/competence.go @@ -1,10 +1,13 @@ package explore import ( + "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" - "net/http" + "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" ) const ( @@ -18,5 +21,12 @@ func Competences(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreCompetences"] = true - ctx.HTML(http.StatusOK, tplExploreCompetences) + 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}, + }, tplExploreCompetences) + } diff --git a/templates/explore/competences.tmpl b/templates/explore/competences.tmpl index 730e194328..7b9382d5a4 100644 --- a/templates/explore/competences.tmpl +++ b/templates/explore/competences.tmpl @@ -6,7 +6,26 @@ {{template "explore/search" .}}
- Здесь будет список пользователей заложен + {{range .Users}} +
+ {{avatar .}} +
+ {{.Name}} {{.FullName}} +
+ {{if .Location}} + {{svg "octicon-location"}} {{.Location}} ({{.LocationCoordinate}}) + {{end}} + {{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}} + {{svg "octicon-mail"}} + {{.Email}} + {{end}} + {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} +
+
+
+ {{else}} +
{{$.i18n.Tr "explore.user_no_results"}}
+ {{end}}
{{template "base/paginate" .}} From 219cf41f1205c5bb4dffbd298219415b83e14f97 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 14:31:06 +0500 Subject: [PATCH 4/9] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B2=D0=B8=D0=B4=D0=B5=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/explore/user.go | 16 ++++++++++++++++ templates/explore/competences.tmpl | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 5973a4e066..ccfce1a3ff 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -6,6 +6,8 @@ package explore import ( "bytes" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" "net/http" "code.gitea.io/gitea/models/db" @@ -78,6 +80,20 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, ctx.Data["Keyword"] = opts.Keyword ctx.Data["Total"] = count ctx.Data["Users"] = users + var renderedCompetences = make(map[int64]string) + for _, user := range users { + renderedCompetences[user.ID], err = markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.Repo.RepoLink, + Metas: map[string]string{"mode": "document"}, + GitRepo: ctx.Repo.GitRepo, + Ctx: ctx, + }, user.Competences) + if err != nil { + ctx.ServerError("RenderCompetences", err) + return + } + } + ctx.Data["RenderedCompetences"] = renderedCompetences ctx.Data["UsersTwoFaStatus"] = user_model.UserList(users).GetTwoFaStatus() ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled diff --git a/templates/explore/competences.tmpl b/templates/explore/competences.tmpl index 7b9382d5a4..91fece10f9 100644 --- a/templates/explore/competences.tmpl +++ b/templates/explore/competences.tmpl @@ -20,6 +20,10 @@ {{.Email}} {{end}} {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} + {{if .Competences}} +

Компетенции:

+
{{(index $.RenderedCompetences .ID)|Str2html}}
+ {{end}} From 0a6487b3d023ea097d2d58557ab9c98fde1814fc Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 16:58:17 +0500 Subject: [PATCH 5/9] =?UTF-8?q?=D0=92=D0=BE=20=D0=B2=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5?= =?UTF-8?q?=D0=BD=D1=86=D0=B8=D0=B8=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D1=82=D0=BE=D0=B6=D0=B5=20#10?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/user/search.go | 12 ++++++++++-- models/user/user.go | 3 +++ routers/web/explore/competence.go | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models/user/search.go b/models/user/search.go index 24a21777e8..453d09558d 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -39,13 +39,21 @@ type SearchUserOptions struct { } func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { - var cond builder.Cond = builder.Eq{"type": opts.Type} + var cond builder.Cond + if opts.Type == UserTypeIdentity { + cond = builder.Or( + builder.Eq{"type": UserTypeIndividual}, + builder.Eq{"type": UserTypeOrganization}, + ) + } else { + cond = builder.Eq{"type": opts.Type} + } if len(opts.Keyword) > 0 { lowerKeyword := strings.ToLower(opts.Keyword) keywordCond := builder.Or( builder.Like{"lower_name", lowerKeyword}, builder.Like{"LOWER(full_name)", lowerKeyword}, - builder.Like{"LOWER(description)", lowerKeyword}, + builder.Like{"LOWER(description)", lowerKeyword}, ) if opts.SearchByEmail { keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) diff --git a/models/user/user.go b/models/user/user.go index 5ce5d3cbd5..9270951449 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -46,6 +46,9 @@ const ( // UserTypeOrganization defines an organization UserTypeOrganization + + // UserTypeIdentity defines individual + organization + UserTypeIdentity ) const ( diff --git a/routers/web/explore/competence.go b/routers/web/explore/competence.go index 0fb9d90067..ccd7bf64f2 100644 --- a/routers/web/explore/competence.go +++ b/routers/web/explore/competence.go @@ -23,7 +23,7 @@ func Competences(ctx *context.Context) { RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.User, - Type: user_model.UserTypeIndividual, + Type: user_model.UserTypeIdentity, ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, IsActive: util.OptionalBoolTrue, Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, From 024759873c966245c33b1530f7989b07068d675e Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 18:57:25 +0500 Subject: [PATCH 6/9] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=20=D0=BF=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D1=8F=D0=BC=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/user/search.go | 17 ++++++++++++++++- routers/web/explore/competence.go | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/models/user/search.go b/models/user/search.go index 453d09558d..f33039582f 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -17,6 +17,13 @@ import ( "xorm.io/xorm" ) +type SearchKind int64 + +const ( + ByDescription SearchKind = iota + ByCompetence +) + // SearchUserOptions contains the options for searching type SearchUserOptions struct { db.ListOptions @@ -28,6 +35,7 @@ type SearchUserOptions struct { Visible []structs.VisibleType Actor *User // The user doing the search SearchByEmail bool // Search by email as well as username/full name + Kind SearchKind IsActive util.OptionalBool IsAdmin util.OptionalBool @@ -53,8 +61,15 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { keywordCond := builder.Or( builder.Like{"lower_name", lowerKeyword}, builder.Like{"LOWER(full_name)", lowerKeyword}, - builder.Like{"LOWER(description)", lowerKeyword}, ) + switch opts.Kind { + case ByDescription: + keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) + case ByCompetence: + keywordCond = builder.Or(builder.Like{"LOWER(competences)", lowerKeyword}) + default: + keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) + } if opts.SearchByEmail { keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) } diff --git a/routers/web/explore/competence.go b/routers/web/explore/competence.go index ccd7bf64f2..20eaaa38c5 100644 --- a/routers/web/explore/competence.go +++ b/routers/web/explore/competence.go @@ -27,6 +27,7 @@ func Competences(ctx *context.Context) { ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, IsActive: util.OptionalBoolTrue, Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Kind: user_model.ByCompetence, }, tplExploreCompetences) } From ef0c047e994507790296c9b34112f8e9d541135e Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 19:15:10 +0500 Subject: [PATCH 7/9] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=20=D0=BF=D0=BE=20=D1=80=D0=B5=D1=81=D1=83=D1=80?= =?UTF-8?q?=D1=81=D0=B0=D0=BC=20=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D1=81=D0=B0=D0=BC=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit пока выводятся форматированные компетенции --- models/user/search.go | 6 ++++++ options/locale/locale_ru-RU.ini | 2 ++ routers/web/explore/interest.go | 33 +++++++++++++++++++++++++++++++++ routers/web/explore/resource.go | 33 +++++++++++++++++++++++++++++++++ routers/web/web.go | 2 ++ templates/explore/interests.tmpl | 39 +++++++++++++++++++++++++++++++++++++++ templates/explore/navbar.tmpl | 6 ++++++ templates/explore/resources.tmpl | 39 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 160 insertions(+) create mode 100644 routers/web/explore/interest.go create mode 100644 routers/web/explore/resource.go create mode 100644 templates/explore/interests.tmpl create mode 100644 templates/explore/resources.tmpl diff --git a/models/user/search.go b/models/user/search.go index f33039582f..4edb4c9f03 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -22,6 +22,8 @@ type SearchKind int64 const ( ByDescription SearchKind = iota ByCompetence + ByResource + ByInterest ) // SearchUserOptions contains the options for searching @@ -67,6 +69,10 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) case ByCompetence: keywordCond = builder.Or(builder.Like{"LOWER(competences)", lowerKeyword}) + case ByResource: + keywordCond = builder.Or(builder.Like{"LOWER(resources)", lowerKeyword}) + case ByInterest: + keywordCond = builder.Or(builder.Like{"LOWER(interests)", lowerKeyword}) default: keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) } diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index 27f9c4fa72..4bc3f3faf8 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -260,6 +260,8 @@ organizations=Сообщества search=Поиск code=Файлы competences=Компетенции +resources=Ресурсы +interests=Интересы search.fuzzy=Неточный search.match=Соответствие repo_no_results=Подходящие проекты не найдены. diff --git a/routers/web/explore/interest.go b/routers/web/explore/interest.go new file mode 100644 index 0000000000..071b989f36 --- /dev/null +++ b/routers/web/explore/interest.go @@ -0,0 +1,33 @@ +package explore + +import ( + "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 ( + tplExploreInterests base.TplName = "explore/interests" +) + +func Interests(ctx *context.Context) { + ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage + ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + ctx.Data["Title"] = ctx.Tr("explore") + ctx.Data["PageIsExplore"] = true + ctx.Data["PageIsExploreInterests"] = true + + RenderUserSearch(ctx, &user_model.SearchUserOptions{ + Actor: ctx.User, + Type: user_model.UserTypeIdentity, + ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, + IsActive: util.OptionalBoolTrue, + Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Kind: user_model.ByInterest, + }, tplExploreInterests) + +} diff --git a/routers/web/explore/resource.go b/routers/web/explore/resource.go new file mode 100644 index 0000000000..f13300bbf0 --- /dev/null +++ b/routers/web/explore/resource.go @@ -0,0 +1,33 @@ +package explore + +import ( + "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 ( + tplExploreResources base.TplName = "explore/resources" +) + +func Resources(ctx *context.Context) { + ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage + ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + ctx.Data["Title"] = ctx.Tr("explore") + ctx.Data["PageIsExplore"] = true + ctx.Data["PageIsExploreResources"] = true + + RenderUserSearch(ctx, &user_model.SearchUserOptions{ + Actor: ctx.User, + Type: user_model.UserTypeIdentity, + ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, + IsActive: util.OptionalBoolTrue, + Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Kind: user_model.ByResource, + }, tplExploreResources) + +} diff --git a/routers/web/web.go b/routers/web/web.go index 1851333e92..1fdd330df0 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -255,6 +255,8 @@ func RegisterRoutes(m *web.Route) { m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) m.Get("/competences", explore.Competences) + m.Get("/resources", explore.Resources) + m.Get("/interests", explore.Interests) }, ignExploreSignIn) m.Group("/map", func() { m.Get("/umap", umap.UsersMap) diff --git a/templates/explore/interests.tmpl b/templates/explore/interests.tmpl new file mode 100644 index 0000000000..91fece10f9 --- /dev/null +++ b/templates/explore/interests.tmpl @@ -0,0 +1,39 @@ +{{template "base/head" .}} + +
+ {{template "explore/navbar" .}} +
+ {{template "explore/search" .}} + +
+ {{range .Users}} +
+ {{avatar .}} +
+ {{.Name}} {{.FullName}} +
+ {{if .Location}} + {{svg "octicon-location"}} {{.Location}} ({{.LocationCoordinate}}) + {{end}} + {{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}} + {{svg "octicon-mail"}} + {{.Email}} + {{end}} + {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} + {{if .Competences}} +

Компетенции:

+
{{(index $.RenderedCompetences .ID)|Str2html}}
+ {{end}} +
+
+
+ {{else}} +
{{$.i18n.Tr "explore.user_no_results"}}
+ {{end}} +
+ + {{template "base/paginate" .}} +
+
+ +{{template "base/footer" .}} diff --git a/templates/explore/navbar.tmpl b/templates/explore/navbar.tmpl index 8ab195895b..4e3d74a921 100644 --- a/templates/explore/navbar.tmpl +++ b/templates/explore/navbar.tmpl @@ -18,4 +18,10 @@ {{svg "octicon-book"}} {{.i18n.Tr "explore.competences"}} + + {{svg "octicon-briefcase"}} {{.i18n.Tr "explore.resources"}} + + + {{svg "octicon-code-of-conduct"}} {{.i18n.Tr "explore.interests"}} + diff --git a/templates/explore/resources.tmpl b/templates/explore/resources.tmpl new file mode 100644 index 0000000000..91fece10f9 --- /dev/null +++ b/templates/explore/resources.tmpl @@ -0,0 +1,39 @@ +{{template "base/head" .}} + +
+ {{template "explore/navbar" .}} +
+ {{template "explore/search" .}} + +
+ {{range .Users}} +
+ {{avatar .}} +
+ {{.Name}} {{.FullName}} +
+ {{if .Location}} + {{svg "octicon-location"}} {{.Location}} ({{.LocationCoordinate}}) + {{end}} + {{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}} + {{svg "octicon-mail"}} + {{.Email}} + {{end}} + {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} + {{if .Competences}} +

Компетенции:

+
{{(index $.RenderedCompetences .ID)|Str2html}}
+ {{end}} +
+
+
+ {{else}} +
{{$.i18n.Tr "explore.user_no_results"}}
+ {{end}} +
+ + {{template "base/paginate" .}} +
+
+ +{{template "base/footer" .}} From 5388d7b1de190df08d954ec882152c70b682e34c Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 20:32:44 +0500 Subject: [PATCH 8/9] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B5=D1=81=D1=8B=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=20=D0=B3=D0=B4=D0=B5=20=D0=BD=D1=83=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetRenderedTextField не вынесен в отдельный сервис, т.к. получается циклический импорт. Из-за того, что modules.Context связан с более нижележащим уровнем modeuls. --- routers/web/explore/user.go | 29 +++++++++++++++++------------ routers/web/user/profile.go | 39 +++++++++++++++++++++++---------------- templates/explore/interests.tmpl | 6 +++--- templates/explore/resources.tmpl | 6 +++--- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index ccfce1a3ff..cecb4578eb 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -6,8 +6,7 @@ package explore import ( "bytes" - "code.gitea.io/gitea/modules/markup" - "code.gitea.io/gitea/modules/markup/markdown" + "code.gitea.io/gitea/routers/web/user" "net/http" "code.gitea.io/gitea/models/db" @@ -80,20 +79,26 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, ctx.Data["Keyword"] = opts.Keyword ctx.Data["Total"] = count ctx.Data["Users"] = users - var renderedCompetences = make(map[int64]string) - for _, user := range users { - renderedCompetences[user.ID], err = markdown.RenderString(&markup.RenderContext{ - URLPrefix: ctx.Repo.RepoLink, - Metas: map[string]string{"mode": "document"}, - GitRepo: ctx.Repo.GitRepo, - Ctx: ctx, - }, user.Competences) + var renderedContent = make(map[int64]string) + var contentFieldName string + switch opts.Kind { + case user_model.ByCompetence: + contentFieldName = "Competences" + case user_model.ByResource: + contentFieldName = "Resources" + case user_model.ByInterest: + contentFieldName = "Interests" + default: + contentFieldName = "Description" + } + for _, curUser := range users { + renderedContent[curUser.ID], err = user.GetRenderedTextField(ctx, curUser, contentFieldName) if err != nil { - ctx.ServerError("RenderCompetences", err) + ctx.ServerError("RenderContent", err) return } } - ctx.Data["RenderedCompetences"] = renderedCompetences + ctx.Data["RenderedContent"] = renderedContent ctx.Data["UsersTwoFaStatus"] = user_model.UserList(users).GetTwoFaStatus() ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 2ad333a6af..90fafb871e 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -159,28 +159,39 @@ func Profile(ctx *context.Context) { ctx.Data["HeatmapData"] = data } - var renderErr error + var ( + renderErr error + content string + ) - renderErr = getRenderedTextField(ctx, ctxUser, "Description") - if renderErr != nil { + content, renderErr = GetRenderedTextField(ctx, ctxUser, "Description") + if renderErr == nil { + ctx.Data["RenderedDescription"] = content + } else { ctx.ServerError("RenderString", renderErr) return } - renderErr = getRenderedTextField(ctx, ctxUser, "Competences") - if renderErr != nil { + content, renderErr = GetRenderedTextField(ctx, ctxUser, "Competences") + if renderErr == nil { + ctx.Data["RenderedCompetences"] = content + } else { ctx.ServerError("RenderString", renderErr) return } - renderErr = getRenderedTextField(ctx, ctxUser, "Resources") - if renderErr != nil { + content, renderErr = GetRenderedTextField(ctx, ctxUser, "Resources") + if renderErr == nil { + ctx.Data["RenderedResources"] = content + } else { ctx.ServerError("RenderString", renderErr) return } - renderErr = getRenderedTextField(ctx, ctxUser, "Interests") - if renderErr != nil { + content, renderErr = GetRenderedTextField(ctx, ctxUser, "Interests") + if renderErr == nil { + ctx.Data["RenderedInterests"] = content + } else { ctx.ServerError("RenderString", renderErr) return } @@ -391,13 +402,13 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.FormString("redirect_to"), u.HomeLink()) } -func getTextField(user *user_model.User, fieldName string) string { +func getTextField(user interface{}, fieldName string) string { reflectedObj := reflect.ValueOf(user) dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) return dynamicField.String() } -func getRenderedTextField(ctx *context.Context, ctxUser *user_model.User, fieldName string) error { +func GetRenderedTextField(ctx *context.Context, ctxUser interface{}, fieldName string) (string, error) { var err error = nil var content string fieldVal := getTextField(ctxUser, fieldName) @@ -408,10 +419,6 @@ func getRenderedTextField(ctx *context.Context, ctxUser *user_model.User, fieldN GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, fieldVal) - if err == nil { - renderedFieldName := fmt.Sprintf("Rendered%s", fieldName) - ctx.Data[renderedFieldName] = content - } } - return err + return content, err } diff --git a/templates/explore/interests.tmpl b/templates/explore/interests.tmpl index 91fece10f9..6f87437518 100644 --- a/templates/explore/interests.tmpl +++ b/templates/explore/interests.tmpl @@ -20,9 +20,9 @@ {{.Email}} {{end}} {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} - {{if .Competences}} -

Компетенции:

-
{{(index $.RenderedCompetences .ID)|Str2html}}
+ {{if .Interests}} +

{{$.i18n.Tr "explore.interests"}}:

+
{{(index $.RenderedContent .ID)|Str2html}}
{{end}} diff --git a/templates/explore/resources.tmpl b/templates/explore/resources.tmpl index 91fece10f9..fc0acff672 100644 --- a/templates/explore/resources.tmpl +++ b/templates/explore/resources.tmpl @@ -20,9 +20,9 @@ {{.Email}} {{end}} {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} - {{if .Competences}} -

Компетенции:

-
{{(index $.RenderedCompetences .ID)|Str2html}}
+ {{if .Resources}} +

{{$.i18n.Tr "explore.resources"}}:

+
{{(index $.RenderedContent .ID)|Str2html}}
{{end}} From 1e6ee55b9fb047e6170c825bb94284ad74a72a95 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 2 Sep 2022 20:45:45 +0500 Subject: [PATCH 9/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B9=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/explore/competences.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/explore/competences.tmpl b/templates/explore/competences.tmpl index 91fece10f9..e49159f579 100644 --- a/templates/explore/competences.tmpl +++ b/templates/explore/competences.tmpl @@ -21,8 +21,8 @@ {{end}} {{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} {{if .Competences}} -

Компетенции:

-
{{(index $.RenderedCompetences .ID)|Str2html}}
+

{{$.i18n.Tr "explore.competences"}}:

+
{{(index $.RenderedContent .ID)|Str2html}}
{{end}}