aboutsummaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
authorBrecht Van Lommel2023-02-24 22:15:10 +0100
committerGitHub2023-02-24 16:15:10 -0500
commitf4920c9c7f5947d3b6476610f39bc3492ab4ef3b (patch)
tree36a4063c1ec25766808a73a2190a50cf13a7b18d /routers
parent740a5ecdd925aec8dcea3e73da07868f70cdacac (diff)
Add pagination for dashboard and user activity feeds (#22937)
Previously only the last few activities where available. This works for all activity and for activity on a date chosen on the heatmap.
Diffstat (limited to 'routers')
-rw-r--r--routers/web/feed/profile.go2
-rw-r--r--routers/web/feed/repo.go2
-rw-r--r--routers/web/user/home.go25
-rw-r--r--routers/web/user/profile.go34
4 files changed, 49 insertions, 14 deletions
diff --git a/routers/web/feed/profile.go b/routers/web/feed/profile.go
index 764176919..b9dda2fc1 100644
--- a/routers/web/feed/profile.go
+++ b/routers/web/feed/profile.go
@@ -26,7 +26,7 @@ func ShowUserFeedAtom(ctx *context.Context) {
func showUserFeed(ctx *context.Context, formatType string) {
includePrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
- actions, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
+ actions, _, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
RequestedUser: ctx.ContextUser,
Actor: ctx.Doer,
IncludePrivate: includePrivate,
diff --git a/routers/web/feed/repo.go b/routers/web/feed/repo.go
index 1d24b5880..5fcad2677 100644
--- a/routers/web/feed/repo.go
+++ b/routers/web/feed/repo.go
@@ -15,7 +15,7 @@ import (
// ShowRepoFeed shows user activity on the repo as RSS / Atom feed
func ShowRepoFeed(ctx *context.Context, repo *repo_model.Repository, formatType string) {
- actions, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
+ actions, _, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
RequestedRepo: repo,
Actor: ctx.Doer,
IncludePrivate: true,
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index 4f45c1d5c..2593ab148 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -72,12 +72,23 @@ func Dashboard(ctx *context.Context) {
return
}
+ var (
+ date = ctx.FormString("date")
+ page = ctx.FormInt("page")
+ )
+
+ // Make sure page number is at least 1. Will be posted to ctx.Data.
+ if page <= 1 {
+ page = 1
+ }
+
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
ctx.Data["PageIsDashboard"] = true
ctx.Data["PageIsNews"] = true
cnt, _ := organization.GetOrganizationCount(ctx, ctxUser)
ctx.Data["UserOrgsCount"] = cnt
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
+ ctx.Data["Date"] = date
var uid int64
if ctxUser != nil {
@@ -98,8 +109,7 @@ func Dashboard(ctx *context.Context) {
ctx.Data["HeatmapData"] = data
}
- var err error
- ctx.Data["Feeds"], err = activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
+ feeds, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
RequestedUser: ctxUser,
RequestedTeam: ctx.Org.Team,
Actor: ctx.Doer,
@@ -107,13 +117,22 @@ func Dashboard(ctx *context.Context) {
OnlyPerformedBy: false,
IncludeDeleted: false,
Date: ctx.FormString("date"),
- ListOptions: db.ListOptions{PageSize: setting.UI.FeedPagingNum},
+ ListOptions: db.ListOptions{
+ Page: page,
+ PageSize: setting.UI.FeedPagingNum,
+ },
})
if err != nil {
ctx.ServerError("GetFeeds", err)
return
}
+ ctx.Data["Feeds"] = feeds
+
+ pager := context.NewPagination(int(count), setting.UI.FeedPagingNum, page, 5)
+ pager.AddParam(ctx, "date", "Date")
+ ctx.Data["Page"] = pager
+
ctx.HTML(http.StatusOK, tplDashboard)
}
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index 4f0a81656..b44526045 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -119,6 +119,11 @@ func Profile(ctx *context.Context) {
page = 1
}
+ pagingNum := setting.UI.User.RepoPagingNum
+ if tab == "activity" {
+ pagingNum = setting.UI.FeedPagingNum
+ }
+
topicOnly := ctx.FormBool("topic")
var (
@@ -164,7 +169,7 @@ func Profile(ctx *context.Context) {
switch tab {
case "followers":
items, count, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
+ PageSize: pagingNum,
Page: page,
})
if err != nil {
@@ -176,7 +181,7 @@ func Profile(ctx *context.Context) {
total = int(count)
case "following":
items, count, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
+ PageSize: pagingNum,
Page: page,
})
if err != nil {
@@ -187,24 +192,32 @@ func Profile(ctx *context.Context) {
total = int(count)
case "activity":
- ctx.Data["Feeds"], err = activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
+ date := ctx.FormString("date")
+ items, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
RequestedUser: ctx.ContextUser,
Actor: ctx.Doer,
IncludePrivate: showPrivate,
OnlyPerformedBy: true,
IncludeDeleted: false,
- Date: ctx.FormString("date"),
- ListOptions: db.ListOptions{PageSize: setting.UI.FeedPagingNum},
+ Date: date,
+ ListOptions: db.ListOptions{
+ PageSize: pagingNum,
+ Page: page,
+ },
})
if err != nil {
ctx.ServerError("GetFeeds", err)
return
}
+ ctx.Data["Feeds"] = items
+ ctx.Data["Date"] = date
+
+ total = int(count)
case "stars":
ctx.Data["PageIsProfileStarList"] = true
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
+ PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
@@ -236,7 +249,7 @@ func Profile(ctx *context.Context) {
case "watching":
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
+ PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
@@ -258,7 +271,7 @@ func Profile(ctx *context.Context) {
default:
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
+ PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
@@ -281,12 +294,15 @@ func Profile(ctx *context.Context) {
ctx.Data["Repos"] = repos
ctx.Data["Total"] = total
- pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
+ pager := context.NewPagination(total, pagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "tab", "TabName")
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
pager.AddParam(ctx, "language", "Language")
}
+ if tab == "activity" {
+ pager.AddParam(ctx, "date", "Date")
+ }
ctx.Data["Page"] = pager
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled