1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-21 08:58:27 +00:00

Make branches list page operations remember current page (#23420) (#23459)

Backport #23420 by @wxiaoguang

Close #23411

Always pass "page" query parameter to backend, and make backend respect
it.

The `ctx.FormInt("limit")` is never used, so removed.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Jason Song <i@wolfogre.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
This commit is contained in:
Giteabot
2023-03-15 08:13:27 -04:00
committed by GitHub
parent 491ee43082
commit 04d489dbdd
3 changed files with 15 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"
"code.gitea.io/gitea/models"
@@ -66,21 +67,17 @@ func Branches(ctx *context.Context) {
if page <= 1 {
page = 1
}
pageSize := setting.Git.BranchesRangeSize
limit := ctx.FormInt("limit")
if limit <= 0 || limit > setting.Git.BranchesRangeSize {
limit = setting.Git.BranchesRangeSize
}
skip := (page - 1) * limit
log.Debug("Branches: skip: %d limit: %d", skip, limit)
defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, limit)
skip := (page - 1) * pageSize
log.Debug("Branches: skip: %d limit: %d", skip, pageSize)
defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, pageSize)
if ctx.Written() {
return
}
ctx.Data["Branches"] = branches
ctx.Data["DefaultBranchBranch"] = defaultBranchBranch
pager := context.NewPagination(branchesCount, setting.Git.BranchesRangeSize, page, 5)
pager := context.NewPagination(branchesCount, pageSize, page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
@@ -166,7 +163,7 @@ func RestoreBranchPost(ctx *context.Context) {
func redirect(ctx *context.Context) {
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/branches",
"redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")),
})
}