Skip to content

Resolved #296 #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2016
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
3 changes: 3 additions & 0 deletions conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ repos = Repositories
users = Users
organizations = Organizations
search = Search
repo_no_results = There are no matched repositories found.
user_no_results = There are no matched users found.
org_no_results = There are no matched organizations found.

[auth]
create_new_account = Create New Account
Expand Down
3 changes: 3 additions & 0 deletions conf/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ repos=仓库
users=用户
organizations=组织
search=搜索
repo_no_results = 没有匹配的仓库。
user_no_results = 没有匹配的用户。
org_no_results = 没有匹配的组织。

[auth]
create_new_account=创建帐户
Expand Down
54 changes: 34 additions & 20 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/Unknwon/paginater"

"bytes"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
Expand Down Expand Up @@ -60,6 +62,14 @@ type RepoSearchOptions struct {
TplName base.TplName
}

var (
nullByte = []byte{0x00}
)

func isKeywordValid(keyword string) bool {
return !bytes.Contains([]byte(keyword), nullByte)
}

// RenderRepoSearch render repositories search page
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
page := ctx.QueryInt("page")
Expand All @@ -82,16 +92,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
}
count = opts.Counter(opts.Private)
} else {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: opts.OrderBy,
Private: opts.Private,
Page: page,
PageSize: opts.PageSize,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
if isKeywordValid(keyword) {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: opts.OrderBy,
Private: opts.Private,
Page: page,
PageSize: opts.PageSize,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
}
}
}
ctx.Data["Keyword"] = keyword
Expand Down Expand Up @@ -156,16 +168,18 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
}
count = opts.Counter()
} else {
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
Keyword: keyword,
Type: opts.Type,
OrderBy: opts.OrderBy,
Page: page,
PageSize: opts.PageSize,
})
if err != nil {
ctx.Handle(500, "SearchUserByName", err)
return
if isKeywordValid(keyword) {
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
Keyword: keyword,
Type: opts.Type,
OrderBy: opts.OrderBy,
Page: page,
PageSize: opts.PageSize,
})
if err != nil {
ctx.Handle(500, "SearchUserByName", err)
return
}
}
}
ctx.Data["Keyword"] = keyword
Expand Down
2 changes: 2 additions & 0 deletions templates/explore/organizations.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</div>
</div>
</div>
{{else}}
<div>{{$.i18n.Tr "explore.org_no_results"}}</div>
{{end}}
</div>

Expand Down
4 changes: 4 additions & 0 deletions templates/explore/repo_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
</div>
{{else}}
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

{{$.i18n.Tr "explore.repo_no_results"}}
</div>
{{end}}
</div>
2 changes: 2 additions & 0 deletions templates/explore/users.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</div>
</div>
</div>
{{else}}
<div>{{$.i18n.Tr "explore.user_no_results"}}</div>
{{end}}
</div>

Expand Down