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

34
routers/web/repo/resource.go

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

Loading…
Cancel
Save