Browse Source

Выводятся ресурсы и интересы там где нужно #106

GetRenderedTextField не вынесен в отдельный сервис, т.к. получается циклический импорт.
Из-за того, что modules.Context связан с более нижележащим уровнем modeuls.
pull/118/head
Artur Galyamov 2 years ago
parent
commit
5388d7b1de
  1. 29
      routers/web/explore/user.go
  2. 39
      routers/web/user/profile.go
  3. 6
      templates/explore/interests.tmpl
  4. 6
      templates/explore/resources.tmpl

29
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

39
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
}

6
templates/explore/interests.tmpl

@ -20,9 +20,9 @@
<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>
{{if .Interests}}
<h4>{{$.i18n.Tr "explore.interests"}}:</h4>
<div>{{(index $.RenderedContent .ID)|Str2html}}</div>
{{end}}
</div>
</div>

6
templates/explore/resources.tmpl

@ -20,9 +20,9 @@
<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>
{{if .Resources}}
<h4>{{$.i18n.Tr "explore.resources"}}:</h4>
<div>{{(index $.RenderedContent .ID)|Str2html}}</div>
{{end}}
</div>
</div>

Loading…
Cancel
Save