diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 5562482324..274f2a807d 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -3,6 +3,7 @@ package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/services/trust_props" "net/http" ) @@ -15,7 +16,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) @@ -24,3 +25,25 @@ func Competences(ctx *context.Context) { ctx.HTML(http.StatusOK, tplCompetences) } + +func ToggleCompetences(ctx *context.Context) { + if !ctx.IsSigned { + ctx.Error(http.StatusForbidden) + return + } + + toggledContent, err := trust_props.SaveRepoAndRenderContent(ctx, "competences") + if err != nil { + ctx.ServerError("ToggleCompetences", err) + return + } + + responseBody := map[string]interface{}{ + "content": toggledContent, + } + + ctx.JSON( + http.StatusOK, + responseBody, + ) +} diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index bcf7f76595..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" @@ -19,7 +20,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 +30,29 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { +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) var regExp *regexp.Regexp @@ -37,7 +60,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 +89,5 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} var renderedTrustPropsWithSafeURLs string renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "

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

-
+
{{$.RenderedCompetences | Str2html}}
+
{{$.TransformedTrustProps}}
+
{{template "base/footer" .}} diff --git a/templates/repo/resources/list.tmpl b/templates/repo/resources/list.tmpl index 125cb62d85..6e827ece27 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" .}} 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..7be7c22bfa --- /dev/null +++ b/web_src/js/markup/trust_props.js @@ -0,0 +1,18 @@ +export function initMarkupTrustProps() { + const renderSearchLink = (trustPropName, trustPropType) => { + const safeName = trustPropName.replace(' ', '+'); + return` найти`; + } + + $('.trust-props input[type="checkbox"]').click((e) => { + if (e.target.checked) { + $(e.target).parent().find('a').remove(); + } else { + const $parent = $(e.target).parent(); + const $listContainer = $parent.parents("div.render-content"); + const trustPropType = $listContainer.attr("data-trust-prop-type"); + const renderedSearchLink = renderSearchLink($parent.text(), trustPropType); + $parent.append(renderedSearchLink); + } + }); +}