Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions models/fixtures/repo_unit.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
-
id: 1
repo_id: 1
type: 1
index: 0
type: 4
index: 3
config: "{}"
created_unix: 946684810

-
id: 2
repo_id: 1
type: 2
index: 1
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}"
type: 5
index: 4
config: "{}"
created_unix: 946684810

-
id: 3
repo_id: 1
type: 3
index: 2
type: 1
index: 0
config: "{}"
created_unix: 946684810

-
id: 4
repo_id: 1
type: 4
index: 3
config: "{}"
type: 2
index: 1
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}"
created_unix: 946684810

-
id: 5
repo_id: 1
type: 5
index: 4
type: 3
index: 2
config: "{}"
created_unix: 946684810

Expand Down
8 changes: 8 additions & 0 deletions models/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func (u *Unit) CanDisable() bool {
return true
}

// 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
}

// Enumerate all the units
var (
UnitCode = Unit{
Expand Down
21 changes: 13 additions & 8 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
// Home render repository home page
func Home(ctx *context.Context) {
if len(ctx.Repo.Repository.Units) > 0 {
tp := ctx.Repo.Repository.Units[0].Type
if tp == models.UnitTypeCode {
renderCode(ctx)
return
var firstUnit *models.Unit
for _, repoUnit := range ctx.Repo.Repository.Units {
if repoUnit.Type == models.UnitTypeCode {
renderCode(ctx)
return
}

unit, ok := models.Units[repoUnit.Type]
if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) {
firstUnit = &unit
}
}

unit, ok := models.Units[tp]
if ok {
ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/%s%s",
ctx.Repo.Repository.FullName(), unit.URI))
if firstUnit != nil {
ctx.Redirect(fmt.Sprintf("%s/%s%s", setting.AppSubURL, ctx.Repo.Repository.FullName(), firstUnit.URI))
return
}
}
Expand Down