aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2017-02-14 15:28:22 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-14 15:28:22 +0800
commit23aba523b551d20ee2bbc694ae630989bcdeaccd (patch)
tree61f0aa0e9a50dcbc924b9d4cacdf3e90936ab7a4 /routers
parent7eb8daffa3181f6bae7aac95d536c68c6bed0e33 (diff)
downloadgitea-23aba523b551d20ee2bbc694ae630989bcdeaccd.tar.gz
gitea-23aba523b551d20ee2bbc694ae630989bcdeaccd.zip
feat: support search bar on star tab of user profile. (#917)
* feat: support search bar on star tab of user profile. * fix: update testing. * fix: Using loadAttributes * fix: remove empty line. * remove LOWER Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/user/profile.go121
1 files changed, 66 insertions, 55 deletions
diff --git a/routers/user/profile.go b/routers/user/profile.go
index f0b1be3060..bb1ab64e02 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -90,6 +90,44 @@ func Profile(ctx *context.Context) {
tab := ctx.Query("tab")
ctx.Data["TabName"] = tab
+
+ page := ctx.QueryInt("page")
+ if page <= 0 {
+ page = 1
+ }
+
+ var (
+ repos []*models.Repository
+ count int64
+ orderBy string
+ )
+
+ ctx.Data["SortType"] = ctx.Query("sort")
+ 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:
+ ctx.Data["SortType"] = "recentupdate"
+ orderBy = "updated_unix DESC"
+ }
+
+ // set default sort value if sort is empty.
+ if ctx.Query("sort") == "" {
+ ctx.Data["SortType"] = "recentupdate"
+ }
+
+ keyword := strings.Trim(ctx.Query("q"), " ")
+ ctx.Data["Keyword"] = keyword
switch tab {
case "activity":
retrieveFeeds(ctx, ctxUser, -1, 0, !showPrivate)
@@ -97,66 +135,39 @@ func Profile(ctx *context.Context) {
return
}
case "stars":
- page := ctx.QueryInt("page")
- if page <= 0 {
- page = 1
- }
-
- repos, err := ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, "")
- if err != nil {
- ctx.Handle(500, "GetStarredRepos", err)
- return
- }
+ ctx.Data["PageIsProfileStarList"] = true
+ if len(keyword) == 0 {
+ repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy)
+ if err != nil {
+ ctx.Handle(500, "GetStarredRepos", err)
+ return
+ }
- counts, err := ctxUser.GetStarredRepoCount(showPrivate)
- if err != nil {
- ctx.Handle(500, "GetStarredRepoCount", err)
- return
+ count, err = ctxUser.GetStarredRepoCount(showPrivate)
+ if err != nil {
+ ctx.Handle(500, "GetStarredRepoCount", err)
+ return
+ }
+ } else {
+ repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
+ Keyword: keyword,
+ OwnerID: ctxUser.ID,
+ OrderBy: orderBy,
+ Private: showPrivate,
+ Page: page,
+ PageSize: setting.UI.User.RepoPagingNum,
+ Starred: true,
+ })
+ if err != nil {
+ ctx.Handle(500, "SearchRepositoryByName", err)
+ return
+ }
}
ctx.Data["Repos"] = repos
- ctx.Data["Page"] = paginater.New(int(counts), setting.UI.User.RepoPagingNum, page, 5)
- ctx.Data["Total"] = int(counts)
- ctx.Data["Tabs"] = "stars"
+ ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5)
+ ctx.Data["Total"] = count
default:
- page := ctx.QueryInt("page")
- if page <= 0 {
- page = 1
- }
-
- var (
- repos []*models.Repository
- count int64
- err error
- orderBy string
- )
-
- ctx.Data["SortType"] = ctx.Query("sort")
- 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:
- ctx.Data["SortType"] = "recentupdate"
- orderBy = "updated_unix DESC"
- }
-
- // set default sort value if sort is empty.
- if ctx.Query("sort") == "" {
- ctx.Data["SortType"] = "recentupdate"
- }
-
- keyword := strings.Trim(ctx.Query("q"), " ")
- ctx.Data["Keyword"] = keyword
if len(keyword) == 0 {
var total int
repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy)