2017-02-04 23:53:46 +08:00
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package models
// UnitType is Unit's Type
type UnitType int
// Enumerate all the unit types
const (
UnitTypeCode UnitType = iota + 1 // 1 code
UnitTypeIssues // 2 issues
UnitTypePullRequests // 3 PRs
UnitTypeCommits // 4 Commits
UnitTypeReleases // 5 Releases
UnitTypeWiki // 6 Wiki
UnitTypeSettings // 7 Settings
UnitTypeExternalWiki // 8 ExternalWiki
UnitTypeExternalTracker // 9 ExternalTracker
)
2017-05-18 22:54:24 +08:00
var (
// allRepUnitTypes contains all the unit types
allRepUnitTypes = [ ] UnitType {
UnitTypeCode ,
UnitTypeIssues ,
UnitTypePullRequests ,
UnitTypeCommits ,
UnitTypeReleases ,
UnitTypeWiki ,
UnitTypeSettings ,
UnitTypeExternalWiki ,
UnitTypeExternalTracker ,
}
// defaultRepoUnits contains the default unit types
defaultRepoUnits = [ ] UnitType {
UnitTypeCode ,
UnitTypeIssues ,
UnitTypePullRequests ,
UnitTypeCommits ,
UnitTypeReleases ,
UnitTypeWiki ,
UnitTypeSettings ,
}
// MustRepoUnits contains the units could be disabled currently
MustRepoUnits = [ ] UnitType {
UnitTypeCode ,
UnitTypeCommits ,
UnitTypeReleases ,
UnitTypeSettings ,
}
)
2017-02-04 23:53:46 +08:00
// Unit is a tab page of one repository
type Unit struct {
Type UnitType
NameKey string
URI string
DescKey string
Idx int
}
2017-05-18 22:54:24 +08:00
// CanDisable returns if this unit could be disabled.
func ( u * Unit ) CanDisable ( ) bool {
return u . Type != UnitTypeSettings
}
2017-02-04 23:53:46 +08:00
// Enumerate all the units
var (
UnitCode = Unit {
UnitTypeCode ,
"repo.code" ,
"/" ,
2017-05-18 22:54:24 +08:00
"repo.code.desc" ,
2017-02-04 23:53:46 +08:00
0 ,
}
UnitIssues = Unit {
UnitTypeIssues ,
"repo.issues" ,
"/issues" ,
2017-05-18 22:54:24 +08:00
"repo.issues.desc" ,
2017-02-04 23:53:46 +08:00
1 ,
}
UnitExternalTracker = Unit {
UnitTypeExternalTracker ,
2017-05-18 22:54:24 +08:00
"repo.ext_issues" ,
2017-02-04 23:53:46 +08:00
"/issues" ,
2017-05-18 22:54:24 +08:00
"repo.ext_issues.desc" ,
2017-02-04 23:53:46 +08:00
1 ,
}
UnitPullRequests = Unit {
UnitTypePullRequests ,
"repo.pulls" ,
"/pulls" ,
2017-05-18 22:54:24 +08:00
"repo.pulls.desc" ,
2017-02-04 23:53:46 +08:00
2 ,
}
UnitCommits = Unit {
UnitTypeCommits ,
"repo.commits" ,
"/commits/master" ,
2017-05-18 22:54:24 +08:00
"repo.commits.desc" ,
2017-02-04 23:53:46 +08:00
3 ,
}
UnitReleases = Unit {
UnitTypeReleases ,
"repo.releases" ,
"/releases" ,
2017-05-18 22:54:24 +08:00
"repo.releases.desc" ,
2017-02-04 23:53:46 +08:00
4 ,
}
UnitWiki = Unit {
UnitTypeWiki ,
"repo.wiki" ,
"/wiki" ,
2017-05-18 22:54:24 +08:00
"repo.wiki.desc" ,
2017-02-04 23:53:46 +08:00
5 ,
}
UnitExternalWiki = Unit {
UnitTypeExternalWiki ,
2017-05-18 22:54:24 +08:00
"repo.ext_wiki" ,
2017-02-04 23:53:46 +08:00
"/wiki" ,
2017-05-18 22:54:24 +08:00
"repo.ext_wiki.desc" ,
2017-02-04 23:53:46 +08:00
5 ,
}
UnitSettings = Unit {
UnitTypeSettings ,
"repo.settings" ,
"/settings" ,
2017-05-18 22:54:24 +08:00
"repo.settings.desc" ,
2017-02-04 23:53:46 +08:00
6 ,
}
// Units contains all the units
Units = map [ UnitType ] Unit {
UnitTypeCode : UnitCode ,
UnitTypeIssues : UnitIssues ,
UnitTypeExternalTracker : UnitExternalTracker ,
UnitTypePullRequests : UnitPullRequests ,
UnitTypeCommits : UnitCommits ,
UnitTypeReleases : UnitReleases ,
UnitTypeWiki : UnitWiki ,
UnitTypeExternalWiki : UnitExternalWiki ,
UnitTypeSettings : UnitSettings ,
}
)