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 <axifnx@gmail.com> * Renamed search repo template Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
parent
ea2a938e8a
commit
b908ac9fab
11 changed files with 99 additions and 16 deletions
|
@ -152,6 +152,10 @@ const (
|
||||||
SearchOrderBySizeReverse = "size DESC"
|
SearchOrderBySizeReverse = "size DESC"
|
||||||
SearchOrderByID = "id ASC"
|
SearchOrderByID = "id ASC"
|
||||||
SearchOrderByIDReverse = "id DESC"
|
SearchOrderByIDReverse = "id DESC"
|
||||||
|
SearchOrderByStars = "num_stars ASC"
|
||||||
|
SearchOrderByStarsReverse = "num_stars DESC"
|
||||||
|
SearchOrderByForks = "num_forks ASC"
|
||||||
|
SearchOrderByForksReverse = "num_forks DESC"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SearchRepositoryByName takes keyword and part of repository name to search,
|
// SearchRepositoryByName takes keyword and part of repository name to search,
|
||||||
|
|
|
@ -1272,7 +1272,7 @@ func GetUser(user *User) (bool, error) {
|
||||||
type SearchUserOptions struct {
|
type SearchUserOptions struct {
|
||||||
Keyword string
|
Keyword string
|
||||||
Type UserType
|
Type UserType
|
||||||
OrderBy string
|
OrderBy SearchOrderBy
|
||||||
Page int
|
Page int
|
||||||
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
|
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
|
||||||
IsActive util.OptionalBool
|
IsActive util.OptionalBool
|
||||||
|
@ -1322,7 +1322,7 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
|
||||||
users = make([]*User, 0, opts.PageSize)
|
users = make([]*User, 0, opts.PageSize)
|
||||||
return users, count, x.Where(cond).
|
return users, count, x.Where(cond).
|
||||||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
|
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
|
||||||
OrderBy(opts.OrderBy).
|
OrderBy(opts.OrderBy.String()).
|
||||||
Find(&users)
|
Find(&users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -693,6 +693,10 @@ issues.filter_sort.recentupdate = Recently updated
|
||||||
issues.filter_sort.leastupdate = Least recently updated
|
issues.filter_sort.leastupdate = Least recently updated
|
||||||
issues.filter_sort.mostcomment = Most commented
|
issues.filter_sort.mostcomment = Most commented
|
||||||
issues.filter_sort.leastcomment = Least commented
|
issues.filter_sort.leastcomment = Least commented
|
||||||
|
issues.filter_sort.moststars = Most stars
|
||||||
|
issues.filter_sort.feweststars = Fewest stars
|
||||||
|
issues.filter_sort.mostforks = Most forks
|
||||||
|
issues.filter_sort.fewestforks = Fewest forks
|
||||||
issues.action_open = Open
|
issues.action_open = Open
|
||||||
issues.action_close = Close
|
issues.action_close = Close
|
||||||
issues.action_label = Label
|
issues.action_label = Label
|
||||||
|
@ -1359,6 +1363,7 @@ repos.name = Name
|
||||||
repos.private = Private
|
repos.private = Private
|
||||||
repos.watches = Watches
|
repos.watches = Watches
|
||||||
repos.stars = Stars
|
repos.stars = Stars
|
||||||
|
repos.forks = Forks
|
||||||
repos.issues = Issues
|
repos.issues = Issues
|
||||||
repos.size = Size
|
repos.size = Size
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,14 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||||
orderBy = models.SearchOrderBySizeReverse
|
orderBy = models.SearchOrderBySizeReverse
|
||||||
case "size":
|
case "size":
|
||||||
orderBy = models.SearchOrderBySize
|
orderBy = models.SearchOrderBySize
|
||||||
|
case "moststars":
|
||||||
|
orderBy = models.SearchOrderByStarsReverse
|
||||||
|
case "feweststars":
|
||||||
|
orderBy = models.SearchOrderByStars
|
||||||
|
case "mostforks":
|
||||||
|
orderBy = models.SearchOrderByForksReverse
|
||||||
|
case "fewestforks":
|
||||||
|
orderBy = models.SearchOrderByForks
|
||||||
default:
|
default:
|
||||||
ctx.Data["SortType"] = "recentupdate"
|
ctx.Data["SortType"] = "recentupdate"
|
||||||
orderBy = models.SearchOrderByRecentUpdated
|
orderBy = models.SearchOrderByRecentUpdated
|
||||||
|
@ -164,26 +172,26 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
|
||||||
users []*models.User
|
users []*models.User
|
||||||
count int64
|
count int64
|
||||||
err error
|
err error
|
||||||
orderBy string
|
orderBy models.SearchOrderBy
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx.Data["SortType"] = ctx.Query("sort")
|
ctx.Data["SortType"] = ctx.Query("sort")
|
||||||
switch ctx.Query("sort") {
|
switch ctx.Query("sort") {
|
||||||
case "newest":
|
case "newest":
|
||||||
orderBy = "id DESC"
|
orderBy = models.SearchOrderByIDReverse
|
||||||
case "oldest":
|
case "oldest":
|
||||||
orderBy = "id ASC"
|
orderBy = models.SearchOrderByID
|
||||||
case "recentupdate":
|
case "recentupdate":
|
||||||
orderBy = "updated_unix DESC"
|
orderBy = models.SearchOrderByRecentUpdated
|
||||||
case "leastupdate":
|
case "leastupdate":
|
||||||
orderBy = "updated_unix ASC"
|
orderBy = models.SearchOrderByLeastUpdated
|
||||||
case "reversealphabetically":
|
case "reversealphabetically":
|
||||||
orderBy = "name DESC"
|
orderBy = models.SearchOrderByAlphabeticallyReverse
|
||||||
case "alphabetically":
|
case "alphabetically":
|
||||||
orderBy = "name ASC"
|
orderBy = models.SearchOrderByAlphabetically
|
||||||
default:
|
default:
|
||||||
ctx.Data["SortType"] = "alphabetically"
|
ctx.Data["SortType"] = "alphabetically"
|
||||||
orderBy = "name ASC"
|
orderBy = models.SearchOrderByAlphabetically
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Keyword = strings.Trim(ctx.Query("q"), " ")
|
opts.Keyword = strings.Trim(ctx.Query("q"), " ")
|
||||||
|
|
|
@ -125,6 +125,14 @@ func Profile(ctx *context.Context) {
|
||||||
orderBy = models.SearchOrderByAlphabeticallyReverse
|
orderBy = models.SearchOrderByAlphabeticallyReverse
|
||||||
case "alphabetically":
|
case "alphabetically":
|
||||||
orderBy = models.SearchOrderByAlphabetically
|
orderBy = models.SearchOrderByAlphabetically
|
||||||
|
case "moststars":
|
||||||
|
orderBy = models.SearchOrderByStarsReverse
|
||||||
|
case "feweststars":
|
||||||
|
orderBy = models.SearchOrderByStars
|
||||||
|
case "mostforks":
|
||||||
|
orderBy = models.SearchOrderByForksReverse
|
||||||
|
case "fewestforks":
|
||||||
|
orderBy = models.SearchOrderByForks
|
||||||
default:
|
default:
|
||||||
ctx.Data["SortType"] = "recentupdate"
|
ctx.Data["SortType"] = "recentupdate"
|
||||||
orderBy = models.SearchOrderByRecentUpdated
|
orderBy = models.SearchOrderByRecentUpdated
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
<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>
|
<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>
|
||||||
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
|
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
|
||||||
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
|
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{{.i18n.Tr "admin.repos.repo_manage_panel"}} ({{.i18n.Tr "admin.total" .Total}})
|
{{.i18n.Tr "admin.repos.repo_manage_panel"}} ({{.i18n.Tr "admin.total" .Total}})
|
||||||
</h4>
|
</h4>
|
||||||
<div class="ui attached segment">
|
<div class="ui attached segment">
|
||||||
{{template "admin/base/search" .}}
|
{{template "admin/repo/search" .}}
|
||||||
</div>
|
</div>
|
||||||
<div class="ui attached table segment">
|
<div class="ui attached table segment">
|
||||||
<table class="ui very basic striped table">
|
<table class="ui very basic striped table">
|
||||||
|
@ -19,6 +19,7 @@
|
||||||
<th>{{.i18n.Tr "admin.repos.private"}}</th>
|
<th>{{.i18n.Tr "admin.repos.private"}}</th>
|
||||||
<th>{{.i18n.Tr "admin.repos.watches"}}</th>
|
<th>{{.i18n.Tr "admin.repos.watches"}}</th>
|
||||||
<th>{{.i18n.Tr "admin.repos.stars"}}</th>
|
<th>{{.i18n.Tr "admin.repos.stars"}}</th>
|
||||||
|
<th>{{.i18n.Tr "admin.repos.forks"}}</th>
|
||||||
<th>{{.i18n.Tr "admin.repos.issues"}}</th>
|
<th>{{.i18n.Tr "admin.repos.issues"}}</th>
|
||||||
<th>{{.i18n.Tr "admin.repos.size"}}</th>
|
<th>{{.i18n.Tr "admin.repos.size"}}</th>
|
||||||
<th>{{.i18n.Tr "admin.users.created"}}</th>
|
<th>{{.i18n.Tr "admin.users.created"}}</th>
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
|
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
|
||||||
<td>{{.NumWatches}}</td>
|
<td>{{.NumWatches}}</td>
|
||||||
<td>{{.NumStars}}</td>
|
<td>{{.NumStars}}</td>
|
||||||
|
<td>{{.NumForks}}</td>
|
||||||
<td>{{.NumIssues}}</td>
|
<td>{{.NumIssues}}</td>
|
||||||
<td>{{SizeFmt .Size}}</td>
|
<td>{{SizeFmt .Size}}</td>
|
||||||
<td><span title="{{.CreatedUnix.FormatLong}}">{{.CreatedUnix.FormatShort}}</span></td>
|
<td><span title="{{.CreatedUnix.FormatLong}}">{{.CreatedUnix.FormatShort}}</span></td>
|
||||||
|
|
29
templates/admin/repo/search.tmpl
Normal file
29
templates/admin/repo/search.tmpl
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<div class="ui right floated secondary filter menu">
|
||||||
|
<!-- Sort -->
|
||||||
|
<div class="ui dropdown type jump item">
|
||||||
|
<span class="text">
|
||||||
|
{{.i18n.Tr "repo.issues.filter_sort"}}
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
</span>
|
||||||
|
<div class="menu">
|
||||||
|
<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>
|
||||||
|
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
|
||||||
|
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
|
||||||
|
<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>
|
||||||
|
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
|
||||||
|
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form class="ui form ignore-dirty" style="max-width: 90%">
|
||||||
|
<div class="ui fluid action input">
|
||||||
|
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
|
||||||
|
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
29
templates/explore/repo_search.tmpl
Normal file
29
templates/explore/repo_search.tmpl
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<div class="ui right floated secondary filter menu">
|
||||||
|
<!-- Sort -->
|
||||||
|
<div class="ui right dropdown type jump item">
|
||||||
|
<span class="text">
|
||||||
|
{{.i18n.Tr "repo.issues.filter_sort"}}
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
</span>
|
||||||
|
<div class="menu">
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form class="ui form ignore-dirty" style="max-width: 90%">
|
||||||
|
<div class="ui fluid action input">
|
||||||
|
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
|
||||||
|
<input type="hidden" name="tab" value="{{$.TabName}}">
|
||||||
|
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="ui divider"></div>
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="explore repositories">
|
<div class="explore repositories">
|
||||||
{{template "explore/navbar" .}}
|
{{template "explore/navbar" .}}
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
{{template "explore/search" .}}
|
{{template "explore/repo_search" .}}
|
||||||
{{template "explore/repo_list" .}}
|
{{template "explore/repo_list" .}}
|
||||||
{{template "base/paginate" .}}
|
{{template "base/paginate" .}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -100,12 +100,12 @@
|
||||||
</div>
|
</div>
|
||||||
{{else if eq .TabName "stars"}}
|
{{else if eq .TabName "stars"}}
|
||||||
<div class="stars">
|
<div class="stars">
|
||||||
{{template "explore/search" .}}
|
{{template "explore/repo_search" .}}
|
||||||
{{template "explore/repo_list" .}}
|
{{template "explore/repo_list" .}}
|
||||||
{{template "base/paginate" .}}
|
{{template "base/paginate" .}}
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{template "explore/search" .}}
|
{{template "explore/repo_search" .}}
|
||||||
{{template "explore/repo_list" .}}
|
{{template "explore/repo_list" .}}
|
||||||
{{template "base/paginate" .}}
|
{{template "base/paginate" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Reference in a new issue