Browse Source

Реализован поиск лиц по ресурсам и интересам #106

пока выводятся форматированные компетенции
pull/118/head
Artur Galyamov 2 years ago
parent
commit
ef0c047e99
  1. 6
      models/user/search.go
  2. 2
      options/locale/locale_ru-RU.ini
  3. 33
      routers/web/explore/interest.go
  4. 33
      routers/web/explore/resource.go
  5. 2
      routers/web/web.go
  6. 39
      templates/explore/interests.tmpl
  7. 6
      templates/explore/navbar.tmpl
  8. 39
      templates/explore/resources.tmpl

6
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})
}

2
options/locale/locale_ru-RU.ini

@ -260,6 +260,8 @@ organizations=Сообщества
search=Поиск
code=Файлы
competences=Компетенции
resources=Ресурсы
interests=Интересы
search.fuzzy=Неточный
search.match=Соответствие
repo_no_results=Подходящие проекты не найдены.

33
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)
}

33
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)
}

2
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)

39
templates/explore/interests.tmpl

@ -0,0 +1,39 @@
{{template "base/head" .}}
<div class="page-content explore">
{{template "explore/navbar" .}}
<div class="ui container">
{{template "explore/search" .}}
<div class="ui user list">
{{range .Users}}
<div class="item">
{{avatar .}}
<div class="content">
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}</span>
<div class="description">
{{if .Location}}
{{svg "octicon-location"}} {{.Location}} ({{.LocationCoordinate}})
{{end}}
{{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}}
{{svg "octicon-mail"}}
<a href="mailto:{{.Email}}" rel="nofollow">{{.Email}}</a>
{{end}}
{{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}}
{{if .Competences}}
<h4>Компетенции:</h4>
<div>{{(index $.RenderedCompetences .ID)|Str2html}}</div>
{{end}}
</div>
</div>
</div>
{{else}}
<div>{{$.i18n.Tr "explore.user_no_results"}}</div>
{{end}}
</div>
{{template "base/paginate" .}}
</div>
</div>
{{template "base/footer" .}}

6
templates/explore/navbar.tmpl

@ -18,4 +18,10 @@
<a class="{{if .PageIsExploreCompetences}}active{{end}} item" href="{{AppSubUrl}}/explore/competences">
{{svg "octicon-book"}} {{.i18n.Tr "explore.competences"}}
</a>
<a class="{{if .PageIsExploreResources}}active{{end}} item" href="{{AppSubUrl}}/explore/resources">
{{svg "octicon-briefcase"}} {{.i18n.Tr "explore.resources"}}
</a>
<a class="{{if .PageIsExploreInterests}}active{{end}} item" href="{{AppSubUrl}}/explore/interests">
{{svg "octicon-code-of-conduct"}} {{.i18n.Tr "explore.interests"}}
</a>
</div>

39
templates/explore/resources.tmpl

@ -0,0 +1,39 @@
{{template "base/head" .}}
<div class="page-content explore">
{{template "explore/navbar" .}}
<div class="ui container">
{{template "explore/search" .}}
<div class="ui user list">
{{range .Users}}
<div class="item">
{{avatar .}}
<div class="content">
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}</span>
<div class="description">
{{if .Location}}
{{svg "octicon-location"}} {{.Location}} ({{.LocationCoordinate}})
{{end}}
{{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}}
{{svg "octicon-mail"}}
<a href="mailto:{{.Email}}" rel="nofollow">{{.Email}}</a>
{{end}}
{{svg "octicon-clock"}} {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}}
{{if .Competences}}
<h4>Компетенции:</h4>
<div>{{(index $.RenderedCompetences .ID)|Str2html}}</div>
{{end}}
</div>
</div>
</div>
{{else}}
<div>{{$.i18n.Tr "explore.user_no_results"}}</div>
{{end}}
</div>
{{template "base/paginate" .}}
</div>
</div>
{{template "base/footer" .}}
Loading…
Cancel
Save