Skip to content

Commit b0118b4

Browse files
wxiaoguangwolfogrelunny
authored andcommitted
Make branches list page operations remember current page (go-gitea#23420)
Close go-gitea#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>
1 parent 1543ac9 commit b0118b4

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

Diff for: modules/context/pagination.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ type Pagination struct {
1818
urlParams []string
1919
}
2020

21-
// NewPagination creates a new instance of the Pagination struct
22-
func NewPagination(total, page, issueNum, numPages int) *Pagination {
21+
// NewPagination creates a new instance of the Pagination struct.
22+
// "pagingNum" is "page size" or "limit", "current" is "page"
23+
func NewPagination(total, pagingNum, current, numPages int) *Pagination {
2324
p := &Pagination{}
24-
p.Paginater = paginator.New(total, page, issueNum, numPages)
25+
p.Paginater = paginator.New(total, pagingNum, current, numPages)
2526
return p
2627
}
2728

Diff for: routers/web/repo/branch.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"net/url"
1112
"strings"
1213

1314
"code.gitea.io/gitea/models"
@@ -65,21 +66,17 @@ func Branches(ctx *context.Context) {
6566
if page <= 1 {
6667
page = 1
6768
}
69+
pageSize := setting.Git.BranchesRangeSize
6870

69-
limit := ctx.FormInt("limit")
70-
if limit <= 0 || limit > setting.Git.BranchesRangeSize {
71-
limit = setting.Git.BranchesRangeSize
72-
}
73-
74-
skip := (page - 1) * limit
75-
log.Debug("Branches: skip: %d limit: %d", skip, limit)
76-
defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, limit)
71+
skip := (page - 1) * pageSize
72+
log.Debug("Branches: skip: %d limit: %d", skip, pageSize)
73+
defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, pageSize)
7774
if ctx.Written() {
7875
return
7976
}
8077
ctx.Data["Branches"] = branches
8178
ctx.Data["DefaultBranchBranch"] = defaultBranchBranch
82-
pager := context.NewPagination(branchesCount, setting.Git.BranchesRangeSize, page, 5)
79+
pager := context.NewPagination(branchesCount, pageSize, page, 5)
8380
pager.SetDefaultParams(ctx)
8481
ctx.Data["Page"] = pager
8582

@@ -165,7 +162,7 @@ func RestoreBranchPost(ctx *context.Context) {
165162

166163
func redirect(ctx *context.Context) {
167164
ctx.JSON(http.StatusOK, map[string]interface{}{
168-
"redirect": ctx.Repo.RepoLink + "/branches",
165+
"redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")),
169166
})
170167
}
171168

Diff for: templates/repo/branch/list.tmpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
<td class="three wide right aligned">
8282
{{if not .LatestPullRequest}}
8383
{{if .IsIncluded}}
84-
<a class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right">
84+
<span class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right">
8585
{{svg "octicon-git-pull-request"}} {{$.locale.Tr "repo.branch.included"}}
86-
</a>
86+
</span>
8787
{{else if and (not .IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}
8888
<a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranch}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .Name}}">
8989
<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 @@
123123
{{end}}
124124
{{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}}
125125
{{if .IsDeleted}}
126-
<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">
126+
<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">
127127
<span class="text blue">
128128
{{svg "octicon-reply"}}
129129
</span>
130130
</button>
131131
{{else}}
132-
<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}}">
132+
<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}}">
133133
{{svg "octicon-trash"}}
134134
</button>
135135
{{end}}

0 commit comments

Comments
 (0)