Browse Source
Указывать для проекта доверительные свойства и находить подходящие лица #65 Reviewed-on: http://git.mirocod.ru/MIROCOD/Platform_Mirocod/pulls/120 Reviewed-by: Алексей Безбородов <alexeibv+mirocod@narod.ru>dev_mirocod
Алексей Безбородов
2 years ago
16 changed files with 252 additions and 28 deletions
@ -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 |
||||
} |
||||
} |
@ -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 |
||||
} |
||||
} |
@ -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) |
||||
} |
@ -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, "<a", "<a target='blank'") |
||||
return renderedTrustPropsWithTargetBlank, err |
||||
} |
@ -0,0 +1,11 @@
|
||||
{{template "base/head" .}} |
||||
<div class="page-content repository"> |
||||
{{template "repo/header" .}} |
||||
<div class="ui container"> |
||||
<h1>{{.i18n.Tr "repo.competences"}}</h1> |
||||
<div> |
||||
{{$.RenderedCompetences | Str2html}} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{{template "base/footer" .}} |
@ -0,0 +1,11 @@
|
||||
{{template "base/head" .}} |
||||
<div class="page-content repository"> |
||||
{{template "repo/header" .}} |
||||
<div class="ui container"> |
||||
<h1>{{.i18n.Tr "repo.resources"}}</h1> |
||||
<div> |
||||
{{$.RenderedResources | Str2html}} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{{template "base/footer" .}} |
Loading…
Reference in new issue