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, Type: tp,
Config: &DatasetConfig{EnableDataset: true}, Config: &DatasetConfig{EnableDataset: true},
}) })
} else if tp == UnitTypeCloudBrain {
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &CloudBrainConfig{EnableCloudBrain: true},
})
} else { } else {
units = append(units, RepoUnit{ units = append(units, RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,


+ 18
- 2
models/repo_unit.go View File

@@ -117,16 +117,30 @@ type DatasetConfig struct {
EnableDataset bool 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 { func (cfg *DatasetConfig) FromDB(bs []byte) error {
return json.Unmarshal(bs, &cfg) 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) { func (cfg *DatasetConfig) ToDB() ([]byte, error) {
return json.Marshal(cfg) 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. // BeforeSet is invoked from XORM before setting the value of a field of this object.
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName { switch colName {
@@ -144,6 +158,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(IssuesConfig) r.Config = new(IssuesConfig)
case UnitTypeDatasets: case UnitTypeDatasets:
r.Config = new(DatasetConfig) r.Config = new(DatasetConfig)
case UnitTypeCloudBrain:
r.Config = new(CloudBrainConfig)
default: default:
panic("unrecognized repo unit type: " + com.ToStr(*val)) panic("unrecognized repo unit type: " + com.ToStr(*val))
} }


+ 14
- 0
models/unit.go View File

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


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


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


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


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

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




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

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


// Advanced settings // Advanced settings
EnableDataset bool EnableDataset bool
EnableCloudBrain bool
EnableWiki bool EnableWiki bool
EnableExternalWiki bool EnableExternalWiki bool
ExternalWikiURL string 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["UnitTypeCode"] = models.UnitTypeCode
ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues
ctx.Data["UnitTypeDatasets"] = models.UnitTypeDatasets ctx.Data["UnitTypeDatasets"] = models.UnitTypeDatasets
ctx.Data["UnitTypeCloudBrain"] = models.UnitTypeCloudBrain
ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests
ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases
ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki 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) 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 form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
if !validation.IsValidExternalURL(form.ExternalWikiURL) { if !validation.IsValidExternalURL(form.ExternalWikiURL) {
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) 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) reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests)
reqRepoDatasetReader := context.RequireRepoReader(models.UnitTypeDatasets) reqRepoDatasetReader := context.RequireRepoReader(models.UnitTypeDatasets)
reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets)
reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain)
reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain)


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


m.Group("/cloudbrain", func() { 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() { m.Group("/wiki", func() {


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

@@ -139,10 +139,10 @@
</a> </a>
{{end}} {{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}} {{end}}


{{template "custom/extra_tabs" .}} {{template "custom/extra_tabs" .}}


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

@@ -150,6 +150,15 @@
</div> </div>
</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)}} {{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
<div class="inline field"> <div class="inline field">
<label>{{.i18n.Tr "repo.wiki"}}</label> <label>{{.i18n.Tr "repo.wiki"}}</label>


Loading…
Cancel
Save