summaryrefslogtreecommitdiffstats
path: root/routers/user
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-07-24 14:32:46 +0800
committerUnknwon <u@gogs.io>2016-07-24 14:32:46 +0800
commite74630ae3b635a43a1bdafcf8b80d2f87b3536b6 (patch)
tree63c5fb32b6ca4417c3dfd9c05f532d5598aa4117 /routers/user
parent1f2e173a745da8e4b57f96b5561a3c10054d3b76 (diff)
downloadgitea-e74630ae3b635a43a1bdafcf8b80d2f87b3536b6.tar.gz
gitea-e74630ae3b635a43a1bdafcf8b80d2f87b3536b6.zip
#1384 add pagination for repositories
Diffstat (limited to 'routers/user')
-rw-r--r--routers/user/home.go101
-rw-r--r--routers/user/profile.go25
2 files changed, 71 insertions, 55 deletions
diff --git a/routers/user/home.go b/routers/user/home.go
index 5316830b62..dab30eb5d2 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -55,8 +55,8 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
// retrieveFeeds loads feeds from database by given context user.
// The user could be organization so it is not always the logged in user,
// which is why we have to explicitly pass the context user ID.
-func retrieveFeeds(ctx *context.Context, ctxUserID, userID, offset int64, isProfile bool) {
- actions, err := models.GetFeeds(ctxUserID, userID, offset, isProfile)
+func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset int64, isProfile bool) {
+ actions, err := models.GetFeeds(ctxUser, userID, offset, isProfile)
if err != nil {
ctx.Handle(500, "GetFeeds", err)
return
@@ -98,54 +98,55 @@ func Dashboard(ctx *context.Context) {
// Only user can have collaborative repositories.
if !ctxUser.IsOrganization() {
- collaborateRepos, err := ctx.User.GetAccessibleRepositories()
+ collaborateRepos, err := ctx.User.GetAccessibleRepositories(setting.UI.User.RepoPagingNum)
if err != nil {
ctx.Handle(500, "GetAccessibleRepositories", err)
return
+ } else if err = models.RepositoryList(collaborateRepos).LoadAttributes(); err != nil {
+ ctx.Handle(500, "RepositoryList.LoadAttributes", err)
+ return
}
-
- for i := range collaborateRepos {
- if err = collaborateRepos[i].GetOwner(); err != nil {
- ctx.Handle(500, "GetOwner: "+collaborateRepos[i].Name, err)
- return
- }
- }
- ctx.Data["CollaborateCount"] = len(collaborateRepos)
ctx.Data["CollaborativeRepos"] = collaborateRepos
}
- var repos []*models.Repository
+ var err error
+ var repos, mirrors []*models.Repository
if ctxUser.IsOrganization() {
- if err := ctxUser.GetUserRepositories(ctx.User.ID); err != nil {
+ repos, _, err = ctxUser.GetUserRepositories(ctx.User.ID, 1, setting.UI.User.RepoPagingNum)
+ if err != nil {
ctx.Handle(500, "GetUserRepositories", err)
return
}
- repos = ctxUser.Repos
- } else {
- var err error
- repos, err = models.GetRepositories(ctxUser.ID, true)
+
+ mirrors, err = ctxUser.GetUserMirrorRepositories(ctx.User.ID)
if err != nil {
+ ctx.Handle(500, "GetUserMirrorRepositories", err)
+ return
+ }
+ } else {
+ if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
+ repos = ctxUser.Repos
+
+ mirrors, err = ctxUser.GetMirrorRepositories()
+ if err != nil {
+ ctx.Handle(500, "GetMirrorRepositories", err)
+ return
+ }
}
ctx.Data["Repos"] = repos
+ ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum
- // Get mirror repositories.
- mirrors := make([]*models.Repository, 0, 5)
- for _, repo := range repos {
- if repo.IsMirror {
- if err := repo.GetMirror(); err != nil {
- ctx.Handle(500, "GetMirror: "+repo.Name, err)
- return
- }
- mirrors = append(mirrors, repo)
- }
+ if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil {
+ ctx.Handle(500, "MirrorRepositoryList.LoadAttributes", err)
+ return
}
ctx.Data["MirrorCount"] = len(mirrors)
ctx.Data["Mirrors"] = mirrors
- retrieveFeeds(ctx, ctxUser.ID, ctx.User.ID, 0, false)
+ retrieveFeeds(ctx, ctxUser, ctx.User.ID, 0, false)
if ctx.Written() {
return
}
@@ -198,18 +199,21 @@ func Issues(ctx *context.Context) {
isShowClosed := ctx.Query("state") == "closed"
// Get repositories.
+ var err error
+ var repos []*models.Repository
if ctxUser.IsOrganization() {
- if err := ctxUser.GetUserRepositories(ctx.User.ID); err != nil {
+ repos, _, err = ctxUser.GetUserRepositories(ctx.User.ID, 1, ctx.User.NumRepos)
+ if err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
} else {
- if err := ctxUser.GetRepositories(); err != nil {
+ if err := ctxUser.GetRepositories(1, ctx.User.NumRepos); err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
+ repos = ctxUser.Repos
}
- repos := ctxUser.Repos
allCount := 0
repoIDs := make([]int64, 0, len(repos))
@@ -331,29 +335,34 @@ func showOrgProfile(ctx *context.Context) {
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
- if ctx.IsSigned {
- if ctx.User.IsAdmin {
- repos, err := models.GetRepositories(org.ID, true)
- if err != nil {
- ctx.Handle(500, "GetRepositoriesAsAdmin", err)
- return
- }
- ctx.Data["Repos"] = repos
- } else {
- if err := org.GetUserRepositories(ctx.User.ID); err != nil {
- ctx.Handle(500, "GetUserRepositories", err)
- return
- }
- ctx.Data["Repos"] = org.Repos
+ page := ctx.QueryInt("page")
+ if page <= 0 {
+ page = 1
+ }
+
+ var (
+ repos []*models.Repository
+ count int64
+ err error
+ )
+ if ctx.IsSigned && !ctx.User.IsAdmin {
+ repos, count, err = org.GetUserRepositories(ctx.User.ID, page, setting.UI.User.RepoPagingNum)
+ if err != nil {
+ ctx.Handle(500, "GetUserRepositories", err)
+ return
}
+ ctx.Data["Repos"] = repos
} else {
- repos, err := models.GetRepositories(org.ID, false)
+ showPrivate := ctx.IsSigned && ctx.User.IsAdmin
+ repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum)
if err != nil {
ctx.Handle(500, "GetRepositories", 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.Handle(500, "GetMembers", err)
diff --git a/routers/user/profile.go b/routers/user/profile.go
index 0e436eac41..363705dd01 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -9,6 +9,8 @@ import (
"path"
"strings"
+ "github.com/Unknwon/paginater"
+
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
@@ -55,27 +57,27 @@ func Profile(ctx *context.Context) {
isShowKeys = true
}
- u := GetUserByName(ctx, strings.TrimSuffix(uname, ".keys"))
+ ctxUser := GetUserByName(ctx, strings.TrimSuffix(uname, ".keys"))
if ctx.Written() {
return
}
// Show SSH keys.
if isShowKeys {
- ShowSSHKeys(ctx, u.ID)
+ ShowSSHKeys(ctx, ctxUser.ID)
return
}
- if u.IsOrganization() {
+ if ctxUser.IsOrganization() {
showOrgProfile(ctx)
return
}
- ctx.Data["Title"] = u.DisplayName()
+ ctx.Data["Title"] = ctxUser.DisplayName()
ctx.Data["PageIsUserProfile"] = true
- ctx.Data["Owner"] = u
+ ctx.Data["Owner"] = ctxUser
- orgs, err := models.GetOrgsByUserID(u.ID, ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID))
+ orgs, err := models.GetOrgsByUserID(ctxUser.ID, ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID))
if err != nil {
ctx.Handle(500, "GetOrgsByUserIDDesc", err)
return
@@ -87,17 +89,22 @@ func Profile(ctx *context.Context) {
ctx.Data["TabName"] = tab
switch tab {
case "activity":
- retrieveFeeds(ctx, u.ID, -1, 0, true)
+ retrieveFeeds(ctx, ctxUser, -1, 0, true)
if ctx.Written() {
return
}
default:
- var err error
- ctx.Data["Repos"], err = models.GetRepositories(u.ID, ctx.IsSigned && ctx.User.ID == u.ID)
+ page := ctx.QueryInt("page")
+ if page <= 0 {
+ page = 1
+ }
+
+ ctx.Data["Repos"], err = models.GetUserRepositories(ctxUser.ID, ctx.IsSigned && ctx.User.ID == ctxUser.ID, page, setting.UI.User.RepoPagingNum)
if err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
+ ctx.Data["Page"] = paginater.New(ctxUser.NumRepos, setting.UI.User.RepoPagingNum, page, 5)
}
ctx.HTML(200, PROFILE)