diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4e27af4d73..8692db26ac 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -375,6 +375,10 @@ 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), + // v213 -> v214 + NewMigration("add location_coordinate to repo tbl", addLocationCoordinateToRepo), } // 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/migrations/v213.go b/models/migrations/v213.go new file mode 100644 index 0000000000..f11a0e3387 --- /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_coordinates VARCHAR(1024);", tableName) + _, err = engine.Exec(addColsQuery) + case schemas.SQLITE: + 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_coordinates VARCHAR(1024);", 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..1ffabd6391 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -100,7 +100,10 @@ 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)"` + 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 4bc3f3faf8..77530587e7 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. @@ -1717,6 +1719,7 @@ settings.email_notifications.onmention=Посылать письмо на эл. settings.email_notifications.disable=Отключить почтовые уведомления settings.email_notifications.submit=Установить настройки электронной почты settings.site=Сайт +settings.location_coordinates=Координаты settings.update_settings=Обновить настройки settings.branches.update_default_branch=Обновить ветку по умолчанию settings.advanced_settings=Расширенные настройки 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 new file mode 100644 index 0000000000..5562482324 --- /dev/null +++ b/routers/web/repo/competence.go @@ -0,0 +1,26 @@ +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.Data["PageIsCompetences"] = true + repo := ctx.Data["Repository"] + + var err error + ctx.Data["RenderedCompetences"], err = GetRenderedTrustPropsWithSearchLinks(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 new file mode 100644 index 0000000000..bcf7f76595 --- /dev/null +++ b/routers/web/repo/resource.go @@ -0,0 +1,70 @@ +package repo + +import ( + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/routers/web/user" + "fmt" + "net/http" + "regexp" + "strings" +) + +const ( + tplResources base.TplName = "repo/resources/list" +) + +func Resources(ctx *context.Context) { + ctx.Data["PageIsResources"] = true + repo := ctx.Data["Repository"] + + var err error + ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") + + if err != nil { + ctx.ServerError("Render", err) + return + } + + ctx.HTML(http.StatusOK, tplResources) +} + +func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { + trustProps := user.GetTextField(repo, fieldName) + + var regExp *regexp.Regexp + var err error + + regExp, err = regexp.Compile(`- \[ \] (.+)`) + if err != nil { + return "", err + } + + trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) + + var transformedTrustProps string + if trustPropNamesMatches == nil { + transformedTrustProps = trustProps + } else { + transformedTrustProps = strings.Clone(trustProps) + var trustPropName string + var searchQS string + + 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) + + transformedTrustProps = strings.Replace(transformedTrustProps, curTrustPropNameMatches[0], trustPropSubstitutionPattern, -1) + } + } + + var renderedTrustPropsWithSafeURLs string + renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) + renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, " + {{template "repo/header" .}} +
+

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

+
+ {{$.RenderedCompetences | Str2html}} +
+
+ +{{template "base/footer" .}} 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..125cb62d85 --- /dev/null +++ b/templates/repo/resources/list.tmpl @@ -0,0 +1,11 @@ +{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+

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

+
+ {{$.RenderedResources | Str2html}} +
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 2dc4ce17c6..85e3855d3e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -44,10 +44,22 @@ +
+ + +
+
+ + +
+
+ + +