| @@ -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, | ||||
| @@ -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)) | ||||
| } | } | ||||
| @@ -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, | |||||
| } | } | ||||
| ) | ) | ||||
| @@ -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 | ||||
| @@ -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 | ||||
| @@ -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")) | ||||
| @@ -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() { | ||||
| @@ -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" .}} | ||||
| @@ -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> | ||||