Browse Source

Реализован вывод компетенций с возможностью искать их #65

pull/120/head
Artur Galyamov 3 years ago
parent
commit
b76fbf7d15
  1. 3
      routers/web/repo/competence.go
  2. 11
      routers/web/repo/resource.go

3
routers/web/repo/competence.go

@ -3,7 +3,6 @@ package repo
import ( import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/routers/web/user"
"net/http" "net/http"
) )
@ -16,7 +15,7 @@ func Competences(ctx *context.Context) {
repo := ctx.Data["Repository"] repo := ctx.Data["Repository"]
var err error var err error
ctx.Data["RenderedCompetences"], err = user.GetRenderedTextFieldByName(ctx, repo, "Competences") ctx.Data["RenderedCompetences"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences")
if err != nil { if err != nil {
ctx.ServerError("Render", err) ctx.ServerError("Render", err)

11
routers/web/repo/resource.go

@ -5,8 +5,10 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/routers/web/user" "code.gitea.io/gitea/routers/web/user"
"errors" "errors"
"fmt"
"net/http" "net/http"
"regexp" "regexp"
"strings"
) )
const ( const (
@ -18,7 +20,7 @@ func Resources(ctx *context.Context) {
repo := ctx.Data["Repository"] repo := ctx.Data["Repository"]
var err error var err error
ctx.Data["RenderedResources"], err = getRenderedResourcesWithSearchLinks(ctx, repo) ctx.Data["RenderedResources"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources")
if err != nil { if err != nil {
ctx.ServerError("Render", err) ctx.ServerError("Render", err)
@ -28,8 +30,8 @@ func Resources(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplResources) ctx.HTML(http.StatusOK, tplResources)
} }
func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) (string, error) { func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) {
resources := user.GetTextField(repo, "Resources") resources := user.GetTextField(repo, fieldName)
var regExp *regexp.Regexp var regExp *regexp.Regexp
var err error var err error
@ -39,7 +41,8 @@ func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{})
return "", err return "", err
} }
resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(`- \[ \] $1 [найти](/explore/resources?tab=&q=$1)`)) resourceSubstitutionPattern := fmt.Sprintf(`- \[ \] $1 [найти](/explore/%s?tab=&q=$1)`, strings.ToLower(fieldName))
resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(resourceSubstitutionPattern))
if resourcesWithLinks == nil { if resourcesWithLinks == nil {
return "", errors.New("not found matches in resources") return "", errors.New("not found matches in resources")

Loading…
Cancel
Save