* resolved #296

* Indentation fixed
This commit is contained in:
Lunny Xiao 2016-12-01 18:52:57 +08:00 committed by GitHub
parent 2343feadd4
commit 590a79ff8a
6 changed files with 48 additions and 20 deletions

View file

@ -139,6 +139,9 @@ repos = Repositories
users = Users users = Users
organizations = Organizations organizations = Organizations
search = Search 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] [auth]
create_new_account = Create New Account create_new_account = Create New Account

View file

@ -139,6 +139,9 @@ repos=仓库
users=用户 users=用户
organizations=组织 organizations=组织
search=搜索 search=搜索
repo_no_results = 没有匹配的仓库。
user_no_results = 没有匹配的用户。
org_no_results = 没有匹配的组织。
[auth] [auth]
create_new_account=创建帐户 create_new_account=创建帐户

View file

@ -9,6 +9,8 @@ import (
"github.com/Unknwon/paginater" "github.com/Unknwon/paginater"
"bytes"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
@ -60,6 +62,14 @@ type RepoSearchOptions struct {
TplName base.TplName TplName base.TplName
} }
var (
nullByte = []byte{0x00}
)
func isKeywordValid(keyword string) bool {
return !bytes.Contains([]byte(keyword), nullByte)
}
// RenderRepoSearch render repositories search page // RenderRepoSearch render repositories search page
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
@ -82,6 +92,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
} }
count = opts.Counter(opts.Private) count = opts.Counter(opts.Private)
} else { } else {
if isKeywordValid(keyword) {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword, Keyword: keyword,
OrderBy: opts.OrderBy, OrderBy: opts.OrderBy,
@ -94,6 +105,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
return return
} }
} }
}
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
@ -156,6 +168,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
} }
count = opts.Counter() count = opts.Counter()
} else { } else {
if isKeywordValid(keyword) {
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ users, count, err = models.SearchUserByName(&models.SearchUserOptions{
Keyword: keyword, Keyword: keyword,
Type: opts.Type, Type: opts.Type,
@ -168,6 +181,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
return return
} }
} }
}
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)

View file

@ -24,6 +24,8 @@
</div> </div>
</div> </div>
</div> </div>
{{else}}
<div>{{$.i18n.Tr "explore.org_no_results"}}</div>
{{end}} {{end}}
</div> </div>

View file

@ -19,5 +19,9 @@
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}} {{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p> <p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
</div> </div>
{{else}}
<div>
{{$.i18n.Tr "explore.repo_no_results"}}
</div>
{{end}} {{end}}
</div> </div>

View file

@ -24,6 +24,8 @@
</div> </div>
</div> </div>
</div> </div>
{{else}}
<div>{{$.i18n.Tr "explore.user_no_results"}}</div>
{{end}} {{end}}
</div> </div>