diff --git a/models/repo_unit.go b/models/repo_unit.go index 42ce8f6c8..d6af3d454 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -113,6 +113,20 @@ func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool { mergeStyle == MergeStyleSquash && cfg.AllowSquash } +type DatasetConfig struct { + EnableTest bool +} + +// FromDB fills up a IssuesConfig from serialized format. +func (cfg *DatasetConfig) FromDB(bs []byte) error { + return json.Unmarshal(bs, &cfg) +} + +// ToDB exports a IssuesConfig to a serialized format. +func (cfg *DatasetConfig) 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 { @@ -128,6 +142,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { r.Config = new(PullRequestsConfig) case UnitTypeIssues: r.Config = new(IssuesConfig) + case UnitTypeDatasets: + r.Config = new(DatasetConfig) default: panic("unrecognized repo unit type: " + com.ToStr(*val)) } @@ -169,6 +185,10 @@ func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig { return r.Config.(*ExternalTrackerConfig) } +func (r *RepoUnit) DatasetConfig() *DatasetConfig { + return r.Config.(*DatasetConfig) +} + func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) { var tmpUnits []*RepoUnit if err := e.Where("repo_id = ?", repoID).Find(&tmpUnits); err != nil { diff --git a/models/unit.go b/models/unit.go index bd2e6b13a..be8dcf24f 100644 --- a/models/unit.go +++ b/models/unit.go @@ -24,6 +24,7 @@ const ( UnitTypeWiki // 5 Wiki UnitTypeExternalWiki // 6 ExternalWiki UnitTypeExternalTracker // 7 ExternalTracker + UnitTypeDatasets UnitType = 10 // 10 Dataset ) // Value returns integer value for unit type @@ -47,6 +48,8 @@ func (u UnitType) String() string { return "UnitTypeExternalWiki" case UnitTypeExternalTracker: return "UnitTypeExternalTracker" + case UnitTypeDatasets: + return "UnitTypeDataset" } return fmt.Sprintf("Unknown UnitType %d", u) } @@ -68,6 +71,7 @@ var ( UnitTypeWiki, UnitTypeExternalWiki, UnitTypeExternalTracker, + UnitTypeDatasets, } // DefaultRepoUnits contains the default unit types @@ -77,6 +81,7 @@ var ( UnitTypePullRequests, UnitTypeReleases, UnitTypeWiki, + UnitTypeDatasets, } // NotAllowedDefaultRepoUnits contains units that can't be default @@ -242,6 +247,14 @@ var ( 4, } + UnitDataset = Unit{ + UnitTypeDatasets, + "repo.dataset", + "/datasets", + "repo.datasets.desc", + 5, + } + // Units contains all the units Units = map[UnitType]Unit{ UnitTypeCode: UnitCode, @@ -251,6 +264,7 @@ var ( UnitTypeReleases: UnitReleases, UnitTypeWiki: UnitWiki, UnitTypeExternalWiki: UnitExternalWiki, + UnitTypeDatasets: UnitDataset, } ) diff --git a/modules/context/repo.go b/modules/context/repo.go index 5ebed0eb7..9d94030d8 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -813,6 +813,7 @@ func UnitTypes() macaron.Handler { return func(ctx *Context) { ctx.Data["UnitTypeCode"] = models.UnitTypeCode ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues + ctx.Data["UnitTypeDatasets"] = models.UnitTypeDatasets ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 4daaa201d..5b621073c 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -97,6 +97,12 @@ {{end}} + {{if .Permission.CanRead $.UnitTypeDatasets}} + + {{svg "octicon-database" 16}} {{.i18n.Tr "repo.datasets"}} {{/*.Repository.NumDatasets*/}} + + {{end}} + {{if .Permission.CanRead $.UnitTypeIssues}} {{svg "octicon-issue-opened" 16}} {{.i18n.Tr "repo.issues"}} {{.Repository.NumOpenIssues}}