Skip to content

Commit b908ac9

Browse files
axifivelunny
authored andcommitted
Added repository search ordered by stars or forks. Forks column in admin repo list. (#3969)
* Added repository search order by stars or forks. Added Forks column to admin repository list. Signed-off-by: Alexey Terentyev <[email protected]> * Renamed search repo template Signed-off-by: Alexey Terentyev <[email protected]>
1 parent ea2a938 commit b908ac9

File tree

11 files changed

+99
-16
lines changed

11 files changed

+99
-16
lines changed

models/repo_list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ const (
152152
SearchOrderBySizeReverse = "size DESC"
153153
SearchOrderByID = "id ASC"
154154
SearchOrderByIDReverse = "id DESC"
155+
SearchOrderByStars = "num_stars ASC"
156+
SearchOrderByStarsReverse = "num_stars DESC"
157+
SearchOrderByForks = "num_forks ASC"
158+
SearchOrderByForksReverse = "num_forks DESC"
155159
)
156160

157161
// SearchRepositoryByName takes keyword and part of repository name to search,

models/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ func GetUser(user *User) (bool, error) {
12721272
type SearchUserOptions struct {
12731273
Keyword string
12741274
Type UserType
1275-
OrderBy string
1275+
OrderBy SearchOrderBy
12761276
Page int
12771277
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
12781278
IsActive util.OptionalBool
@@ -1322,7 +1322,7 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
13221322
users = make([]*User, 0, opts.PageSize)
13231323
return users, count, x.Where(cond).
13241324
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
1325-
OrderBy(opts.OrderBy).
1325+
OrderBy(opts.OrderBy.String()).
13261326
Find(&users)
13271327
}
13281328

options/locale/locale_en-US.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ issues.filter_sort.recentupdate = Recently updated
693693
issues.filter_sort.leastupdate = Least recently updated
694694
issues.filter_sort.mostcomment = Most commented
695695
issues.filter_sort.leastcomment = Least commented
696+
issues.filter_sort.moststars = Most stars
697+
issues.filter_sort.feweststars = Fewest stars
698+
issues.filter_sort.mostforks = Most forks
699+
issues.filter_sort.fewestforks = Fewest forks
696700
issues.action_open = Open
697701
issues.action_close = Close
698702
issues.action_label = Label
@@ -1359,6 +1363,7 @@ repos.name = Name
13591363
repos.private = Private
13601364
repos.watches = Watches
13611365
repos.stars = Stars
1366+
repos.forks = Forks
13621367
repos.issues = Issues
13631368
repos.size = Size
13641369

routers/home.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
104104
orderBy = models.SearchOrderBySizeReverse
105105
case "size":
106106
orderBy = models.SearchOrderBySize
107+
case "moststars":
108+
orderBy = models.SearchOrderByStarsReverse
109+
case "feweststars":
110+
orderBy = models.SearchOrderByStars
111+
case "mostforks":
112+
orderBy = models.SearchOrderByForksReverse
113+
case "fewestforks":
114+
orderBy = models.SearchOrderByForks
107115
default:
108116
ctx.Data["SortType"] = "recentupdate"
109117
orderBy = models.SearchOrderByRecentUpdated
@@ -164,26 +172,26 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
164172
users []*models.User
165173
count int64
166174
err error
167-
orderBy string
175+
orderBy models.SearchOrderBy
168176
)
169177

170178
ctx.Data["SortType"] = ctx.Query("sort")
171179
switch ctx.Query("sort") {
172180
case "newest":
173-
orderBy = "id DESC"
181+
orderBy = models.SearchOrderByIDReverse
174182
case "oldest":
175-
orderBy = "id ASC"
183+
orderBy = models.SearchOrderByID
176184
case "recentupdate":
177-
orderBy = "updated_unix DESC"
185+
orderBy = models.SearchOrderByRecentUpdated
178186
case "leastupdate":
179-
orderBy = "updated_unix ASC"
187+
orderBy = models.SearchOrderByLeastUpdated
180188
case "reversealphabetically":
181-
orderBy = "name DESC"
189+
orderBy = models.SearchOrderByAlphabeticallyReverse
182190
case "alphabetically":
183-
orderBy = "name ASC"
191+
orderBy = models.SearchOrderByAlphabetically
184192
default:
185193
ctx.Data["SortType"] = "alphabetically"
186-
orderBy = "name ASC"
194+
orderBy = models.SearchOrderByAlphabetically
187195
}
188196

189197
opts.Keyword = strings.Trim(ctx.Query("q"), " ")

routers/user/profile.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func Profile(ctx *context.Context) {
125125
orderBy = models.SearchOrderByAlphabeticallyReverse
126126
case "alphabetically":
127127
orderBy = models.SearchOrderByAlphabetically
128+
case "moststars":
129+
orderBy = models.SearchOrderByStarsReverse
130+
case "feweststars":
131+
orderBy = models.SearchOrderByStars
132+
case "mostforks":
133+
orderBy = models.SearchOrderByForksReverse
134+
case "fewestforks":
135+
orderBy = models.SearchOrderByForks
128136
default:
129137
ctx.Data["SortType"] = "recentupdate"
130138
orderBy = models.SearchOrderByRecentUpdated

templates/admin/base/search.tmpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
1313
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
1414
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
15-
<a class="{{if eq .SortType "size"}}active{{end}} item" href="{{$.Link}}?sort=size&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.by_size"}}</a>
16-
<a class="{{if eq .SortType "reversesize"}}active{{end}} item" href="{{$.Link}}?sort=reversesize&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_by_size"}}</a>
1715
</div>
1816
</div>
1917
</div>

