summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2017-02-04 20:20:20 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-04 20:20:20 +0800
commita90a215662636fed1a2c67b49cf060e2936822f6 (patch)
tree78ff0fbcb36fb252e671fdbff6011483aca53ce6 /routers
parentde81f68d4d4a87c044034be682abffaccd399860 (diff)
downloadgitea-a90a215662636fed1a2c67b49cf060e2936822f6.tar.gz
gitea-a90a215662636fed1a2c67b49cf060e2936822f6.zip
feat: Add search bar on user profile page. (#787)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/repo.go2
-rw-r--r--routers/user/home.go2
-rw-r--r--routers/user/profile.go64
3 files changed, 61 insertions, 7 deletions
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index fea625fbe7..d65f30d729 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -80,7 +80,7 @@ func Search(ctx *context.APIContext) {
// ListMyRepos list all my repositories
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
func ListMyRepos(ctx *context.APIContext) {
- ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos)
+ ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos, "")
if err != nil {
ctx.Error(500, "GetRepositories", err)
return
diff --git a/routers/user/home.go b/routers/user/home.go
index e043f67bea..09711f4bc0 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -383,7 +383,7 @@ func showOrgProfile(ctx *context.Context) {
ctx.Data["Repos"] = repos
} else {
showPrivate := ctx.IsSigned && ctx.User.IsAdmin
- repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum)
+ repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum, "")
if err != nil {
ctx.Handle(500, "GetRepositories", err)
return
diff --git a/routers/user/profile.go b/routers/user/profile.go
index 857b9e3f5b..3b4d5a6b3c 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -109,12 +109,66 @@ func Profile(ctx *context.Context) {
page = 1
}
- ctx.Data["Repos"], err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum)
- if err != nil {
- ctx.Handle(500, "GetRepositories", err)
- return
+ var (
+ repos []*models.Repository
+ count int64
+ err error
+ orderBy string
+ )
+ switch ctx.Query("sort") {
+ case "newest":
+ orderBy = "created_unix DESC"
+ case "oldest":
+ orderBy = "created_unix ASC"
+ case "recentupdate":
+ orderBy = "updated_unix DESC"
+ case "leastupdate":
+ orderBy = "updated_unix ASC"
+ case "reversealphabetically":
+ orderBy = "name DESC"
+ case "alphabetically":
+ orderBy = "name ASC"
+ default:
+ orderBy = "updated_unix DESC"
+ }
+
+ keyword := ctx.Query("q")
+ if len(keyword) == 0 {
+ repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy)
+ if err != nil {
+ ctx.Handle(500, "GetRepositories", err)
+ return
+ }
+ ctx.Data["Repos"] = repos
+ ctx.Data["Page"] = paginater.New(ctxUser.NumRepos, setting.UI.User.RepoPagingNum, page, 5)
+ ctx.Data["Total"] = ctxUser.NumRepos
+ } else {
+ repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
+ Keyword: keyword,
+ OwnerID: ctxUser.ID,
+ OrderBy: orderBy,
+ Private: ctx.IsSigned && ctx.User.ID == ctxUser.ID,
+ Page: page,
+ PageSize: setting.UI.User.RepoPagingNum,
+ })
+ if err != nil {
+ ctx.Handle(500, "SearchRepositoryByName", err)
+ return
+ }
+
+ ctx.Data["Repos"] = repos
+ ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5)
+ ctx.Data["Total"] = count
}
- ctx.Data["Page"] = paginater.New(ctxUser.NumRepos, setting.UI.User.RepoPagingNum, page, 5)
+
+ // set default sort value.
+ if ctx.Query("sort") == "" {
+ ctx.Data["SortType"] = "recentupdate"
+ } else {
+ ctx.Data["SortType"] = ctx.Query("sort")
+ }
+
+ ctx.Data["Keyword"] = keyword
}
ctx.HTML(200, tplProfile)