Browse Source

add repo unit type for cloud brain

tags/v1.21.12.1
palytoxin 5 years ago
parent
commit
ce499a28e3
9 changed files with 69 additions and 8 deletions
  1. +6
    -0
      models/repo.go
  2. +18
    -2
      models/repo_unit.go
  3. +14
    -0
      models/unit.go
  4. +1
    -0
      modules/auth/repo_form.go
  5. +1
    -0
      modules/context/repo.go
  6. +12
    -0
      routers/repo/setting.go
  7. +4
    -2
      routers/routes/routes.go
  8. +4
    -4
      templates/repo/header.tmpl
  9. +9
    -0
      templates/repo/settings/options.tmpl

+ 6
- 0
models/repo.go View File

@@ -1076,6 +1076,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error
Type: tp,
Config: &DatasetConfig{EnableDataset: true},
})
} else if tp == UnitTypeCloudBrain {
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &CloudBrainConfig{EnableCloudBrain: true},
})
} else {
units = append(units, RepoUnit{
RepoID: repo.ID,


+ 18
- 2
models/repo_unit.go View File

@@ -117,16 +117,30 @@ type DatasetConfig struct {
EnableDataset bool
}

// FromDB fills up a IssuesConfig from serialized format.
// FromDB fills up a DatasetConfig from serialized format.
func (cfg *DatasetConfig) FromDB(bs []byte) error {
return json.Unmarshal(bs, &cfg)
}

// ToDB exports a IssuesConfig to a serialized format.
// ToDB exports a DatasetConfig to a serialized format.
func (cfg *DatasetConfig) ToDB() ([]byte, error) {
return json.Marshal(cfg)
}

type CloudBrainConfig struct {
EnableCloudBrain bool
}

// FromDB fills up a CloudBrainConfig from serialized format.
func (cfg *CloudBrainConfig) FromDB(bs []byte) error {
return json.Unmarshal(bs, &cfg)
}

// ToDB exports a CloudBrainConfig to a serialized format.
func (cfg *CloudBrainConfig) ToDB() ([]byte, error) {
return json.Marshal(cfg)
}

// BeforeSet is invoked from XORM before setting the value of a field of this object.
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName {
@@ -144,6 +158,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(IssuesConfig)
case UnitTypeDatasets:
r.Config = new(DatasetConfig)
case UnitTypeCloudBrain:
r.Config = new(CloudBrainConfig)
default:
panic("unrecognized repo unit type: " + com.ToStr(*val))
}


+ 14
- 0
models/unit.go View File

@@ -25,6 +25,7 @@ const (
UnitTypeExternalWiki // 6 ExternalWiki
UnitTypeExternalTracker // 7 ExternalTracker
UnitTypeDatasets UnitType = 10 // 10 Dataset
UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain
)

// Value returns integer value for unit type
@@ -50,6 +51,8 @@ func (u UnitType) String() string {
return "UnitTypeExternalTracker"
case UnitTypeDatasets:
return "UnitTypeDataset"
case UnitTypeCloudBrain:
return "UnitTypeCloudBrain"
}
return fmt.Sprintf("Unknown UnitType %d", u)
}
@@ -72,6 +75,7 @@ var (
UnitTypeExternalWiki,
UnitTypeExternalTracker,
UnitTypeDatasets,
UnitTypeCloudBrain,
}

// DefaultRepoUnits contains the default unit types
@@ -82,6 +86,7 @@ var (
UnitTypeReleases,
UnitTypeWiki,
UnitTypeDatasets,
UnitTypeCloudBrain,
}

// NotAllowedDefaultRepoUnits contains units that can't be default
@@ -255,6 +260,14 @@ var (
5,
}

UnitCloudBrain = Unit{
UnitTypeCloudBrain,
"repo.cloudbrains",
"/cloudbrains",
"repo.cloudbrains.desc",
6,
}

// Units contains all the units
Units = map[UnitType]Unit{
UnitTypeCode: UnitCode,
@@ -265,6 +278,7 @@ var (
UnitTypeWiki: UnitWiki,
UnitTypeExternalWiki: UnitExternalWiki,
UnitTypeDatasets: UnitDataset,
UnitTypeCloudBrain: UnitCloudBrain,
}
)



+ 1
- 0
modules/auth/repo_form.go View File

@@ -121,6 +121,7 @@ type RepoSettingForm struct {

// Advanced settings
EnableDataset bool
EnableCloudBrain bool
EnableWiki bool
EnableExternalWiki bool
ExternalWikiURL string


+ 1
- 0
modules/context/repo.go View File

@@ -814,6 +814,7 @@ func UnitTypes() macaron.Handler {
ctx.Data["UnitTypeCode"] = models.UnitTypeCode
ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues
ctx.Data["UnitTypeDatasets"] = models.UnitTypeDatasets
ctx.Data["UnitTypeCloudBrain"] = models.UnitTypeCloudBrain
ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests
ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases
ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki


+ 12
- 0
routers/repo/setting.go View File

@@ -227,6 +227,18 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeDatasets)
}

if form.EnableCloudBrain && !models.UnitTypeCloudBrain.UnitGlobalDisabled() {
units = append(units, models.RepoUnit{
RepoID: repo.ID,
Type: models.UnitTypeCloudBrain,
Config: &models.CloudBrainConfig{
EnableCloudBrain: form.EnableCloudBrain,
},
})
} else if !models.UnitTypeCloudBrain.UnitGlobalDisabled() {
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeCloudBrain)
}

if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
if !validation.IsValidExternalURL(form.ExternalWikiURL) {
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error"))


+ 4
- 2
routers/routes/routes.go View File

@@ -544,6 +544,8 @@ func RegisterRoutes(m *macaron.Macaron) {
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests)
reqRepoDatasetReader := context.RequireRepoReader(models.UnitTypeDatasets)
reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets)
reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain)
reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain)

