2017-02-04 21:23:46 +05:30
|
|
|
// 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
|
|
|
|
|
2018-11-11 01:15:32 +05:30
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-02-04 21:23:46 +05:30
|
|
|
// 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
|
2017-07-17 07:34:43 +05:30
|
|
|
UnitTypeReleases // 4 Releases
|
|
|
|
UnitTypeWiki // 5 Wiki
|
|
|
|
UnitTypeExternalWiki // 6 ExternalWiki
|
|
|
|
UnitTypeExternalTracker // 7 ExternalTracker
|
2017-02-04 21:23:46 +05:30
|
|
|
)
|
|
|
|
|
2017-05-18 20:24:24 +05:30
|
|
|
var (
|
|
|
|
// allRepUnitTypes contains all the unit types
|
|
|
|
allRepUnitTypes = []UnitType{
|
|
|
|
UnitTypeCode,
|
|
|
|
UnitTypeIssues,
|
|
|
|
UnitTypePullRequests,
|
|
|
|
UnitTypeReleases,
|
|
|
|
UnitTypeWiki,
|
|
|
|
UnitTypeExternalWiki,
|
|
|
|
UnitTypeExternalTracker,
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaultRepoUnits contains the default unit types
|
|
|
|
defaultRepoUnits = []UnitType{
|
|
|
|
UnitTypeCode,
|
|
|
|
UnitTypeIssues,
|
|
|
|
UnitTypePullRequests,
|
|
|
|
UnitTypeReleases,
|
|
|
|
UnitTypeWiki,
|
|
|
|
}
|
|
|
|
|
2017-07-17 07:34:43 +05:30
|
|
|
// MustRepoUnits contains the units could not be disabled currently
|
2017-05-18 20:24:24 +05:30
|
|
|
MustRepoUnits = []UnitType{
|
|
|
|
UnitTypeCode,
|
|
|
|
UnitTypeReleases,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-07-17 07:34:43 +05:30
|
|
|
// Unit is a section of one repository
|
2017-02-04 21:23:46 +05:30
|
|
|
type Unit struct {
|
|
|
|
Type UnitType
|
|
|
|
NameKey string
|
|
|
|
URI string
|
|
|
|
DescKey string
|
|
|
|
Idx int
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:24:24 +05:30
|
|
|
// CanDisable returns if this unit could be disabled.
|
|
|
|
func (u *Unit) CanDisable() bool {
|
2017-07-17 07:34:43 +05:30
|
|
|
return true
|
2017-05-18 20:24:24 +05:30
|
|
|
}
|
|
|
|
|
2017-10-01 19:20:56 +05:30
|
|
|
// IsLessThan compares order of two units
|
|
|
|
func (u Unit) IsLessThan(unit Unit) bool {
|
|
|
|
if (u.Type == UnitTypeExternalTracker || u.Type == UnitTypeExternalWiki) && unit.Type != UnitTypeExternalTracker && unit.Type != UnitTypeExternalWiki {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return u.Idx < unit.Idx
|
|
|
|
}
|
|
|
|
|
2017-02-04 21:23:46 +05:30
|
|
|
// Enumerate all the units
|
|
|
|
var (
|
|
|
|
UnitCode = Unit{
|
|
|
|
UnitTypeCode,
|
|
|
|
"repo.code",
|
|
|
|
"/",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.code.desc",
|
2017-02-04 21:23:46 +05:30
|
|
|
0,
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitIssues = Unit{
|
|
|
|
UnitTypeIssues,
|
|
|
|
"repo.issues",
|
|
|
|
"/issues",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.issues.desc",
|
2017-02-04 21:23:46 +05:30
|
|
|
1,
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitExternalTracker = Unit{
|
|
|
|
UnitTypeExternalTracker,
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.ext_issues",
|
2017-02-04 21:23:46 +05:30
|
|
|
"/issues",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.ext_issues.desc",
|
2017-02-04 21:23:46 +05:30
|
|
|
1,
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitPullRequests = Unit{
|
|
|
|
UnitTypePullRequests,
|
|
|
|
"repo.pulls",
|
|
|
|
"/pulls",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.pulls.desc",
|
2017-02-04 21:23:46 +05:30
|
|
|
2,
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitReleases = Unit{
|
|
|
|
UnitTypeReleases,
|
|
|
|
"repo.releases",
|
|
|
|
"/releases",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.releases.desc",
|
2017-07-17 07:34:43 +05:30
|
|
|
3,
|
2017-02-04 21:23:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
UnitWiki = Unit{
|
|
|
|
UnitTypeWiki,
|
|
|
|
"repo.wiki",
|
|
|
|
"/wiki",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.wiki.desc",
|
2017-07-17 07:34:43 +05:30
|
|
|
4,
|
2017-02-04 21:23:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
UnitExternalWiki = Unit{
|
|
|
|
UnitTypeExternalWiki,
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.ext_wiki",
|
2017-02-04 21:23:46 +05:30
|
|
|
"/wiki",
|
2017-05-18 20:24:24 +05:30
|
|
|
"repo.ext_wiki.desc",
|
2017-07-17 07:34:43 +05:30
|
|
|
4,
|
2017-02-04 21:23:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Units contains all the units
|
|
|
|
Units = map[UnitType]Unit{
|
|
|
|
UnitTypeCode: UnitCode,
|
|
|
|
UnitTypeIssues: UnitIssues,
|
|
|
|
UnitTypeExternalTracker: UnitExternalTracker,
|
|
|
|
UnitTypePullRequests: UnitPullRequests,
|
|
|
|
UnitTypeReleases: UnitReleases,
|
|
|
|
UnitTypeWiki: UnitWiki,
|
|
|
|
UnitTypeExternalWiki: UnitExternalWiki,
|
|
|
|
}
|
|
|
|
)
|
2018-11-11 01:15:32 +05:30
|
|
|
|
|
|
|
// FindUnitTypes give the unit key name and return unit
|
|
|
|
func FindUnitTypes(nameKeys ...string) (res []UnitType) {
|
|
|
|
for _, key := range nameKeys {
|
|
|
|
for t, u := range Units {
|
|
|
|
if strings.EqualFold(key, u.NameKey) {
|
|
|
|
res = append(res, t)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|