Browse Source

Теперь ссылки на поиск доверительных свойств открываются в отдельной вкладке #65

также выполнен рефакторинг, т.к. метод вызывается и для компетенций, и для ресурсов.
pull/120/head
Artur Galyamov 2 years ago
parent
commit
f77d73c83a
  1. 2
      routers/web/repo/competence.go
  2. 34
      routers/web/repo/resource.go

2
routers/web/repo/competence.go

@ -15,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 = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences") ctx.Data["RenderedCompetences"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences")
if err != nil { if err != nil {
ctx.ServerError("Render", err) ctx.ServerError("Render", err)

34
routers/web/repo/resource.go

@ -19,7 +19,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, "Resources") ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources")
if err != nil { if err != nil {
ctx.ServerError("Render", err) ctx.ServerError("Render", err)
@ -29,8 +29,8 @@ func Resources(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplResources) ctx.HTML(http.StatusOK, tplResources)
} }
func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) {
resources := user.GetTextField(repo, fieldName) trustProps := user.GetTextField(repo, fieldName)
var regExp *regexp.Regexp var regExp *regexp.Regexp
var err error var err error
@ -40,29 +40,29 @@ func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{},
return "", err return "", err
} }
resourceNamesMatches := regExp.FindAllStringSubmatch(resources, -1) trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1)
if resourceNamesMatches == nil { if trustPropNamesMatches == nil {
return "", err return "", err
} }
var resourcesWithSafeURLs = strings.Clone(resources) var trustPropsWithSafeURLs = strings.Clone(trustProps)
var resourceName string var trustPropName string
var searchQS string var searchQS string
for _, resourceNameMatches := range resourceNamesMatches { for _, trustPropNameMatches := range trustPropNamesMatches {
resourceName = resourceNameMatches[1] trustPropName = trustPropNameMatches[1]
searchQS = strings.ReplaceAll(resourceName, " ", "+") searchQS = strings.ReplaceAll(trustPropName, " ", "+")
resourceSubstitutionPattern := fmt.Sprintf( trustPropSubstitutionPattern := fmt.Sprintf(
`- [ ] %s [найти](/explore/%s?tab=&q=%s)`, `- [ ] %s [найти](/explore/%s?tab=&q=%s)`,
resourceName, trustPropName,
strings.ToLower(fieldName), strings.ToLower(fieldName),
searchQS) searchQS)
resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceNameMatches[0], resourceSubstitutionPattern, -1) trustPropsWithSafeURLs = strings.Replace(trustPropsWithSafeURLs, trustPropNameMatches[0], trustPropSubstitutionPattern, -1)
} }
var renderedResourcesWithSafeURLs string var renderedTrustPropsWithSafeURLs string
renderedResourcesWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, resourcesWithSafeURLs) renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, trustPropsWithSafeURLs)
renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "<a", "<a target='blank'")
return renderedResourcesWithSafeURLs, err return renderedTrustPropsWithTargetBlank, err
} }

Loading…
Cancel
Save