From 1540f8c5adb72972c75929e7fde1f89df67d409d Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 14 Sep 2022 18:07:15 +0500 Subject: [PATCH 01/11] =?UTF-8?q?=D0=9F=D1=80=D0=B8=20=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20=D1=83=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=D0=BE=D0=B1?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D1=8B=D0=B5=20=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=83=D1=80=D1=81=D1=8B=20=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF?= =?UTF-8?q?=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B8=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/migrations/migrations.go | 2 ++ models/migrations/v212.go | 28 ++++++++++++++++++++++++++++ models/repo/repo.go | 2 ++ options/locale/locale_ru-RU.ini | 2 ++ routers/web/repo/setting.go | 2 ++ services/forms/repo_form.go | 2 ++ templates/repo/settings/options.tmpl | 8 ++++++++ 7 files changed, 46 insertions(+) create mode 100644 models/migrations/v212.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4e27af4d73..9036c4489b 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -375,6 +375,8 @@ var migrations = []Migration{ NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials), // v211 -> v212 NewMigration("add competences, resources, interests to user tbl", addTrustedPropsToUser), + // v212 -> v213 + NewMigration("add competences and resources to repo tbl", addTrustedPropsToRepo), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v212.go b/models/migrations/v212.go new file mode 100644 index 0000000000..bec9d021ea --- /dev/null +++ b/models/migrations/v212.go @@ -0,0 +1,28 @@ +package migrations + +import ( + "fmt" + "xorm.io/xorm" + "xorm.io/xorm/schemas" +) + +func addTrustedPropsToRepo(engine *xorm.Engine) error { + var err error + tableName := "repository" + switch engine.Dialect().URI().DBType { + case schemas.POSTGRES: + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN competences TEXT, ADD COLUMN resources TEXT;", tableName) + _, err = engine.Exec(addColsQuery) + case schemas.SQLITE: + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN competences TEXT;\nALTER TABLE \"%s\" ADD COLUMN resources TEXT;", tableName, tableName) + _, err = engine.Exec(addColsQuery) + case schemas.MYSQL: + addColsQuery := fmt.Sprintf("ALTER TABLE `%s` ADD COLUMN competences TEXT, ADD COLUMN resources TEXT;", tableName) + _, err = engine.Exec(addColsQuery) + } + if err != nil { + return fmt.Errorf("Ошибка добавления колонок компетенции и ресурсы в проект: %v", err) + } else { + return nil + } +} diff --git a/models/repo/repo.go b/models/repo/repo.go index 5108231cd8..13108dfae8 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -100,6 +100,8 @@ type Repository struct { LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` Description string `xorm:"TEXT"` + Resources string `xorm:"TEXT"` + Competences string `xorm:"TEXT"` Website string `xorm:"VARCHAR(2048)"` OriginalServiceType api.GitServiceType `xorm:"index"` OriginalURL string `xorm:"VARCHAR(2048)"` diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index 4bc3f3faf8..f073f5997e 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -804,6 +804,8 @@ download_bundle=Скачать BUNDLE generate_repo=Создать проект generate_from=Создать из repo_desc=Описание +resources=Необходимые ресурсы +competences=Необходимые компетенции repo_desc_helper=Добавьте краткое описание (необязательно) repo_lang=Язык repo_gitignore_helper=Выберите шаблон .gitignore. diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index f0548aaffe..37dc4b3e99 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -151,6 +151,8 @@ func SettingsPost(ctx *context.Context) { repo.Name = newRepoName repo.LowerName = strings.ToLower(newRepoName) repo.Description = form.Description + repo.Resources = form.Resources + repo.Competences = form.Competences repo.Website = form.Website repo.IsTemplate = form.Template diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 550375bd7a..92cd82a1bf 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -115,6 +115,8 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err type RepoSettingForm struct { RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` Description string `binding:"MaxSize(255)"` + Resources string `binding:"MaxSize(1024)"` + Competences string `binding:"MaxSize(1024)"` Website string `binding:"ValidUrl;MaxSize(255)"` Interval string MirrorAddress string diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 2dc4ce17c6..f2adec149c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -44,6 +44,14 @@ +
+ + +
+
+ + +
From dc2e63eeefb89556ae646994b2960910ec50316a Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 14 Sep 2022 18:42:31 +0500 Subject: [PATCH 02/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20#15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/migrations/migrations.go | 2 ++ models/migrations/v213.go | 28 ++++++++++++++++++++++++++++ models/repo/repo.go | 1 + options/locale/locale_ru-RU.ini | 1 + routers/web/repo/setting.go | 1 + services/forms/repo_form.go | 1 + templates/repo/settings/options.tmpl | 4 ++++ 7 files changed, 38 insertions(+) create mode 100644 models/migrations/v213.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 9036c4489b..8692db26ac 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -377,6 +377,8 @@ var migrations = []Migration{ NewMigration("add competences, resources, interests to user tbl", addTrustedPropsToUser), // v212 -> v213 NewMigration("add competences and resources to repo tbl", addTrustedPropsToRepo), + // v213 -> v214 + NewMigration("add location_coordinate to repo tbl", addLocationCoordinateToRepo), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v213.go b/models/migrations/v213.go new file mode 100644 index 0000000000..0bc3adcabe --- /dev/null +++ b/models/migrations/v213.go @@ -0,0 +1,28 @@ +package migrations + +import ( + "fmt" + "xorm.io/xorm" + "xorm.io/xorm/schemas" +) + +func addLocationCoordinateToRepo(engine *xorm.Engine) error { + var err error + tableName := "repository" + switch engine.Dialect().URI().DBType { + case schemas.POSTGRES: + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinate VARCHAR(20);", tableName) + _, err = engine.Exec(addColsQuery) + case schemas.SQLITE: + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinate TEXT;", tableName) + _, err = engine.Exec(addColsQuery) + case schemas.MYSQL: + addColsQuery := fmt.Sprintf("ALTER TABLE `%s` ADD COLUMN location_coordinate VARCHAR(20);", tableName) + _, err = engine.Exec(addColsQuery) + } + if err != nil { + return fmt.Errorf("Ошибка добавления колонок компетенции и ресурсы в проект: %v", err) + } else { + return nil + } +} diff --git a/models/repo/repo.go b/models/repo/repo.go index 13108dfae8..52c51d545a 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -103,6 +103,7 @@ type Repository struct { Resources string `xorm:"TEXT"` Competences string `xorm:"TEXT"` Website string `xorm:"VARCHAR(2048)"` + LocationCoordinate string `xorm:"VARCHAR(20)"` OriginalServiceType api.GitServiceType `xorm:"index"` OriginalURL string `xorm:"VARCHAR(2048)"` DefaultBranch string diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index f073f5997e..09643754b4 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -1719,6 +1719,7 @@ settings.email_notifications.onmention=Посылать письмо на эл. settings.email_notifications.disable=Отключить почтовые уведомления settings.email_notifications.submit=Установить настройки электронной почты settings.site=Сайт +settings.location_coordinate=Координаты settings.update_settings=Обновить настройки settings.branches.update_default_branch=Обновить ветку по умолчанию settings.advanced_settings=Расширенные настройки diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 37dc4b3e99..d0d3cde190 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -154,6 +154,7 @@ func SettingsPost(ctx *context.Context) { repo.Resources = form.Resources repo.Competences = form.Competences repo.Website = form.Website + repo.LocationCoordinate = form.LocationCoordinate repo.IsTemplate = form.Template // Visibility of forked repository is forced sync with base repository. diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 92cd82a1bf..c11b0f6edd 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -118,6 +118,7 @@ type RepoSettingForm struct { Resources string `binding:"MaxSize(1024)"` Competences string `binding:"MaxSize(1024)"` Website string `binding:"ValidUrl;MaxSize(255)"` + LocationCoordinate string Interval string MirrorAddress string MirrorUsername string diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index f2adec149c..dd9973f73f 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -56,6 +56,10 @@
+
+ + +
From 23e8063895243065af67d1267e5b5034e89c9c5f Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 15 Sep 2022 18:49:06 +0500 Subject: [PATCH 03/11] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= =?UTF-8?q?=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit если таковые имеются --- options/locale/locale_ru-RU.ini | 4 ++-- routers/web/repo/competence.go | 15 +++++++++++++++ routers/web/repo/resource.go | 15 +++++++++++++++ routers/web/web.go | 2 ++ templates/repo/competences/list.tmpl | 1 + templates/repo/header.tmpl | 16 ++++++++++++++-- templates/repo/resources/list.tmpl | 1 + 7 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 routers/web/repo/competence.go create mode 100644 routers/web/repo/resource.go create mode 100644 templates/repo/competences/list.tmpl create mode 100644 templates/repo/resources/list.tmpl diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index 09643754b4..eec461d65a 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -804,8 +804,8 @@ download_bundle=Скачать BUNDLE generate_repo=Создать проект generate_from=Создать из repo_desc=Описание -resources=Необходимые ресурсы -competences=Необходимые компетенции +resources=Ресурсы +competences=Компетенции repo_desc_helper=Добавьте краткое описание (необязательно) repo_lang=Язык repo_gitignore_helper=Выберите шаблон .gitignore. diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go new file mode 100644 index 0000000000..14fa178ccd --- /dev/null +++ b/routers/web/repo/competence.go @@ -0,0 +1,15 @@ +package repo + +import ( + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/context" + "net/http" +) + +const ( + tplCompetences base.TplName = "repo/competences/list" +) + +func Competences(ctx *context.Context) { + ctx.HTML(http.StatusOK, tplCompetences) +} diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go new file mode 100644 index 0000000000..95e75c0818 --- /dev/null +++ b/routers/web/repo/resource.go @@ -0,0 +1,15 @@ +package repo + +import ( + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/context" + "net/http" +) + +const ( + tplResources base.TplName = "repo/resources/list" +) + +func Resources(ctx *context.Context) { + ctx.HTML(http.StatusOK, tplResources) +} diff --git a/routers/web/web.go b/routers/web/web.go index 171d5c0e81..1e0937671e 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -890,6 +890,8 @@ func RegisterRoutes(m *web.Route) { m.Group("", func() { m.Get("/{type:issues|pulls}", repo.Issues) m.Get("/issues_tree", repo.IssuesTree) + m.Get("/resources", repo.Resources) + m.Get("/competences", repo.Competences) m.Get("/{type:issues|pulls}/{index}", repo.ViewIssue) m.Group("/{type:issues|pulls}/{index}/content-history", func() { m.Get("/overview", repo.GetContentHistoryOverview) diff --git a/templates/repo/competences/list.tmpl b/templates/repo/competences/list.tmpl new file mode 100644 index 0000000000..15bd99afda --- /dev/null +++ b/templates/repo/competences/list.tmpl @@ -0,0 +1 @@ +

Competences

diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 4948d90379..7221d7ac88 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -152,7 +152,7 @@ {{svg "octicon-book"}} {{.i18n.Tr "repo.wiki"}} {{end}} - + {{if .Permission.CanRead $.UnitTypeIssues}} {{svg "octicon-issue-opened"}} {{.i18n.Tr "repo.issues"}} @@ -162,6 +162,18 @@ {{end}} + {{if .Repository.Resources}} + + {{svg "octicon-briefcase"}} {{.i18n.Tr "repo.resources"}} + + {{end}} + + {{if .Repository.Competences}} + + {{svg "octicon-multi-select"}} {{.i18n.Tr "repo.competences"}} + + {{end}} + {{if .Permission.CanRead $.UnitTypeExternalTracker}} {{svg "octicon-link-external"}} {{.i18n.Tr "repo.issues"}} @@ -176,7 +188,7 @@ {{end}} {{ end }} - + {{if .Permission.CanRead $.UnitTypeCode}} {{svg "octicon-code"}} {{.i18n.Tr "repo.code"}} diff --git a/templates/repo/resources/list.tmpl b/templates/repo/resources/list.tmpl new file mode 100644 index 0000000000..81f8fc8e69 --- /dev/null +++ b/templates/repo/resources/list.tmpl @@ -0,0 +1 @@ +

Resources

From ff3b56acd217ae7217d5244f5b3a4c593b8c6921 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 15 Sep 2022 19:16:20 +0500 Subject: [PATCH 04/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=91=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B4=D0=BE=D0=B2=D0=B5=D1=80=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B0=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/competence.go | 12 ++++++++++++ routers/web/repo/resource.go | 12 ++++++++++++ routers/web/user/profile.go | 8 ++++---- templates/repo/competences/list.tmpl | 12 +++++++++++- templates/repo/resources/list.tmpl | 12 +++++++++++- 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 14fa178ccd..fb97c86b8a 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/routers/web/user" "net/http" ) @@ -11,5 +12,16 @@ const ( ) func Competences(ctx *context.Context) { + ctx.Data["PageIsCompetences"] = true + repo := ctx.Data["Repository"] + + var err error + ctx.Data["RenderedCompetences"], err = user.GetRenderedTextField(ctx, repo, "Competences") + + if err != nil { + ctx.ServerError("Render", err) + return + } + ctx.HTML(http.StatusOK, tplCompetences) } diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index 95e75c0818..fbc825cdc4 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -3,6 +3,7 @@ package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/routers/web/user" "net/http" ) @@ -11,5 +12,16 @@ const ( ) func Resources(ctx *context.Context) { + ctx.Data["PageIsResources"] = true + repo := ctx.Data["Repository"] + + var err error + ctx.Data["RenderedResources"], err = user.GetRenderedTextField(ctx, repo, "Resources") + + if err != nil { + ctx.ServerError("Render", err) + return + } + ctx.HTML(http.StatusOK, tplResources) } diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 90fafb871e..8cdfac9578 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -402,16 +402,16 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.FormString("redirect_to"), u.HomeLink()) } -func getTextField(user interface{}, fieldName string) string { - reflectedObj := reflect.ValueOf(user) +func getTextField(obj interface{}, fieldName string) string { + reflectedObj := reflect.ValueOf(obj) dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) return dynamicField.String() } -func GetRenderedTextField(ctx *context.Context, ctxUser interface{}, fieldName string) (string, error) { +func GetRenderedTextField(ctx *context.Context, obj interface{}, fieldName string) (string, error) { var err error = nil var content string - fieldVal := getTextField(ctxUser, fieldName) + fieldVal := getTextField(obj, fieldName) if len(fieldVal) != 0 { content, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, diff --git a/templates/repo/competences/list.tmpl b/templates/repo/competences/list.tmpl index 15bd99afda..8fa2c9cb8a 100644 --- a/templates/repo/competences/list.tmpl +++ b/templates/repo/competences/list.tmpl @@ -1 +1,11 @@ -

Competences

+{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+

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

+
+ {{$.RenderedCompetences | Str2html}} +
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/resources/list.tmpl b/templates/repo/resources/list.tmpl index 81f8fc8e69..125cb62d85 100644 --- a/templates/repo/resources/list.tmpl +++ b/templates/repo/resources/list.tmpl @@ -1 +1,11 @@ -

Resources

+{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+

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

+
+ {{$.RenderedResources | Str2html}} +
+
+
+{{template "base/footer" .}} From c1c130ae34dc3a265f4ea1f0d348ebf37ce78555 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 16 Sep 2022 16:24:24 +0500 Subject: [PATCH 05/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=D1=81=D0=BE?= =?UTF-8?q?=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=BE=D0=B9=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BB=D0=B8=D1=86=20=D1=81=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=20=D1=80=D0=B5=D1=81=D1=83?= =?UTF-8?q?=D1=80=D1=81=D0=BE=D0=BC=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/explore/user.go | 2 +- routers/web/repo/competence.go | 2 +- routers/web/repo/resource.go | 27 ++++++++++++++++++++++++++- routers/web/user/profile.go | 22 +++++++++++++++------- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index cecb4578eb..0dcf638bcd 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -92,7 +92,7 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, contentFieldName = "Description" } for _, curUser := range users { - renderedContent[curUser.ID], err = user.GetRenderedTextField(ctx, curUser, contentFieldName) + renderedContent[curUser.ID], err = user.GetRenderedTextFieldByName(ctx, curUser, contentFieldName) if err != nil { ctx.ServerError("RenderContent", err) return diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index fb97c86b8a..4282698ce7 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -16,7 +16,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = user.GetRenderedTextField(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], err = user.GetRenderedTextFieldByName(ctx, repo, "Competences") if err != nil { ctx.ServerError("Render", err) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index fbc825cdc4..1aac28328b 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -4,7 +4,9 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" + "errors" "net/http" + "regexp" ) const ( @@ -16,7 +18,7 @@ func Resources(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedResources"], err = user.GetRenderedTextField(ctx, repo, "Resources") + ctx.Data["RenderedResources"], err = getRenderedResourcesWithSearchLinks(ctx, repo) if err != nil { ctx.ServerError("Render", err) @@ -25,3 +27,26 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } + +func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) (string, error) { + resources := user.GetTextField(repo, "Resources") + + var regExp *regexp.Regexp + var err error + + regExp, err = regexp.Compile(`- \[ \] (.+)`) + if err != nil { + return "", err + } + + resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(`- \[ \] $1 [найти](/explore/resources?tab=&q=$1)`)) + + if resourcesWithLinks == nil { + return "", errors.New("not found matches in resources") + } + + var renderedResourcesWithLinks string + renderedResourcesWithLinks, err = user.GetRenderedTextFieldByValue(ctx, repo, string(resourcesWithLinks)) + + return renderedResourcesWithLinks, err +} diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 8cdfac9578..04201fcb88 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -164,7 +164,7 @@ func Profile(ctx *context.Context) { content string ) - content, renderErr = GetRenderedTextField(ctx, ctxUser, "Description") + content, renderErr = GetRenderedTextFieldByName(ctx, ctxUser, "Description") if renderErr == nil { ctx.Data["RenderedDescription"] = content } else { @@ -172,7 +172,7 @@ func Profile(ctx *context.Context) { return } - content, renderErr = GetRenderedTextField(ctx, ctxUser, "Competences") + content, renderErr = GetRenderedTextFieldByName(ctx, ctxUser, "Competences") if renderErr == nil { ctx.Data["RenderedCompetences"] = content } else { @@ -180,7 +180,7 @@ func Profile(ctx *context.Context) { return } - content, renderErr = GetRenderedTextField(ctx, ctxUser, "Resources") + content, renderErr = GetRenderedTextFieldByName(ctx, ctxUser, "Resources") if renderErr == nil { ctx.Data["RenderedResources"] = content } else { @@ -188,7 +188,7 @@ func Profile(ctx *context.Context) { return } - content, renderErr = GetRenderedTextField(ctx, ctxUser, "Interests") + content, renderErr = GetRenderedTextFieldByName(ctx, ctxUser, "Interests") if renderErr == nil { ctx.Data["RenderedInterests"] = content } else { @@ -402,16 +402,24 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.FormString("redirect_to"), u.HomeLink()) } -func getTextField(obj interface{}, fieldName string) string { +func GetTextField(obj interface{}, fieldName string) string { reflectedObj := reflect.ValueOf(obj) dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) return dynamicField.String() } -func GetRenderedTextField(ctx *context.Context, obj interface{}, fieldName string) (string, error) { +func GetRenderedTextFieldByName(ctx *context.Context, obj interface{}, fieldName string) (string, error) { var err error = nil var content string - fieldVal := getTextField(obj, fieldName) + fieldVal := GetTextField(obj, fieldName) + content, err = GetRenderedTextFieldByValue(ctx, obj, fieldVal) + return content, err +} + +func GetRenderedTextFieldByValue(ctx *context.Context, obj interface{}, fieldVal string) (string, error) { + var content string + var err error + if len(fieldVal) != 0 { content, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, From b76fbf7d15d23fc65a2f366907bdb6b44e102821 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 16 Sep 2022 16:48:42 +0500 Subject: [PATCH 06/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=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=D1=81=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D0=B8=D1=81=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B8=D1=85=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/competence.go | 3 +-- routers/web/repo/resource.go | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 4282698ce7..1c33a9293b 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -3,7 +3,6 @@ package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/routers/web/user" "net/http" ) @@ -16,7 +15,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = user.GetRenderedTextFieldByName(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences") if err != nil { ctx.ServerError("Render", err) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index 1aac28328b..d0e5ea569d 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -5,8 +5,10 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" "errors" + "fmt" "net/http" "regexp" + "strings" ) const ( @@ -18,7 +20,7 @@ func Resources(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedResources"], err = getRenderedResourcesWithSearchLinks(ctx, repo) + ctx.Data["RenderedResources"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) @@ -28,8 +30,8 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) (string, error) { - resources := user.GetTextField(repo, "Resources") +func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { + resources := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp var err error @@ -39,7 +41,8 @@ func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) 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 { return "", errors.New("not found matches in resources") From da59f8af8d6bff50753ce544f07d9ce2b77831d0 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 16 Sep 2022 21:49:03 +0500 Subject: [PATCH 07/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=B4=D0=BD=D1=8B=D0=B9=20=D1=81=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B0=D0=B9,=20=D0=BA=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=B2?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B0=20=D0=B5=D1=81=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D0=B5=D0=BB=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit трудность в том, что нужно учесть это в URL. Сделать путём регулярных выражений НЕ получилось. Т.к. непонятно, как сделать глобальную замену содержимого обратных ссылок. --- routers/web/repo/resource.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index d0e5ea569d..b056c70048 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -4,7 +4,6 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" - "errors" "fmt" "net/http" "regexp" @@ -41,15 +40,29 @@ func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, return "", err } - resourceSubstitutionPattern := fmt.Sprintf(`- \[ \] $1 [найти](/explore/%s?tab=&q=$1)`, strings.ToLower(fieldName)) - resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(resourceSubstitutionPattern)) + resourceNamesMatches := regExp.FindAllStringSubmatch(resources, -1) + if resourceNamesMatches == nil { + return "", err + } + + var resourcesWithSafeURLs = strings.Clone(resources) + var resourceName string + var searchQS string + + for _, matches := range resourceNamesMatches { + resourceName = matches[1] + searchQS = strings.ReplaceAll(resourceName, " ", "+") + resourceSubstitutionPattern := fmt.Sprintf( + `- \[ \] %s [найти](/explore/%s?tab=&q=%s)`, + resourceName, + strings.ToLower(fieldName), + searchQS) - if resourcesWithLinks == nil { - return "", errors.New("not found matches in resources") + resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceName, resourceSubstitutionPattern, -1) } - var renderedResourcesWithLinks string - renderedResourcesWithLinks, err = user.GetRenderedTextFieldByValue(ctx, repo, string(resourcesWithLinks)) + var renderedResourcesWithSafeURLs string + renderedResourcesWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, resourcesWithSafeURLs) - return renderedResourcesWithLinks, err + return renderedResourcesWithSafeURLs, err } From 05f5c04461dc97880e23295531c64a6bc156143e Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 16 Sep 2022 22:00:15 +0500 Subject: [PATCH 08/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=BB=D0=BE=D1=81=D1=8C=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=B2=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D1=81=D1=83=D1=80=D1=81=D0=B0=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/resource.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index b056c70048..29fa57f164 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -49,16 +49,16 @@ func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, var resourceName string var searchQS string - for _, matches := range resourceNamesMatches { - resourceName = matches[1] + for _, resourceNameMatches := range resourceNamesMatches { + resourceName = resourceNameMatches[1] searchQS = strings.ReplaceAll(resourceName, " ", "+") resourceSubstitutionPattern := fmt.Sprintf( - `- \[ \] %s [найти](/explore/%s?tab=&q=%s)`, + `- [ ] %s [найти](/explore/%s?tab=&q=%s)`, resourceName, strings.ToLower(fieldName), searchQS) - resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceName, resourceSubstitutionPattern, -1) + resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceNameMatches[0], resourceSubstitutionPattern, -1) } var renderedResourcesWithSafeURLs string From f77d73c83adf2bdd2380d5ba08e076c1d46cfaec Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 19 Sep 2022 17:10:08 +0500 Subject: [PATCH 09/11] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA=20=D0=B4=D0=BE=D0=B2=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B2=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B5=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit также выполнен рефакторинг, т.к. метод вызывается и для компетенций, и для ресурсов. --- routers/web/repo/competence.go | 2 +- routers/web/repo/resource.go | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 1c33a9293b..5562482324 100644 --- a/routers/web/repo/competence.go +++ b/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) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index 29fa57f164..2499cc0d04 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 = 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, " Date: Tue, 20 Sep 2022 16:06:41 +0500 Subject: [PATCH 10/11] =?UTF-8?q?=D0=9A=D0=BE=D0=BE=D1=80=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=BE=D0=B3=D1=83=D1=82=20=D1=81=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=B0=D1=82=D1=8C=20=D0=BC=D0=BD=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B2=D0=BE=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20#65=20#120?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/migrations/v213.go | 6 +++--- models/repo/repo.go | 2 +- options/locale/locale_ru-RU.ini | 2 +- routers/web/repo/setting.go | 2 +- services/forms/repo_form.go | 40 ++++++++++++++++++------------------ templates/repo/settings/options.tmpl | 6 +++--- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/models/migrations/v213.go b/models/migrations/v213.go index 0bc3adcabe..f11a0e3387 100644 --- a/models/migrations/v213.go +++ b/models/migrations/v213.go @@ -11,13 +11,13 @@ func addLocationCoordinateToRepo(engine *xorm.Engine) error { tableName := "repository" switch engine.Dialect().URI().DBType { case schemas.POSTGRES: - addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinate VARCHAR(20);", tableName) + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinates VARCHAR(1024);", tableName) _, err = engine.Exec(addColsQuery) case schemas.SQLITE: - addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinate TEXT;", tableName) + addColsQuery := fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN location_coordinates TEXT;", tableName) _, err = engine.Exec(addColsQuery) case schemas.MYSQL: - addColsQuery := fmt.Sprintf("ALTER TABLE `%s` ADD COLUMN location_coordinate VARCHAR(20);", tableName) + addColsQuery := fmt.Sprintf("ALTER TABLE `%s` ADD COLUMN location_coordinates VARCHAR(1024);", tableName) _, err = engine.Exec(addColsQuery) } if err != nil { diff --git a/models/repo/repo.go b/models/repo/repo.go index 52c51d545a..1ffabd6391 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -103,7 +103,7 @@ type Repository struct { Resources string `xorm:"TEXT"` Competences string `xorm:"TEXT"` Website string `xorm:"VARCHAR(2048)"` - LocationCoordinate string `xorm:"VARCHAR(20)"` + LocationCoordinates string `xorm:"VARCHAR(1024)"` OriginalServiceType api.GitServiceType `xorm:"index"` OriginalURL string `xorm:"VARCHAR(2048)"` DefaultBranch string diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index eec461d65a..77530587e7 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -1719,7 +1719,7 @@ settings.email_notifications.onmention=Посылать письмо на эл. settings.email_notifications.disable=Отключить почтовые уведомления settings.email_notifications.submit=Установить настройки электронной почты settings.site=Сайт -settings.location_coordinate=Координаты +settings.location_coordinates=Координаты settings.update_settings=Обновить настройки settings.branches.update_default_branch=Обновить ветку по умолчанию settings.advanced_settings=Расширенные настройки diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index d0d3cde190..184ddace6d 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -154,7 +154,7 @@ func SettingsPost(ctx *context.Context) { repo.Resources = form.Resources repo.Competences = form.Competences repo.Website = form.Website - repo.LocationCoordinate = form.LocationCoordinate + repo.LocationCoordinates = form.LocationCoordinates repo.IsTemplate = form.Template // Visibility of forked repository is forced sync with base repository. diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c11b0f6edd..76fc3f17c9 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -113,26 +113,26 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err // RepoSettingForm form for changing repository settings type RepoSettingForm struct { - RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` - Description string `binding:"MaxSize(255)"` - Resources string `binding:"MaxSize(1024)"` - Competences string `binding:"MaxSize(1024)"` - Website string `binding:"ValidUrl;MaxSize(255)"` - LocationCoordinate string - Interval string - MirrorAddress string - MirrorUsername string - MirrorPassword string - LFS bool `form:"mirror_lfs"` - LFSEndpoint string `form:"mirror_lfs_endpoint"` - PushMirrorID string - PushMirrorAddress string - PushMirrorUsername string - PushMirrorPassword string - PushMirrorInterval string - Private bool - Template bool - EnablePrune bool + RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` + Description string `binding:"MaxSize(255)"` + Resources string `binding:"MaxSize(1024)"` + Competences string `binding:"MaxSize(1024)"` + Website string `binding:"ValidUrl;MaxSize(255)"` + LocationCoordinates string `binding:"MaxSize(1024)"` + Interval string + MirrorAddress string + MirrorUsername string + MirrorPassword string + LFS bool `form:"mirror_lfs"` + LFSEndpoint string `form:"mirror_lfs_endpoint"` + PushMirrorID string + PushMirrorAddress string + PushMirrorUsername string + PushMirrorPassword string + PushMirrorInterval string + Private bool + Template bool + EnablePrune bool // Advanced settings EnableWiki bool diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index dd9973f73f..85e3855d3e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -56,9 +56,9 @@
-
- - +
+ +
From d8a9c5e12b18cb99f5f4e798ee00f43e8db32722 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Tue, 20 Sep 2022 19:09:37 +0500 Subject: [PATCH 11/11] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B9=20=D0=B8=20=D1=80=D0=B5?= =?UTF-8?q?=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=20#65=20#120?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit исправлен баг, что НЕ выводилось содержимое доверительного свойства, если нет ни одной галочки. Если нет галочек, значит, и доверительных свойств нет. Но пользователю это непонятно. Поэтому принято пока такое архитектурное решение, выводить содержимое без галочек. --- routers/web/repo/resource.go | 34 ++++++++++++++++++---------------- services/forms/repo_form.go | 4 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index 2499cc0d04..bcf7f76595 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -41,28 +41,30 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} } trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) - if trustPropNamesMatches == nil { - return "", err - } - var trustPropsWithSafeURLs = strings.Clone(trustProps) - var trustPropName string - var searchQS string + var transformedTrustProps string + if trustPropNamesMatches == nil { + transformedTrustProps = trustProps + } else { + transformedTrustProps = strings.Clone(trustProps) + var trustPropName string + var searchQS string - for _, trustPropNameMatches := range trustPropNamesMatches { - trustPropName = trustPropNameMatches[1] - searchQS = strings.ReplaceAll(trustPropName, " ", "+") - trustPropSubstitutionPattern := fmt.Sprintf( - `- [ ] %s [найти](/explore/%s?tab=&q=%s)`, - trustPropName, - strings.ToLower(fieldName), - searchQS) + for _, curTrustPropNameMatches := range trustPropNamesMatches { + trustPropName = curTrustPropNameMatches[1] + searchQS = strings.ReplaceAll(trustPropName, " ", "+") + trustPropSubstitutionPattern := fmt.Sprintf( + `- [ ] %s [найти](/explore/%s?tab=&q=%s)`, + trustPropName, + strings.ToLower(fieldName), + searchQS) - trustPropsWithSafeURLs = strings.Replace(trustPropsWithSafeURLs, trustPropNameMatches[0], trustPropSubstitutionPattern, -1) + transformedTrustProps = strings.Replace(transformedTrustProps, curTrustPropNameMatches[0], trustPropSubstitutionPattern, -1) + } } var renderedTrustPropsWithSafeURLs string - renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, trustPropsWithSafeURLs) + renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "