Skip to content

Commit 590a79f

Browse files
authored
Resolved #296 (#324)
* resolved #296 * Indentation fixed
1 parent 2343fea commit 590a79f

File tree

6 files changed

+48
-20
lines changed

6 files changed

+48
-20
lines changed

conf/locale/locale_en-US.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ repos = Repositories
139139
users = Users
140140
organizations = Organizations
141141
search = Search
142+
repo_no_results = There are no matched repositories found.
143+
user_no_results = There are no matched users found.
144+
org_no_results = There are no matched organizations found.
142145
143146
[auth]
144147
create_new_account = Create New Account

conf/locale/locale_zh-CN.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ repos=仓库
139139
users=用户
140140
organizations=组织
141141
search=搜索
142+
repo_no_results = 没有匹配的仓库。
143+
user_no_results = 没有匹配的用户。
144+
org_no_results = 没有匹配的组织。
142145

143146
[auth]
144147
create_new_account=创建帐户

routers/home.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/Unknwon/paginater"
1111

12+
"bytes"
13+
1214
"code.gitea.io/gitea/models"
1315
"code.gitea.io/gitea/modules/base"
1416
"code.gitea.io/gitea/modules/context"
@@ -60,6 +62,14 @@ type RepoSearchOptions struct {
6062
TplName base.TplName
6163
}
6264

65+
var (
66+
nullByte = []byte{0x00}
67+
)
68+
69+
func isKeywordValid(keyword string) bool {
70+
return !bytes.Contains([]byte(keyword), nullByte)
71+
}
72+
6373
// RenderRepoSearch render repositories search page
6474
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
6575
page := ctx.QueryInt("page")
@@ -82,16 +92,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
8292
}
8393
count = opts.Counter(opts.Private)
8494
} else {
85-
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
86-
Keyword: keyword,
87-
OrderBy: opts.OrderBy,
88-
Private: opts.Private,
89-
Page: page,
90-
PageSize: opts.PageSize,
91-
})
92-
if err != nil {
93-
ctx.Handle(500, "SearchRepositoryByName", err)
94-
return
95+
if isKeywordValid(keyword) {
96+
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
97+
Keyword: keyword,
98+
OrderBy: opts.OrderBy,
99+
Private: opts.Private,
100+
Page: page,
101+
PageSize: opts.PageSize,
102+
})
103+
if err != nil {
104+
ctx.Handle(500, "SearchRepositoryByName", err)
105+
return
106+
}
95107
}
96108
}
97109
ctx.Data["Keyword"] = keyword
@@ -156,16 +168,18 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
156168
}
157169
count = opts.Counter()
158170
} else {
159-
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
160-
Keyword: keyword,
161-
Type: opts.Type,
162-
OrderBy: opts.OrderBy,
163-
Page: page,
164-
PageSize: opts.PageSize,
165-
})
166-
if err != nil {
167-
ctx.Handle(500, "SearchUserByName", err)
168-
return
171+
if isKeywordValid(keyword) {
172+
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
173+
Keyword: keyword,
174+
Type: opts.Type,
175+
OrderBy: opts.OrderBy,
176+
Page: page,
177+
PageSize: opts.PageSize,
178+
})
179+
if err != nil {
180+
ctx.Handle(500, "SearchUserByName", err)
181+
return
182+
}
169183
}
170184
}
171185
ctx.Data["Keyword"] = keyword

templates/explore/organizations.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</div>
2525
</div>
2626
</div>
27+
{{else}}
28+
<div>{{$.i18n.Tr "explore.org_no_results"}}</div>
2729
{{end}}
2830
</div>
2931

templates/explore/repo_list.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
2020
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
2121
</div>
22+
{{else}}
23+
<div>
24+
{{$.i18n.Tr "explore.repo_no_results"}}
25+
</div>
2226
{{end}}
2327
</div>

templates/explore/users.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</div>
2525
</div>
2626
</div>
27+
{{else}}
28+
<div>{{$.i18n.Tr "explore.user_no_results"}}</div>
2729
{{end}}
2830
</div>
2931

0 commit comments

Comments
 (0)