// ***** START: Organization *****
m.Group("/org", func() {
@@ -870,8 +872,8 @@ func RegisterRoutes(m *macaron.Macaron) {
}, context.RepoRef())

m.Group("/cloudbrain", func() {
m.Get("", repo.CloudBrainIndex)
m.Get("/new", repo.CloudBrainNew)
m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex)
m.Get("/new", reqRepoCloudBrainWriter, repo.CloudBrainNew)
})

m.Group("/wiki", func() {


+ 4
- 4
templates/repo/header.tmpl View File

@@ -139,10 +139,10 @@
</a>
{{end}}

{{if .Permission.CanRead $.UnitTypeCode}}
<a class="{{if .PageIsViewCloudBrain}}active{{end}} item" href="{{.RepoLink}}/cloudbrain">
{{svg "octicon-circuit-board" 16}} {{.i18n.Tr "repo.cloudbrain"}}
</a>
{{if .Permission.CanRead $.UnitTypeCloudBrain}}
<a class="{{if .PageIsCloudBrain}}active{{end}} item" href="{{.RepoLink}}/cloudbrain">
{{svg "octicon-file-submodule" 16}} {{.i18n.Tr "cloudbrains"}}
</a>
{{end}}

{{template "custom/extra_tabs" .}}


+ 9
- 0
templates/repo/settings/options.tmpl View File

@@ -150,6 +150,15 @@
</div>
</div>

{{$isCloudBrainEnabled := .Repository.UnitEnabled $.UnitTypeCloudBrain }}
<div class="inline field">
<label>{{.i18n.Tr "repo.cloudbrain"}}</label>
<div class="ui checkbox">
<input class="enable-system" name="enable_cloud_brain" type="checkbox" {{if $isCloudBrainEnabled}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.cloudbrain_desc"}}</label>
</div>
</div>

{{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
<div class="inline field">
<label>{{.i18n.Tr "repo.wiki"}}</label>


Loading…
Cancel
Save