mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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.
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							740a5ecdd9
						
					
				
				
					commit
					f4920c9c7f
				
			@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user