|
|
|
@ -5,7 +5,11 @@
|
|
|
|
|
package org |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"code.gitea.io/gitea/modules/markup" |
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown" |
|
|
|
|
"fmt" |
|
|
|
|
"net/http" |
|
|
|
|
"reflect" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
@ -13,8 +17,6 @@ import (
|
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
|
"code.gitea.io/gitea/modules/markup" |
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown" |
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -46,17 +48,24 @@ func Home(ctx *context.Context) {
|
|
|
|
|
|
|
|
|
|
ctx.Data["PageIsUserProfile"] = true |
|
|
|
|
ctx.Data["Title"] = org.DisplayName() |
|
|
|
|
if len(org.Description) != 0 { |
|
|
|
|
desc, err := markdown.RenderString(&markup.RenderContext{ |
|
|
|
|
URLPrefix: ctx.Repo.RepoLink, |
|
|
|
|
Metas: map[string]string{"mode": "document"}, |
|
|
|
|
GitRepo: ctx.Repo.GitRepo, |
|
|
|
|
}, org.Description) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.ServerError("RenderString", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ctx.Data["RenderedDescription"] = desc |
|
|
|
|
|
|
|
|
|
var renderErr error |
|
|
|
|
renderErr = getRenderedTextField(ctx, org, "Description") |
|
|
|
|
if renderErr != nil { |
|
|
|
|
ctx.ServerError("RenderString", renderErr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderErr = getRenderedTextField(ctx, org, "Competences") |
|
|
|
|
if renderErr != nil { |
|
|
|
|
ctx.ServerError("RenderString", renderErr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderErr = getRenderedTextField(ctx, org, "Resources") |
|
|
|
|
if renderErr != nil { |
|
|
|
|
ctx.ServerError("RenderString", renderErr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var orderBy db.SearchOrderBy |
|
|
|
@ -159,3 +168,32 @@ func Home(ctx *context.Context) {
|
|
|
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, tplOrgHome) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getTextField(user *models.Organization, fieldName string) string { |
|
|
|
|
reflectedObj := reflect.ValueOf(user) |
|
|
|
|
dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) |
|
|
|
|
return dynamicField.String() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
Приходится дублировать код, т.к. не получилось вынести эту функцию и функцию getTextField в services, |
|
|
|
|
т.к. modules/context/context.go зависит от models/user. |
|
|
|
|
*/ |
|
|
|
|
func getRenderedTextField(ctx *context.Context, ctxUser *models.Organization, fieldName string) error { |
|
|
|
|
var err error = nil |
|
|
|
|
var content string |
|
|
|
|
fieldVal := getTextField(ctxUser, fieldName) |
|
|
|
|
if len(fieldVal) != 0 { |
|
|
|
|
content, err = markdown.RenderString(&markup.RenderContext{ |
|
|
|
|
URLPrefix: ctx.Repo.RepoLink, |
|
|
|
|
Metas: map[string]string{"mode": "document"}, |
|
|
|
|
GitRepo: ctx.Repo.GitRepo, |
|
|
|
|
Ctx: ctx, |
|
|
|
|
}, fieldVal) |
|
|
|
|
if err == nil { |
|
|
|
|
renderedFieldName := fmt.Sprintf("Rendered%s", fieldName) |
|
|
|
|
ctx.Data[renderedFieldName] = content |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|