From 9ce84e08a405481350055b26991a63c37bc64fab Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 2 Nov 2022 13:40:25 +0500 Subject: [PATCH 1/8] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=20js-=D1=81?= =?UTF-8?q?=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B4=D0=BB=D1=8F=20AJAX-?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B5/=D1=81?= =?UTF-8?q?=D0=BD=D1=8F=D1=82=D0=B8=D1=8E=20=D0=B3=D0=B0=D0=BB=D0=BE=D1=87?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=81=20=D1=84=D0=BB=D0=B0=D0=B6=D0=BA=D0=B0=20?= =?UTF-8?q?#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/competences/list.tmpl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/repo/competences/list.tmpl b/templates/repo/competences/list.tmpl index 8fa2c9cb8a..65a1578fb8 100644 --- a/templates/repo/competences/list.tmpl +++ b/templates/repo/competences/list.tmpl @@ -3,9 +3,11 @@ {{template "repo/header" .}}

{{.i18n.Tr "repo.competences"}}

-
+
{{$.RenderedCompetences | Str2html}}
+
{{.Repository.Competences}}
+
{{template "base/footer" .}} From c02f7bd41a270f1a5b15b6a1c4eb9855edce0f74 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 2 Nov 2022 14:18:19 +0500 Subject: [PATCH 2/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D1=82=D0=BE=D1=87=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/competence.go | 40 ++++++++++++++++++++++++++++++++++++++++ routers/web/web.go | 1 + 2 files changed, 41 insertions(+) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 5562482324..2002cbc41b 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -1,8 +1,11 @@ package repo 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" "net/http" ) @@ -24,3 +27,40 @@ func Competences(ctx *context.Context) { ctx.HTML(http.StatusOK, tplCompetences) } + +func ToggleCompetences(ctx *context.Context) { + if !ctx.IsSigned { + ctx.Error(http.StatusForbidden) + return + } + + repo := ctx.Repo.Repository + toggledContent := ctx.FormString("content") + + content, err := markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? + Metas: ctx.Repo.Repository.ComposeMetas(), + GitRepo: ctx.Repo.GitRepo, + Ctx: ctx, + }, toggledContent) + if err != nil { + ctx.ServerError("RenderString", err) + return + } + + repo.Competences = toggledContent + err = repo_model.UpdateRepositoryCols(repo, "competences") + if err != nil { + ctx.ServerError("ToggleCompetences", err) + return + } + + responseBody := map[string]interface{}{ + "content": content, + } + + ctx.JSON( + http.StatusOK, + responseBody, + ) +} diff --git a/routers/web/web.go b/routers/web/web.go index 1e0937671e..bca09e950c 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -892,6 +892,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/issues_tree", repo.IssuesTree) m.Get("/resources", repo.Resources) m.Get("/competences", repo.Competences) + m.Post("/competences", repo.ToggleCompetences) m.Get("/{type:issues|pulls}/{index}", repo.ViewIssue) m.Group("/{type:issues|pulls}/{index}/content-history", func() { m.Get("/overview", repo.GetContentHistoryOverview) From c3da3fd3887af675b3d76aeaa8205ce4edadfcbf Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 3 Nov 2022 17:24:52 +0500 Subject: [PATCH 3/8] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5/=D0=B2=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD?= =?UTF-8?q?=D1=86=D0=B8=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE?= =?UTF-8?q?=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit в сырое содержимое выводим преобразованную информацию с найти. При сохранении изменений в БД удаляем ссылку на найти. В сырое содержимое (rawContent) выводим ссылку на найти, иначе неправильно будут вычисляться data-source-position. Был альтернативный вариант, вычислять data-source-position на основании трансформированного содержимого (с найти), но сохранять в сырое содержимое изначальное, нетрансформированное, содержимое. --- routers/web/repo/competence.go | 19 +++++++++++++++++-- routers/web/repo/resource.go | 8 ++++---- templates/repo/competences/list.tmpl | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 2002cbc41b..4ad4f175a2 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -7,6 +7,7 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "net/http" + "regexp" ) const ( @@ -18,7 +19,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], ctx.Data["TransformedTrustProps"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences") if err != nil { ctx.ServerError("Render", err) @@ -48,7 +49,12 @@ func ToggleCompetences(ctx *context.Context) { return } - repo.Competences = toggledContent + repo.Competences, err = trimSearchLinks(toggledContent) + if err != nil { + ctx.ServerError("trimSearchLinks", err) + return + } + err = repo_model.UpdateRepositoryCols(repo, "competences") if err != nil { ctx.ServerError("ToggleCompetences", err) @@ -64,3 +70,12 @@ func ToggleCompetences(ctx *context.Context) { responseBody, ) } + +func trimSearchLinks(content string) (string, error) { + regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) + if err != nil { + return "", err + } + trimmedSearchLink := regExp.ReplaceAllString(content, "") + return trimmedSearchLink, nil +} diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index bcf7f76595..a5ca592219 100644 --- a/routers/web/repo/resource.go +++ b/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 = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") + ctx.Data["RenderedResources"], ctx.Data["TransformedTrustProps"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) @@ -29,7 +29,7 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { +func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, string, error) { trustProps := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp @@ -37,7 +37,7 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} regExp, err = regexp.Compile(`- \[ \] (.+)`) if err != nil { - return "", err + return "", "", err } trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) @@ -66,5 +66,5 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} var renderedTrustPropsWithSafeURLs string renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, " {{$.RenderedCompetences | Str2html}} -
{{.Repository.Competences}}
+
{{$.TransformedTrustProps}}
From 86fde45a5287f141dee0c04809162939369984d2 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 3 Nov 2022 21:23:45 +0500 Subject: [PATCH 4/8] =?UTF-8?q?=D0=A1=D1=81=D1=8B=D0=BB=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D1=87=D0=B5=D0=B7=D0=B0=D0=B5=D1=82=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B5?= =?UTF-8?q?=20=D0=B3=D0=B0=D0=BB=D0=BE=D1=87=D0=BA=D0=B8=20=D0=BD=D0=B0=20?= =?UTF-8?q?checkbox=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/competences/list.tmpl | 2 +- web_src/js/index.js | 3 ++- web_src/js/markup/content.js | 5 +++++ web_src/js/markup/trust_props.js | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 web_src/js/markup/trust_props.js diff --git a/templates/repo/competences/list.tmpl b/templates/repo/competences/list.tmpl index 4fd7110c38..88f7100933 100644 --- a/templates/repo/competences/list.tmpl +++ b/templates/repo/competences/list.tmpl @@ -3,7 +3,7 @@ {{template "repo/header" .}}

