Browse Source

Sort repos in issues dashboard sidebar (#3072)

* Sort repos in issues dashboard sidebar

* Sort repos by name
Ethan Koenig 1 year ago
parent
commit
c0a7899416
2 changed files with 14 additions and 0 deletions
  1. 12 0
      models/repo_list.go
  2. 2 0
      routers/user/home.go

+ 12 - 0
models/repo_list.go

@@ -16,6 +16,18 @@ import (
16 16
 // RepositoryList contains a list of repositories
17 17
 type RepositoryList []*Repository
18 18
 
19
+func (repos RepositoryList) Len() int {
20
+	return len(repos)
21
+}
22
+
23
+func (repos RepositoryList) Less(i, j int) bool {
24
+	return repos[i].FullName() < repos[j].FullName()
25
+}
26
+
27
+func (repos RepositoryList) Swap(i, j int) {
28
+	repos[i], repos[j] = repos[j], repos[i]
29
+}
30
+
19 31
 // RepositoryListOfMap make list from values of map
20 32
 func RepositoryListOfMap(repoMap map[int64]*Repository) RepositoryList {
21 33
 	return RepositoryList(valuesRepository(repoMap))

+ 2 - 0
routers/user/home.go

@@ -7,6 +7,7 @@ package user
7 7
 import (
8 8
 	"bytes"
9 9
 	"fmt"
10
+	"sort"
10 11
 
11 12
 	"github.com/Unknwon/com"
12 13
 	"github.com/Unknwon/paginater"
@@ -302,6 +303,7 @@ func Issues(ctx *context.Context) {
302 303
 	}
303 304
 
304 305
 	showRepos := models.RepositoryListOfMap(showReposMap)
306
+	sort.Sort(showRepos)
305 307
 	if err = showRepos.LoadAttributes(); err != nil {
306 308
 		ctx.Handle(500, "LoadAttributes", fmt.Errorf("%v", err))
307 309
 		return