From 1d1ea118fc801b841eaeaca68da01c9df0ad1df0 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Sat, 2 Dec 2017 19:00:41 -0800 Subject: [PATCH 1/2] Sort repos in issues dashboard sidebar --- models/repo_list.go | 12 ++++++++++++ routers/user/home.go | 2 ++ 2 files changed, 14 insertions(+) diff --git a/models/repo_list.go b/models/repo_list.go index 883e3b98d5b71..4da6a3aef2b0e 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -16,6 +16,18 @@ import ( // RepositoryList contains a list of repositories type RepositoryList []*Repository +func (repos RepositoryList) Len() int { + return len(repos) +} + +func (repos RepositoryList) Less(i, j int) bool { + return repos[i].ID < repos[j].ID +} + +func (repos RepositoryList) Swap(i, j int) { + repos[i], repos[j] = repos[j], repos[i] +} + // RepositoryListOfMap make list from values of map func RepositoryListOfMap(repoMap map[int64]*Repository) RepositoryList { return RepositoryList(valuesRepository(repoMap)) diff --git a/routers/user/home.go b/routers/user/home.go index c2c6a67018ea1..581db850f6710 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -7,6 +7,7 @@ package user import ( "bytes" "fmt" + "sort" "github.com/Unknwon/com" "github.com/Unknwon/paginater" @@ -302,6 +303,7 @@ func Issues(ctx *context.Context) { } showRepos := models.RepositoryListOfMap(showReposMap) + sort.Sort(showRepos) if err = showRepos.LoadAttributes(); err != nil { ctx.Handle(500, "LoadAttributes", fmt.Errorf("%v", err)) return From 7cc20c9b2f036b5f2ceb47516378e1e37ee9274d Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Sun, 3 Dec 2017 09:46:03 -0800 Subject: [PATCH 2/2] Sort repos by name --- models/repo_list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo_list.go b/models/repo_list.go index 4da6a3aef2b0e..d13266f2087d3 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -21,7 +21,7 @@ func (repos RepositoryList) Len() int { } func (repos RepositoryList) Less(i, j int) bool { - return repos[i].ID < repos[j].ID + return repos[i].FullName() < repos[j].FullName() } func (repos RepositoryList) Swap(i, j int) {