Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Upstream
Gitea
Commits
ba912146
Commit
ba912146
authored
6 years ago
by
Richard Mahn
Committed by
techknowlogick
6 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Feature - #3031 - search for org repos (#5986)
parent
7fb09f03
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
models/org.go
+9
-0
models/org.go
routers/user/home.go
+60
-9
routers/user/home.go
templates/explore/repo_search.tmpl
+1
-0
templates/explore/repo_search.tmpl
templates/org/home.tmpl
+1
-0
templates/org/home.tmpl
with
71 additions
and
9 deletions
+71
-9
models/org.go
View file @
ba912146
...
...
@@ -620,6 +620,7 @@ type AccessibleReposEnvironment interface {
RepoIDs
(
page
,
pageSize
int
)
([]
int64
,
error
)
Repos
(
page
,
pageSize
int
)
([]
*
Repository
,
error
)
MirrorRepos
()
([]
*
Repository
,
error
)
AddKeyword
(
keyword
string
)
}
type
accessibleReposEnv
struct
{
...
...
@@ -627,6 +628,7 @@ type accessibleReposEnv struct {
userID
int64
teamIDs
[]
int64
e
Engine
keyword
string
}
// AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
...
...
@@ -656,6 +658,9 @@ func (env *accessibleReposEnv) cond() builder.Cond {
if
len
(
env
.
teamIDs
)
>
0
{
cond
=
cond
.
Or
(
builder
.
In
(
"team_repo.team_id"
,
env
.
teamIDs
))
}
if
env
.
keyword
!=
""
{
cond
=
cond
.
And
(
builder
.
Like
{
"`repository`.lower_name"
,
strings
.
ToLower
(
env
.
keyword
)})
}
return
cond
}
...
...
@@ -731,3 +736,7 @@ func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) {
In
(
"`repository`.id"
,
repoIDs
)
.
Find
(
&
repos
)
}
func
(
env
*
accessibleReposEnv
)
AddKeyword
(
keyword
string
)
{
env
.
keyword
=
keyword
}
This diff is collapsed.
Click to expand it.
routers/user/home.go
View file @
ba912146
// Copyright 2014 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
...
...
@@ -387,6 +388,37 @@ func showOrgProfile(ctx *context.Context) {
org
:=
ctx
.
Org
.
Organization
ctx
.
Data
[
"Title"
]
=
org
.
DisplayName
()
var
orderBy
models
.
SearchOrderBy
ctx
.
Data
[
"SortType"
]
=
ctx
.
Query
(
"sort"
)
switch
ctx
.
Query
(
"sort"
)
{
case
"newest"
:
orderBy
=
models
.
SearchOrderByNewest
case
"oldest"
:
orderBy
=
models
.
SearchOrderByOldest
case
"recentupdate"
:
orderBy
=
models
.
SearchOrderByRecentUpdated
case
"leastupdate"
:
orderBy
=
models
.
SearchOrderByLeastUpdated
case
"reversealphabetically"
:
orderBy
=
models
.
SearchOrderByAlphabeticallyReverse
case
"alphabetically"
:
orderBy
=
models
.
SearchOrderByAlphabetically
case
"moststars"
:
orderBy
=
models
.
SearchOrderByStarsReverse
case
"feweststars"
:
orderBy
=
models
.
SearchOrderByStars
case
"mostforks"
:
orderBy
=
models
.
SearchOrderByForksReverse
case
"fewestforks"
:
orderBy
=
models
.
SearchOrderByForks
default
:
ctx
.
Data
[
"SortType"
]
=
"recentupdate"
orderBy
=
models
.
SearchOrderByRecentUpdated
}
keyword
:=
strings
.
Trim
(
ctx
.
Query
(
"q"
),
" "
)
ctx
.
Data
[
"Keyword"
]
=
keyword
page
:=
ctx
.
QueryInt
(
"page"
)
if
page
<=
0
{
page
=
1
...
...
@@ -403,6 +435,9 @@ func showOrgProfile(ctx *context.Context) {
ctx
.
ServerError
(
"AccessibleReposEnv"
,
err
)
return
}
if
len
(
keyword
)
!=
0
{
env
.
AddKeyword
(
keyword
)
}
repos
,
err
=
env
.
Repos
(
page
,
setting
.
UI
.
User
.
RepoPagingNum
)
if
err
!=
nil
{
ctx
.
ServerError
(
"env.Repos"
,
err
)
...
...
@@ -413,25 +448,41 @@ func showOrgProfile(ctx *context.Context) {
ctx
.
ServerError
(
"env.CountRepos"
,
err
)
return
}
ctx
.
Data
[
"Repos"
]
=
repos
}
else
{
showPrivate
:=
ctx
.
IsSigned
&&
ctx
.
User
.
IsAdmin
repos
,
err
=
models
.
GetUserRepositories
(
org
.
ID
,
showPrivate
,
page
,
setting
.
UI
.
User
.
RepoPagingNum
,
""
)
if
err
!=
nil
{
ctx
.
ServerError
(
"GetRepositories"
,
err
)
return
if
len
(
keyword
)
==
0
{
repos
,
err
=
models
.
GetUserRepositories
(
org
.
ID
,
showPrivate
,
page
,
setting
.
UI
.
User
.
RepoPagingNum
,
orderBy
.
String
())
if
err
!=
nil
{
ctx
.
ServerError
(
"GetRepositories"
,
err
)
return
}
count
=
models
.
CountUserRepositories
(
org
.
ID
,
showPrivate
)
}
else
{
repos
,
count
,
err
=
models
.
SearchRepositoryByName
(
&
models
.
SearchRepoOptions
{
Keyword
:
keyword
,
OwnerID
:
org
.
ID
,
OrderBy
:
orderBy
,
Private
:
showPrivate
,
Page
:
page
,
IsProfile
:
true
,
PageSize
:
setting
.
UI
.
User
.
RepoPagingNum
,
})
if
err
!=
nil
{
ctx
.
ServerError
(
"SearchRepositoryByName"
,
err
)
return
}
}
ctx
.
Data
[
"Repos"
]
=
repos
count
=
models
.
CountUserRepositories
(
org
.
ID
,
showPrivate
)
}
ctx
.
Data
[
"Page"
]
=
paginater
.
New
(
int
(
count
),
setting
.
UI
.
User
.
RepoPagingNum
,
page
,
5
)
if
err
:=
org
.
GetMembers
();
err
!=
nil
{
ctx
.
ServerError
(
"GetMembers"
,
err
)
return
}
ctx
.
Data
[
"Members"
]
=
org
.
Members
ctx
.
Data
[
"Repos"
]
=
repos
ctx
.
Data
[
"Total"
]
=
count
ctx
.
Data
[
"Page"
]
=
paginater
.
New
(
int
(
count
),
setting
.
UI
.
User
.
RepoPagingNum
,
page
,
5
)
ctx
.
Data
[
"Members"
]
=
org
.
Members
ctx
.
Data
[
"Teams"
]
=
org
.
Teams
ctx
.
HTML
(
200
,
tplOrgHome
)
...
...
This diff is collapsed.
Click to expand it.
templates/explore/repo_search.tmpl
View file @
ba912146
...
...
@@ -23,6 +23,7 @@
<div class="ui fluid action input">
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
<input type="hidden" name="tab" value="{{$.TabName}}">
<input type="hidden" name="sort" value="{{$.SortType}}">
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
</div>
</form>
...
...
This diff is collapsed.
Click to expand it.
templates/org/home.tmpl
View file @
ba912146
...
...
@@ -28,6 +28,7 @@
</div>
<div class="ui divider"></div>
{{end}}
{{template "explore/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment