You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unit.go 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. // UnitType is Unit's Type
  6. type UnitType int
  7. // Enumerate all the unit types
  8. const (
  9. UnitTypeCode UnitType = iota + 1 // 1 code
  10. UnitTypeIssues // 2 issues
  11. UnitTypePullRequests // 3 PRs
  12. UnitTypeCommits // 4 Commits
  13. UnitTypeReleases // 5 Releases
  14. UnitTypeWiki // 6 Wiki
  15. UnitTypeSettings // 7 Settings
  16. UnitTypeExternalWiki // 8 ExternalWiki
  17. UnitTypeExternalTracker // 9 ExternalTracker
  18. )
  19. var (
  20. // allRepUnitTypes contains all the unit types
  21. allRepUnitTypes = []UnitType{
  22. UnitTypeCode,
  23. UnitTypeIssues,
  24. UnitTypePullRequests,
  25. UnitTypeCommits,
  26. UnitTypeReleases,
  27. UnitTypeWiki,
  28. UnitTypeSettings,
  29. UnitTypeExternalWiki,
  30. UnitTypeExternalTracker,
  31. }
  32. // defaultRepoUnits contains the default unit types
  33. defaultRepoUnits = []UnitType{
  34. UnitTypeCode,
  35. UnitTypeIssues,
  36. UnitTypePullRequests,
  37. UnitTypeCommits,
  38. UnitTypeReleases,
  39. UnitTypeWiki,
  40. UnitTypeSettings,
  41. }
  42. // MustRepoUnits contains the units could be disabled currently
  43. MustRepoUnits = []UnitType{
  44. UnitTypeCode,
  45. UnitTypeCommits,
  46. UnitTypeReleases,
  47. UnitTypeSettings,
  48. }
  49. )
  50. // Unit is a tab page of one repository
  51. type Unit struct {
  52. Type UnitType
  53. NameKey string
  54. URI string
  55. DescKey string
  56. Idx int
  57. }
  58. // CanDisable returns if this unit could be disabled.
  59. func (u *Unit) CanDisable() bool {
  60. return u.Type != UnitTypeSettings
  61. }
  62. // Enumerate all the units
  63. var (
  64. UnitCode = Unit{
  65. UnitTypeCode,
  66. "repo.code",
  67. "/",
  68. "repo.code.desc",
  69. 0,
  70. }
  71. UnitIssues = Unit{
  72. UnitTypeIssues,
  73. "repo.issues",
  74. "/issues",
  75. "repo.issues.desc",
  76. 1,
  77. }
  78. UnitExternalTracker = Unit{
  79. UnitTypeExternalTracker,
  80. "repo.ext_issues",
  81. "/issues",
  82. "repo.ext_issues.desc",
  83. 1,
  84. }
  85. UnitPullRequests = Unit{
  86. UnitTypePullRequests,
  87. "repo.pulls",
  88. "/pulls",
  89. "repo.pulls.desc",
  90. 2,
  91. }
  92. UnitCommits = Unit{
  93. UnitTypeCommits,
  94. "repo.commits",
  95. "/commits/master",
  96. "repo.commits.desc",
  97. 3,
  98. }
  99. UnitReleases = Unit{
  100. UnitTypeReleases,
  101. "repo.releases",
  102. "/releases",
  103. "repo.releases.desc",
  104. 4,
  105. }
  106. UnitWiki = Unit{
  107. UnitTypeWiki,
  108. "repo.wiki",
  109. "/wiki",
  110. "repo.wiki.desc",
  111. 5,
  112. }
  113. UnitExternalWiki = Unit{
  114. UnitTypeExternalWiki,
  115. "repo.ext_wiki",
  116. "/wiki",
  117. "repo.ext_wiki.desc",
  118. 5,
  119. }
  120. UnitSettings = Unit{
  121. UnitTypeSettings,
  122. "repo.settings",
  123. "/settings",
  124. "repo.settings.desc",
  125. 6,
  126. }
  127. // Units contains all the units
  128. Units = map[UnitType]Unit{
  129. UnitTypeCode: UnitCode,
  130. UnitTypeIssues: UnitIssues,
  131. UnitTypeExternalTracker: UnitExternalTracker,
  132. UnitTypePullRequests: UnitPullRequests,
  133. UnitTypeCommits: UnitCommits,
  134. UnitTypeReleases: UnitReleases,
  135. UnitTypeWiki: UnitWiki,
  136. UnitTypeExternalWiki: UnitExternalWiki,
  137. UnitTypeSettings: UnitSettings,
  138. }
  139. )