0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 23:33:15 -05:00

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

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: Jason Song <i@wolfogre.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
wxiaoguang 2023-03-14 13:11:38 +08:00 committed by GitHub
parent 0efa9d5649
commit 6ff5400af9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 17 deletions

View file

@ -18,10 +18,11 @@ type Pagination struct {
urlParams []string urlParams []string
} }
// NewPagination creates a new instance of the Pagination struct // NewPagination creates a new instance of the Pagination struct.
func NewPagination(total, page, issueNum, numPages int) *Pagination { // "pagingNum" is "page size" or "limit", "current" is "page"
func NewPagination(total, pagingNum, current, numPages int) *Pagination {
p := &Pagination{} p := &Pagination{}
p.Paginater = paginator.New(total, page, issueNum, numPages) p.Paginater = paginator.New(total, pagingNum, current, numPages)
return p return p
} }

View file

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

View file

@ -81,9 +81,9 @@
<td class="three wide right aligned"> <td class="three wide right aligned">
{{if not .LatestPullRequest}} {{if not .LatestPullRequest}}
{{if .IsIncluded}} {{if .IsIncluded}}
<a class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right"> <span class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right">
{{svg "octicon-git-pull-request"}} {{$.locale.Tr "repo.branch.included"}} {{svg "octicon-git-pull-request"}} {{$.locale.Tr "repo.branch.included"}}
</a> </span>
{{else if and (not .IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}} {{else if and (not .IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}
<a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranch}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .Name}}"> <a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranch}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .Name}}">
<button id="new-pull-request" class="ui compact basic button gt-mr-0">{{if $.CanPull}}{{$.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{$.locale.Tr "action.compare_branch"}}{{end}}</button> <button id="new-pull-request" class="ui compact basic button gt-mr-0">{{if $.CanPull}}{{$.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{$.locale.Tr "action.compare_branch"}}{{end}}</button>
@ -123,13 +123,13 @@
{{end}} {{end}}
{{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}}
{{if .IsDeleted}} {{if .IsDeleted}}
<button class="ui basic jump button icon tooltip undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}" data-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}" data-position="top right"> <button class="ui basic jump button icon tooltip undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}" data-position="top right">
<span class="text blue"> <span class="text blue">
{{svg "octicon-reply"}} {{svg "octicon-reply"}}
</span> </span>
</button> </button>
{{else}} {{else}}
<button class="ui basic jump button icon tooltip delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.Name}}" data-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-position="top right" data-name="{{.Name}}"> <button class="ui basic jump button icon tooltip delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.Name}}&page={{$.Page.Paginater.Current}}" data-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-position="top right" data-name="{{.Name}}">
{{svg "octicon-trash"}} {{svg "octicon-trash"}}
</button> </button>
{{end}} {{end}}