aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-12-30 09:57:38 +0800
committerGitHub <noreply@github.com>2024-12-30 01:57:38 +0000
commitcd1b5488a31ff208b511302905330499167faa10 (patch)
treefa13e9950c7fc3400412bd2b21a432d40e29e727
parent1dbf0d7f0822c10b379a21c192c2d63e34fd52f9 (diff)
downloadgitea-cd1b5488a31ff208b511302905330499167faa10.tar.gz
gitea-cd1b5488a31ff208b511302905330499167faa10.zip
Refactor pagination (#33037)
I am sure the simple approach should work, let's try it in 1.24 Follow #29834 and #29841
-rw-r--r--models/user/search.go2
-rw-r--r--routers/web/admin/emails.go2
-rw-r--r--routers/web/admin/packages.go4
-rw-r--r--routers/web/admin/repos.go7
-rw-r--r--routers/web/admin/users.go5
-rw-r--r--routers/web/explore/code.go3
-rw-r--r--routers/web/explore/repo.go21
-rw-r--r--routers/web/explore/user.go5
-rw-r--r--routers/web/org/home.go19
-rw-r--r--routers/web/org/projects.go2
-rw-r--r--routers/web/repo/actions/actions.go6
-rw-r--r--routers/web/repo/branch.go2
-rw-r--r--routers/web/repo/commit.go14
-rw-r--r--routers/web/repo/milestone.go4
-rw-r--r--routers/web/repo/packages.go3
-rw-r--r--routers/web/repo/projects.go2
-rw-r--r--routers/web/repo/release.go4
-rw-r--r--routers/web/repo/search.go3
-rw-r--r--routers/web/repo/wiki.go3
-rw-r--r--routers/web/user/code.go3
-rw-r--r--routers/web/user/home.go7
-rw-r--r--routers/web/user/notification.go22
-rw-r--r--routers/web/user/package.go13
-rw-r--r--routers/web/user/setting/profile.go4
-rw-r--r--services/context/pagination.go24
25 files changed, 33 insertions, 151 deletions
diff --git a/models/user/search.go b/models/user/search.go
index 6af3389237..85915f4020 100644
--- a/models/user/search.go
+++ b/models/user/search.go
@@ -39,8 +39,6 @@ type SearchUserOptions struct {
IsTwoFactorEnabled optional.Option[bool]
IsProhibitLogin optional.Option[bool]
IncludeReserved bool
-
- ExtraParamStrings map[string]string
}
func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Session {
diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go
index e925de8937..23ddfa583a 100644
--- a/routers/web/admin/emails.go
+++ b/routers/web/admin/emails.go
@@ -94,7 +94,7 @@ func Emails(ctx *context.Context) {
ctx.Data["Emails"] = emails
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplEmails)
diff --git a/routers/web/admin/packages.go b/routers/web/admin/packages.go
index da345f2f89..5122342259 100644
--- a/routers/web/admin/packages.go
+++ b/routers/web/admin/packages.go
@@ -77,9 +77,7 @@ func Packages(ctx *context.Context) {
ctx.Data["TotalUnreferencedBlobSize"] = totalUnreferencedBlobSize
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
- pager.AddParamString("q", query)
- pager.AddParamString("type", packageType)
- pager.AddParamString("sort", sort)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplPackagesList)
diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go
index 27d39dcf4b..1bc8abb88c 100644
--- a/routers/web/admin/repos.go
+++ b/routers/web/admin/repos.go
@@ -4,7 +4,6 @@
package admin
import (
- "fmt"
"net/http"
"net/url"
"strings"
@@ -84,8 +83,7 @@ func UnadoptedRepos(ctx *context.Context) {
if !doSearch {
pager := context.NewPagination(0, opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("search", fmt.Sprint(doSearch))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplUnadoptedRepos)
return
@@ -99,8 +97,7 @@ func UnadoptedRepos(ctx *context.Context) {
}
ctx.Data["Dirs"] = repoNames
pager := context.NewPagination(count, opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("search", fmt.Sprint(doSearch))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplUnadoptedRepos)
}
diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go
index fdd18b2f9d..be2ba4424c 100644
--- a/routers/web/admin/users.go
+++ b/routers/web/admin/users.go
@@ -47,16 +47,12 @@ func Users(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users")
ctx.Data["PageIsAdminUsers"] = true
- extraParamStrings := map[string]string{}
statusFilterKeys := []string{"is_active", "is_admin", "is_restricted", "is_2fa_enabled", "is_prohibit_login"}
statusFilterMap := map[string]string{}
for _, filterKey := range statusFilterKeys {
paramKey := "status_filter[" + filterKey + "]"
paramVal := ctx.FormString(paramKey)
statusFilterMap[filterKey] = paramVal
- if paramVal != "" {
- extraParamStrings[paramKey] = paramVal
- }
}
sortType := ctx.FormString("sort")
@@ -82,7 +78,6 @@ func Users(ctx *context.Context) {
IsTwoFactorEnabled: util.OptionalBoolParse(statusFilterMap["is_2fa_enabled"]),
IsProhibitLogin: util.OptionalBoolParse(statusFilterMap["is_prohibit_login"]),
IncludeReserved: true, // administrator needs to list all accounts include reserved, bot, remote ones
- ExtraParamStrings: extraParamStrings,
}, tplUsers)
}
diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go
index 4df89253b4..3658144610 100644
--- a/routers/web/explore/code.go
+++ b/routers/web/explore/code.go
@@ -137,8 +137,7 @@ func Code(ctx *context.Context) {
ctx.Data["SearchResultLanguages"] = searchResultLanguages
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("l", language)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplExploreCode)
diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go
index c421aea715..cf3128314b 100644
--- a/routers/web/explore/repo.go
+++ b/routers/web/explore/repo.go
@@ -4,7 +4,6 @@
package explore
import (
- "fmt"
"net/http"
"code.gitea.io/gitea/models/db"
@@ -139,25 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
pager := context.NewPagination(int(count), opts.PageSize, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("topic", fmt.Sprint(topicOnly))
- pager.AddParamString("language", language)
- pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant))
- if archived.Has() {
- pager.AddParamString("archived", fmt.Sprint(archived.Value()))
- }
- if fork.Has() {
- pager.AddParamString("fork", fmt.Sprint(fork.Value()))
- }
- if mirror.Has() {
- pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
- }
- if template.Has() {
- pager.AddParamString("template", fmt.Sprint(template.Value()))
- }
- if private.Has() {
- pager.AddParamString("private", fmt.Sprint(private.Value()))
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, opts.TplName)
diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go
index ef103af8cf..b14272c76a 100644
--- a/routers/web/explore/user.go
+++ b/routers/web/explore/user.go
@@ -120,10 +120,7 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
- for paramKey, paramVal := range opts.ExtraParamStrings {
- pager.AddParamString(paramKey, paramVal)
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplName)
diff --git a/routers/web/org/home.go b/routers/web/org/home.go
index bdc43acc30..deeb18ae7c 100644
--- a/routers/web/org/home.go
+++ b/routers/web/org/home.go
@@ -4,7 +4,6 @@
package org
import (
- "fmt"
"net/http"
"path"
"strings"
@@ -146,23 +145,7 @@ func home(ctx *context.Context, viewRepositories bool) {
ctx.Data["Total"] = count
pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("language", language)
- if archived.Has() {
- pager.AddParamString("archived", fmt.Sprint(archived.Value()))
- }
- if fork.Has() {
- pager.AddParamString("fork", fmt.Sprint(fork.Value()))
- }
- if mirror.Has() {
- pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
- }
- if template.Has() {
- pager.AddParamString("template", fmt.Sprint(template.Value()))
- }
- if private.Has() {
- pager.AddParamString("private", fmt.Sprint(private.Value()))
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplOrgHome)
diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go
index efcc8fadc8..c037d4a7fd 100644
--- a/routers/web/org/projects.go
+++ b/routers/web/org/projects.go
@@ -120,7 +120,7 @@ func Projects(ctx *context.Context) {
}
pager := context.NewPagination(int(total), setting.UI.IssuePagingNum, page, numPages)
- pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go
index 099593bff0..f0d8d81fee 100644
--- a/routers/web/repo/actions/actions.go
+++ b/routers/web/repo/actions/actions.go
@@ -6,7 +6,6 @@ package actions
import (
"bytes"
stdCtx "context"
- "fmt"
"net/http"
"slices"
"strings"
@@ -262,10 +261,7 @@ func List(ctx *context.Context) {
ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx)
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("workflow", workflowID)
- pager.AddParamString("actor", fmt.Sprint(actorID))
- pager.AddParamString("status", fmt.Sprint(status))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index 72fd958e28..2bcd7821b4 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -87,7 +87,7 @@ func Branches(ctx *context.Context) {
ctx.Data["CommitStatuses"] = commitStatuses
ctx.Data["DefaultBranchBranch"] = defaultBranch
pager := context.NewPagination(int(branchesCount), pageSize, page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplBranch)
}
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index 6f534b9e2e..3655233312 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -101,7 +101,7 @@ func Commits(ctx *context.Context) {
ctx.Data["CommitCount"] = commitsCount
pager := context.NewPagination(int(commitsCount), pageSize, page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplCommits)
}
@@ -139,7 +139,6 @@ func Graph(ctx *context.Context) {
if err != nil {
log.Warn("GetCommitGraphsCount error for generate graph exclude prs: %t branches: %s in %-v, Will Ignore branches and try again. Underlying Error: %v", hidePRRefs, branches, ctx.Repo.Repository, err)
realBranches = []string{}
- branches = []string{}
graphCommitsCount, err = ctx.Repo.GetCommitGraphsCount(ctx, hidePRRefs, realBranches, files)
if err != nil {
ctx.ServerError("GetCommitGraphsCount", err)
@@ -175,14 +174,7 @@ func Graph(ctx *context.Context) {
ctx.Data["CommitCount"] = commitsCount
paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
- paginator.AddParamString("mode", mode)
- paginator.AddParamString("hide-pr-refs", fmt.Sprint(hidePRRefs))
- for _, branch := range branches {
- paginator.AddParamString("branch", branch)
- }
- for _, file := range files {
- paginator.AddParamString("file", file)
- }
+ paginator.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = paginator
if ctx.FormBool("div-only") {
ctx.HTML(http.StatusOK, tplGraphDiv)
@@ -262,7 +254,7 @@ func FileHistory(ctx *context.Context) {
ctx.Data["CommitCount"] = commitsCount
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplCommits)
}
diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go
index 392d87167a..6a0e6b25a9 100644
--- a/routers/web/repo/milestone.go
+++ b/routers/web/repo/milestone.go
@@ -4,7 +4,6 @@
package repo
import (
- "fmt"
"net/http"
"net/url"
@@ -93,8 +92,7 @@ func Milestones(ctx *context.Context) {
ctx.Data["IsShowClosed"] = isShowClosed
pager := context.NewPagination(int(total), setting.UI.IssuePagingNum, page, 5)
- pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
- pager.AddParamString("q", keyword)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplMilestone)
diff --git a/routers/web/repo/packages.go b/routers/web/repo/packages.go
index c8d3719bc0..5dcfd0454c 100644
--- a/routers/web/repo/packages.go
+++ b/routers/web/repo/packages.go
@@ -70,8 +70,7 @@ func Packages(ctx *context.Context) {
ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
- pager.AddParamString("q", query)
- pager.AddParamString("type", packageType)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplPackagesList)
diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go
index 4313b6c403..1800f60eae 100644
--- a/routers/web/repo/projects.go
+++ b/routers/web/repo/projects.go
@@ -115,7 +115,7 @@ func Projects(ctx *context.Context) {
}
pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, numPages)
- pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index b8176cb70b..5b099fe8d4 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -186,7 +186,7 @@ func Releases(ctx *context.Context) {
numReleases := ctx.Data["NumReleases"].(int64)
pager := context.NewPagination(int(numReleases), listOptions.PageSize, listOptions.Page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplReleasesList)
}
@@ -240,7 +240,7 @@ func TagsList(ctx *context.Context) {
ctx.Data["TagCount"] = count
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases)
ctx.HTML(http.StatusOK, tplTagsList)
diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go
index a037a34833..cbc7e2e0fe 100644
--- a/routers/web/repo/search.go
+++ b/routers/web/repo/search.go
@@ -108,8 +108,7 @@ func Search(ctx *context.Context) {
ctx.Data["SearchResultLanguages"] = searchResultLanguages
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("l", language)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplSearch)
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index 3fca7cebea..19366c0104 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -440,8 +440,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commitsHistory, ctx.Repo.Repository)
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("action", "_revision")
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
return wikiRepo, entry
diff --git a/routers/web/user/code.go b/routers/web/user/code.go
index f805f2b028..9d515596f1 100644
--- a/routers/web/user/code.go
+++ b/routers/web/user/code.go
@@ -121,8 +121,7 @@ func CodeSearch(ctx *context.Context) {
ctx.Data["SearchResultLanguages"] = searchResultLanguages
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("l", language)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplUserCode)
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index b5d3a7294b..c79648a455 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -139,7 +139,7 @@ func Dashboard(ctx *context.Context) {
ctx.Data["Feeds"] = feeds
pager := context.NewPagination(int(count), setting.UI.FeedPagingNum, page, 5)
- pager.AddParamString("date", date)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplDashboard)
@@ -330,10 +330,7 @@ func Milestones(ctx *context.Context) {
ctx.Data["IsShowClosed"] = isShowClosed
pager := context.NewPagination(pagerCount, setting.UI.IssuePagingNum, page, 5)
- pager.AddParamString("q", keyword)
- pager.AddParamString("repos", reposQuery)
- pager.AddParamString("sort", sortType)
- pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplMilestones)
diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go
index 732fac2595..1c91ff6364 100644
--- a/routers/web/user/notification.go
+++ b/routers/web/user/notification.go
@@ -173,7 +173,7 @@ func getNotifications(ctx *context.Context) {
ctx.Data["Status"] = status
ctx.Data["Notifications"] = notifications
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
}
@@ -357,8 +357,7 @@ func NotificationSubscriptions(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current()))
return
}
- pager.AddParamString("sort", sortType)
- pager.AddParamString("state", state)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplNotificationSubscriptions)
@@ -446,22 +445,7 @@ func NotificationWatching(ctx *context.Context) {
// redirect to last page if request page is more than total pages
pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- if archived.Has() {
- pager.AddParamString("archived", fmt.Sprint(archived.Value()))
- }
- if fork.Has() {
- pager.AddParamString("fork", fmt.Sprint(fork.Value()))
- }
- if mirror.Has() {
- pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
- }
- if template.Has() {
- pager.AddParamString("template", fmt.Sprint(template.Value()))
- }
- if private.Has() {
- pager.AddParamString("private", fmt.Sprint(private.Value()))
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.Data["Status"] = 2
diff --git a/routers/web/user/package.go b/routers/web/user/package.go
index 8d78da7c5a..1f75faf1c6 100644
--- a/routers/web/user/package.go
+++ b/routers/web/user/package.go
@@ -128,8 +128,7 @@ func ListPackages(ctx *context.Context) {
}
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
- pager.AddParamString("q", query)
- pager.AddParamString("type", packageType)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplPackagesList)
@@ -348,11 +347,6 @@ func ListPackageVersions(ctx *context.Context) {
ctx.Data["Query"] = query
ctx.Data["Sort"] = sort
- pagerParams := map[string]string{
- "q": query,
- "sort": sort,
- }
-
var (
total int64
pvs []*packages_model.PackageVersion
@@ -361,7 +355,6 @@ func ListPackageVersions(ctx *context.Context) {
case packages_model.TypeContainer:
tagged := ctx.FormTrim("tagged")
- pagerParams["tagged"] = tagged
ctx.Data["Tagged"] = tagged
pvs, total, err = container_model.SearchImageTags(ctx, &container_model.ImageTagsSearchOptions{
@@ -407,9 +400,7 @@ func ListPackageVersions(ctx *context.Context) {
}
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
- for k, v := range pagerParams {
- pager.AddParamString(k, v)
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplPackageVersionList)
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index 4b3c214096..ebf682bf58 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -222,7 +222,7 @@ func Organization(ctx *context.Context) {
ctx.Data["Orgs"] = orgs
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplSettingsOrganization)
}
@@ -329,7 +329,7 @@ func Repos(ctx *context.Context) {
}
ctx.Data["ContextUser"] = ctxUser
pager := context.NewPagination(count, opts.PageSize, opts.Page, 5)
- pager.SetDefaultParams(ctx)
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplSettingsRepositories)
}
diff --git a/services/context/pagination.go b/services/context/pagination.go
index 42117cf96d..d33dd217d0 100644
--- a/services/context/pagination.go
+++ b/services/context/pagination.go
@@ -27,19 +27,13 @@ func NewPagination(total, pagingNum, current, numPages int) *Pagination {
return p
}
-// AddParamString adds a string parameter directly
-func (p *Pagination) AddParamString(key, value string) {
- urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(key), url.QueryEscape(value))
- p.urlParams = append(p.urlParams, urlParam)
-}
-
func (p *Pagination) AddParamFromRequest(req *http.Request) {
for key, values := range req.URL.Query() {
- if key == "page" || len(values) == 0 {
+ if key == "page" || len(values) == 0 || (len(values) == 1 && values[0] == "") {
continue
}
for _, value := range values {
- urlParam := fmt.Sprintf("%s=%v", key, url.QueryEscape(value))
+ urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(key), url.QueryEscape(value))
p.urlParams = append(p.urlParams, urlParam)
}
}
@@ -49,17 +43,3 @@ func (p *Pagination) AddParamFromRequest(req *http.Request) {
func (p *Pagination) GetParams() template.URL {
return template.URL(strings.Join(p.urlParams, "&"))
}
-
-// SetDefaultParams sets common pagination params that are often used
-func (p *Pagination) SetDefaultParams(ctx *Context) {
- if v, ok := ctx.Data["SortType"].(string); ok {
- p.AddParamString("sort", v)
- }
- if v, ok := ctx.Data["Keyword"].(string); ok {
- p.AddParamString("q", v)
- }
- if v, ok := ctx.Data["IsFuzzy"].(bool); ok {
- p.AddParamString("fuzzy", fmt.Sprint(v))
- }
- // do not add any more uncommon params here!
-}