forked from forgejo/forgejo
Add Activity page to repository (#2674)
* Add Activity page to repository * Add request data for activity * Add issue data for activity * Add user unit right checks * Add releases to activity * Log repository unit loading error
This commit is contained in:
parent
8863e74f2a
commit
f42dbdbae5
12 changed files with 686 additions and 4 deletions
|
@ -573,7 +573,7 @@ func LoadRepoUnits() macaron.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
// CheckUnit will check whether
|
||||
// CheckUnit will check whether unit type is enabled
|
||||
func CheckUnit(unitType models.UnitType) macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
if !ctx.Repo.Repository.UnitEnabled(unitType) {
|
||||
|
@ -582,6 +582,15 @@ func CheckUnit(unitType models.UnitType) macaron.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
// CheckAnyUnit will check whether any of the unit types are enabled
|
||||
func CheckAnyUnit(unitTypes ...models.UnitType) macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
if !ctx.Repo.Repository.AnyUnitEnabled(unitTypes...) {
|
||||
ctx.Handle(404, "CheckAnyUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitTypes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GitHookService checks if repository Git hooks service has been enabled.
|
||||
func GitHookService() macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
|
|
|
@ -158,6 +158,7 @@ func NewFuncMap() []template.FuncMap {
|
|||
"DisableGitHooks": func() bool {
|
||||
return setting.DisableGitHooks
|
||||
},
|
||||
"TrN": TrN,
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -342,3 +343,60 @@ func DiffLineTypeToStr(diffType int) string {
|
|||
}
|
||||
return "same"
|
||||
}
|
||||
|
||||
// Language specific rules for translating plural texts
|
||||
var trNLangRules = map[string]func(int64) int{
|
||||
"en-US": func(cnt int64) int {
|
||||
if cnt == 1 {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
},
|
||||
"lv-LV": func(cnt int64) int {
|
||||
if cnt%10 == 1 && cnt%100 != 11 {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
},
|
||||
"ru-RU": func(cnt int64) int {
|
||||
if cnt%10 == 1 && cnt%100 != 11 {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
},
|
||||
"zh-CN": func(cnt int64) int {
|
||||
return 0
|
||||
},
|
||||
"zh-HK": func(cnt int64) int {
|
||||
return 0
|
||||
},
|
||||
"zh-TW": func(cnt int64) int {
|
||||
return 0
|
||||
},
|
||||
}
|
||||
|
||||
// TrN returns key to be used for plural text translation
|
||||
func TrN(lang string, cnt interface{}, key1, keyN string) string {
|
||||
var c int64
|
||||
if t, ok := cnt.(int); ok {
|
||||
c = int64(t)
|
||||
} else if t, ok := cnt.(int16); ok {
|
||||
c = int64(t)
|
||||
} else if t, ok := cnt.(int32); ok {
|
||||
c = int64(t)
|
||||
} else if t, ok := cnt.(int64); ok {
|
||||
c = t
|
||||
} else {
|
||||
return keyN
|
||||
}
|
||||
|
||||
ruleFunc, ok := trNLangRules[lang]
|
||||
if !ok {
|
||||
ruleFunc = trNLangRules["en-US"]
|
||||
}
|
||||
|
||||
if ruleFunc(c) == 0 {
|
||||
return key1
|
||||
}
|
||||
return keyN
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue