Skip to content

Commit faa05d6

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 3dc2724 commit faa05d6

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
@@ -19,10 +19,11 @@ type Pagination struct {
1919
urlParams []string
2020
}
2121

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

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"net/http"
12+
"net/url"
1213
"strings"
1314

1415
"code.gitea.io/gitea/models"
@@ -66,21 +67,17 @@ func Branches(ctx *context.Context) {
6667
if page <= 1 {
6768
page = 1
6869
}
70+
pageSize := setting.Git.BranchesRangeSize
6971

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

@@ -166,7 +163,7 @@ func RestoreBranchPost(ctx *context.Context) {
166163

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

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 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)