templates/admin/repo/list.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{.i18n.Tr "admin.repos.repo_manage_panel"}} ({{.i18n.Tr "admin.total" .Total}})
88
</h4>
99
<div class="ui attached segment">
10-
{{template "admin/base/search" .}}
10+
{{template "admin/repo/search" .}}
1111
</div>
1212
<div class="ui attached table segment">
1313
<table class="ui very basic striped table">
@@ -19,6 +19,7 @@
1919
<th>{{.i18n.Tr "admin.repos.private"}}</th>
2020
<th>{{.i18n.Tr "admin.repos.watches"}}</th>
2121
<th>{{.i18n.Tr "admin.repos.stars"}}</th>
22+
<th>{{.i18n.Tr "admin.repos.forks"}}</th>
2223
<th>{{.i18n.Tr "admin.repos.issues"}}</th>
2324
<th>{{.i18n.Tr "admin.repos.size"}}</th>
2425
<th>{{.i18n.Tr "admin.users.created"}}</th>
@@ -34,6 +35,7 @@
3435
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
3536
<td>{{.NumWatches}}</td>
3637
<td>{{.NumStars}}</td>
38+
<td>{{.NumForks}}</td>
3739
<td>{{.NumIssues}}</td>
3840
<td>{{SizeFmt .Size}}</td>
3941
<td><span title="{{.CreatedUnix.FormatLong}}">{{.CreatedUnix.FormatShort}}</span></td>

templates/admin/repo/search.tmpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div class="ui right floated secondary filter menu">
2+
<!-- Sort -->
3+
<div class="ui dropdown type jump item">
4+
<span class="text">
5+
{{.i18n.Tr "repo.issues.filter_sort"}}
6+
<i class="dropdown icon"></i>
7+
</span>
8+
<div class="menu">
9+
<a class="{{if or (eq .SortType "oldest") (not .SortType)}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
10+
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
11+
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
12+
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
13+
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
14+
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
15+
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
16+
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
17+
<a class="{{if eq .SortType "mostforks"}}active{{end}} item" href="{{$.Link}}?sort=mostforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.mostforks"}}</a>
18+
<a class="{{if eq .SortType "fewestforks"}}active{{end}} item" href="{{$.Link}}?sort=fewestforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.fewestforks"}}</a>
19+
<a class="{{if eq .SortType "size"}}active{{end}} item" href="{{$.Link}}?sort=size&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.by_size"}}</a>
20+
<a class="{{if eq .SortType "reversesize"}}active{{end}} item" href="{{$.Link}}?sort=reversesize&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_by_size"}}</a>
21+
</div>
22+
</div>
23+
</div>
24+
<form class="ui form ignore-dirty" style="max-width: 90%">
25+
<div class="ui fluid action input">
26+
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
27+
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
28+
</div>
29+
</form>

templates/explore/repo_search.tmpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div class="ui right floated secondary filter menu">
2+
<!-- Sort -->
3+
<div class="ui right dropdown type jump item">
4+
<span class="text">
5+
{{.i18n.Tr "repo.issues.filter_sort"}}
6+
<i class="dropdown icon"></i>
7+
</span>
8+
<div class="menu">
9+
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
10+
<a class="{{if eq .SortType "oldest"}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
11+
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
12+
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
13+
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
14+
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
15+
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
16+
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
17+
<a class="{{if eq .SortType "mostforks"}}active{{end}} item" href="{{$.Link}}?sort=mostforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.mostforks"}}</a>
18+
<a class="{{if eq .SortType "fewestforks"}}active{{end}} item" href="{{$.Link}}?sort=fewestforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.fewestforks"}}</a>
19+
</div>
20+
</div>
21+
</div>
22+
<form class="ui form ignore-dirty" style="max-width: 90%">
23+
<div class="ui fluid action input">
24+
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
25+
<input type="hidden" name="tab" value="{{$.TabName}}">
26+
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
27+
</div>
28+
</form>
29+
<div class="ui divider"></div>

templates/explore/repos.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="explore repositories">
33
{{template "explore/navbar" .}}
44
<div class="ui container">
5-
{{template "explore/search" .}}
5+
{{template "explore/repo_search" .}}
66
{{template "explore/repo_list" .}}
77
{{template "base/paginate" .}}
88
</div>

templates/user/profile.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@
100100
</div>
101101
{{else if eq .TabName "stars"}}
102102
<div class="stars">
103-
{{template "explore/search" .}}
103+
{{template "explore/repo_search" .}}
104104
{{template "explore/repo_list" .}}
105105
{{template "base/paginate" .}}
106106
</div>
107107
{{else}}
108-
{{template "explore/search" .}}
108+
{{template "explore/repo_search" .}}
109109
{{template "explore/repo_list" .}}
110110
{{template "base/paginate" .}}
111111
{{end}}

0 commit comments

Comments
 (0)