{{.i18n.Tr "repo.competences"}}

-
+
{{$.RenderedCompetences | Str2html}}
{{$.TransformedTrustProps}}
diff --git a/web_src/js/index.js b/web_src/js/index.js index 8ea30f1fca..8330ac87c1 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -19,7 +19,7 @@ import {initMarkupAnchors} from './markup/anchors.js'; import {initNotificationCount, initNotificationsTable} from './features/notification.js'; import {initRepoIssueContentHistory} from './features/repo-issue-content.js'; import {initStopwatch} from './features/stopwatch.js'; -import {initCommentContent, initMarkupContent} from './markup/content.js'; +import {initCommentContent, initMarkupContent, initTrustPropsContent} from './markup/content.js'; import {initUserAuthLinkAccountView, initUserAuthOauth2} from './features/user-auth.js'; import { @@ -105,6 +105,7 @@ $(document).ready(() => { initFootLanguageMenu(); initCommentContent(); + initTrustPropsContent() initContextPopups(); initHeatmap(); initImageDiff(); diff --git a/web_src/js/markup/content.js b/web_src/js/markup/content.js index ef5067fd66..16875903a3 100644 --- a/web_src/js/markup/content.js +++ b/web_src/js/markup/content.js @@ -1,6 +1,7 @@ import {renderMermaid} from './mermaid.js'; import {renderCodeCopy} from './codecopy.js'; import {initMarkupTasklist} from './tasklist.js'; +import {initMarkupTrustProps} from './trust_props.js' // code that runs for all markup content export function initMarkupContent() { @@ -12,3 +13,7 @@ export function initMarkupContent() { export function initCommentContent() { initMarkupTasklist(); } + +export function initTrustPropsContent() { + initMarkupTrustProps(); +} diff --git a/web_src/js/markup/trust_props.js b/web_src/js/markup/trust_props.js new file mode 100644 index 0000000000..f4ceb04470 --- /dev/null +++ b/web_src/js/markup/trust_props.js @@ -0,0 +1,5 @@ +export function initMarkupTrustProps() { + $('.trust-props input[type="checkbox"]').click((e) => { + $(e.target).parent().find('a').remove() + }) +} From 4d2ebb1020377a87734717e2ac6e0389a2fd4b91 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 4 Nov 2022 18:19:32 +0500 Subject: [PATCH 5/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B9=D1=82=D0=B8,=20=D0=B5=D1=81=D0=BB=D0=B8?= =?UTF-8?q?=20=D1=84=D0=BB=D0=B0=D0=B6=D0=BE=D0=BA=20=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=B3=D0=B0=D0=BB=D0=BE=D1=87=D0=BA=D0=B8=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_src/js/markup/trust_props.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web_src/js/markup/trust_props.js b/web_src/js/markup/trust_props.js index f4ceb04470..eb5169e205 100644 --- a/web_src/js/markup/trust_props.js +++ b/web_src/js/markup/trust_props.js @@ -1,5 +1,16 @@ export function initMarkupTrustProps() { + const renderSearchLink = (trustPropName) => { + const safeName = trustPropName.replace(' ', '+'); + return` найти`; + } + $('.trust-props input[type="checkbox"]').click((e) => { - $(e.target).parent().find('a').remove() - }) + if (e.target.checked) { + $(e.target).parent().find('a').remove(); + } else { + const $parent = $(e.target).parent(); + const renderedSearchLink = renderSearchLink($parent.text()); + $parent.append(renderedSearchLink); + } + }); } From 6631cf0220ae200b12648a66c58d19e5bfd72f6b Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 4 Nov 2022 21:36:18 +0500 Subject: [PATCH 6/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F=20=D1=84=D0=BB=D0=B0=D0=B6=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit заодно отрефакторил, вынес общий код в отдельный служебный слой. Чтобы избежать дублирования и переиспользовать код. --- routers/web/repo/competence.go | 38 ++---------------------- routers/web/repo/resource.go | 23 +++++++++++++++ routers/web/web.go | 1 + services/trust_props/trust_props.go | 58 +++++++++++++++++++++++++++++++++++++ templates/repo/resources/list.tmpl | 4 ++- 5 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 services/trust_props/trust_props.go diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 4ad4f175a2..274f2a807d 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -1,13 +1,10 @@ package repo 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/services/trust_props" "net/http" - "regexp" ) const ( @@ -35,34 +32,14 @@ func ToggleCompetences(ctx *context.Context) { return } - repo := ctx.Repo.Repository - toggledContent := ctx.FormString("content") - - content, err := markdown.RenderString(&markup.RenderContext{ - URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? - Metas: ctx.Repo.Repository.ComposeMetas(), - GitRepo: ctx.Repo.GitRepo, - Ctx: ctx, - }, toggledContent) - if err != nil { - ctx.ServerError("RenderString", err) - return - } - - repo.Competences, err = trimSearchLinks(toggledContent) - if err != nil { - ctx.ServerError("trimSearchLinks", err) - return - } - - err = repo_model.UpdateRepositoryCols(repo, "competences") + toggledContent, err := trust_props.SaveRepoAndRenderContent(ctx, "competences") if err != nil { ctx.ServerError("ToggleCompetences", err) return } responseBody := map[string]interface{}{ - "content": content, + "content": toggledContent, } ctx.JSON( @@ -70,12 +47,3 @@ func ToggleCompetences(ctx *context.Context) { responseBody, ) } - -func trimSearchLinks(content string) (string, error) { - regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) - if err != nil { - return "", err - } - trimmedSearchLink := regExp.ReplaceAllString(content, "") - return trimmedSearchLink, nil -} diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index a5ca592219..1bfe4998d3 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -4,6 +4,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" + "code.gitea.io/gitea/services/trust_props" "fmt" "net/http" "regexp" @@ -29,6 +30,28 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } +func ToggleResources(ctx *context.Context) { + if !ctx.IsSigned { + ctx.Error(http.StatusForbidden) + return + } + + toggledContent, err := trust_props.SaveRepoAndRenderContent(ctx, "resources") + if err != nil { + ctx.ServerError("ToggleCompetences", err) + return + } + + responseBody := map[string]interface{}{ + "content": toggledContent, + } + + ctx.JSON( + http.StatusOK, + responseBody, + ) +} + func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, string, error) { trustProps := user.GetTextField(repo, fieldName) diff --git a/routers/web/web.go b/routers/web/web.go index bca09e950c..d5451e853a 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -891,6 +891,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/{type:issues|pulls}", repo.Issues) m.Get("/issues_tree", repo.IssuesTree) m.Get("/resources", repo.Resources) + m.Post("/resources", repo.ToggleResources) m.Get("/competences", repo.Competences) m.Post("/competences", repo.ToggleCompetences) m.Get("/{type:issues|pulls}/{index}", repo.ViewIssue) diff --git a/services/trust_props/trust_props.go b/services/trust_props/trust_props.go new file mode 100644 index 0000000000..9f635f4b97 --- /dev/null +++ b/services/trust_props/trust_props.go @@ -0,0 +1,58 @@ +package trust_props + +import ( + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" + "reflect" + "regexp" + "strings" +) + +func SaveRepoAndRenderContent(ctx *context.Context, colName string) (string, error) { + repo := ctx.Repo.Repository + toggledContent := ctx.FormString("content") + + content, err := markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? + Metas: ctx.Repo.Repository.ComposeMetas(), + GitRepo: ctx.Repo.GitRepo, + Ctx: ctx, + }, toggledContent) + if err != nil { + return "", err + } + + trimmedToggledContent, err := trimSearchLinks(toggledContent) + if err != nil { + return "", err + } + fieldName := upCase(colName) + reflectedRepo := reflect.ValueOf(repo) + reflectedRepo.Elem().FieldByName(fieldName).SetString(trimmedToggledContent) + err = repo_model.UpdateRepositoryCols(repo, colName) + if err != nil { + return "", err + } + + return content, nil +} + +func trimSearchLinks(content string) (string, error) { + regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) + if err != nil { + return "", err + } + trimmedSearchLink := regExp.ReplaceAllString(content, "") + return trimmedSearchLink, nil +} + +func upCase(str string) string { + ch := rune(str[0]) + ch -= 'a' - 'A' + var upCasedSB strings.Builder + upCasedSB.WriteRune(ch) + upCasedSB.WriteString(str[1:]) + return upCasedSB.String() +} diff --git a/templates/repo/resources/list.tmpl b/templates/repo/resources/list.tmpl index 125cb62d85..6ab050f0af 100644 --- a/templates/repo/resources/list.tmpl +++ b/templates/repo/resources/list.tmpl @@ -3,9 +3,11 @@ {{template "repo/header" .}}

{{.i18n.Tr "repo.resources"}}

-
+
{{$.RenderedResources | Str2html}}
+
{{$.TransformedTrustProps}}
+
{{template "base/footer" .}} From 1ef18757dea13fc3b2ba1ba0e300010947414e15 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 7 Nov 2022 13:45:00 +0500 Subject: [PATCH 7/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3,=20=D1=81=D1=81=D1=8B=D0=BB?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2=D0=B5=D1=80=D0=B8=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=20#150?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/competences/list.tmpl | 2 +- templates/repo/resources/list.tmpl | 2 +- web_src/js/markup/trust_props.js | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/repo/competences/list.tmpl b/templates/repo/competences/list.tmpl index 88f7100933..40366e7209 100644 --- a/templates/repo/competences/list.tmpl +++ b/templates/repo/competences/list.tmpl @@ -3,7 +3,7 @@ {{template "repo/header" .}}

{{.i18n.Tr "repo.competences"}}

-
+
{{$.RenderedCompetences | Str2html}}
{{$.TransformedTrustProps}}
diff --git a/templates/repo/resources/list.tmpl b/templates/repo/resources/list.tmpl index 6ab050f0af..6e827ece27 100644 --- a/templates/repo/resources/list.tmpl +++ b/templates/repo/resources/list.tmpl @@ -3,7 +3,7 @@ {{template "repo/header" .}}

{{.i18n.Tr "repo.resources"}}

-
+
{{$.RenderedResources | Str2html}}
{{$.TransformedTrustProps}}
diff --git a/web_src/js/markup/trust_props.js b/web_src/js/markup/trust_props.js index eb5169e205..7be7c22bfa 100644 --- a/web_src/js/markup/trust_props.js +++ b/web_src/js/markup/trust_props.js @@ -1,7 +1,7 @@ export function initMarkupTrustProps() { - const renderSearchLink = (trustPropName) => { + const renderSearchLink = (trustPropName, trustPropType) => { const safeName = trustPropName.replace(' ', '+'); - return` найти`; + return` найти`; } $('.trust-props input[type="checkbox"]').click((e) => { @@ -9,7 +9,9 @@ export function initMarkupTrustProps() { $(e.target).parent().find('a').remove(); } else { const $parent = $(e.target).parent(); - const renderedSearchLink = renderSearchLink($parent.text()); + const $listContainer = $parent.parents("div.render-content"); + const trustPropType = $listContainer.attr("data-trust-prop-type"); + const renderedSearchLink = renderSearchLink($parent.text(), trustPropType); $parent.append(renderedSearchLink); } }); From aa6d260ca121d18b4b31b5647d708ce41bf3beb6 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 7 Nov 2022 15:10:48 +0500 Subject: [PATCH 8/8] =?UTF-8?q?=D0=9E=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D1=86?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B=20=D0=B4=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20?= =?UTF-8?q?=D1=8F=D0=B2=D0=BD=D0=BE=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/trust_props/trust_props.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/services/trust_props/trust_props.go b/services/trust_props/trust_props.go index 9f635f4b97..c7317c86ac 100644 --- a/services/trust_props/trust_props.go +++ b/services/trust_props/trust_props.go @@ -7,7 +7,6 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" "reflect" "regexp" - "strings" ) func SaveRepoAndRenderContent(ctx *context.Context, colName string) (string, error) { @@ -28,7 +27,13 @@ func SaveRepoAndRenderContent(ctx *context.Context, colName string) (string, err if err != nil { return "", err } - fieldName := upCase(colName) + + fieldNames := map[string]string{ + "resources": "Resources", + "competences": "Competences", + } + + fieldName := fieldNames[colName] reflectedRepo := reflect.ValueOf(repo) reflectedRepo.Elem().FieldByName(fieldName).SetString(trimmedToggledContent) err = repo_model.UpdateRepositoryCols(repo, colName) @@ -40,19 +45,10 @@ func SaveRepoAndRenderContent(ctx *context.Context, colName string) (string, err } func trimSearchLinks(content string) (string, error) { - regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) + regExp, err := regexp.Compile(`\s+\[найти\]\(.+\s*\)`) if err != nil { return "", err } trimmedSearchLink := regExp.ReplaceAllString(content, "") return trimmedSearchLink, nil } - -func upCase(str string) string { - ch := rune(str[0]) - ch -= 'a' - 'A' - var upCasedSB strings.Builder - upCasedSB.WriteRune(ch) - upCasedSB.WriteString(str[1:]) - return upCasedSB.String() -}