Skip to content

Commit cfdb950

Browse files
committed
fix
1 parent bf6502a commit cfdb950

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

modules/translation/mock.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
)
1010

1111
// MockLocale provides a mocked locale without any translations
12-
type MockLocale struct{}
12+
type MockLocale struct {
13+
Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
14+
}
1315

1416
var _ Locale = (*MockLocale)(nil)
1517

modules/translation/translation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func Match(tags ...language.Tag) language.Tag {
144144
// locale represents the information of localization.
145145
type locale struct {
146146
i18n.Locale
147-
Lang, LangName string // these fields are used directly in templates: .i18n.Lang
147+
Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
148148
msgPrinter *message.Printer
149149
}
150150

routers/web/user/home_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
repo_model "code.gitea.io/gitea/models/repo"
1212
"code.gitea.io/gitea/models/unittest"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/templates"
15+
"code.gitea.io/gitea/services/context"
1416
"code.gitea.io/gitea/services/contexttest"
1517

1618
"github.com/stretchr/testify/assert"
@@ -113,3 +115,18 @@ func TestMilestonesForSpecificRepo(t *testing.T) {
113115
assert.Len(t, ctx.Data["Milestones"], 1)
114116
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
115117
}
118+
119+
func TestDashboardPagination(t *testing.T) {
120+
ctx, _ := contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.HTMLRenderer()})
121+
page := context.NewPagination(10, 3, 1, 3)
122+
123+
setting.AppSubURL = "/SubPath"
124+
out, err := ctx.RenderToHTML("base/paginate", map[string]any{"Link": setting.AppSubURL, "Page": page})
125+
assert.NoError(t, err)
126+
assert.Contains(t, out, `<a class=" item navigation" href="/SubPath/?page=2">`)
127+
128+
setting.AppSubURL = ""
129+
out, err = ctx.RenderToHTML("base/paginate", map[string]any{"Link": setting.AppSubURL, "Page": page})
130+
assert.NoError(t, err)
131+
assert.Contains(t, out, `<a class=" item navigation" href="/?page=2">`)
132+
}

services/contexttest/context_tests.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/url"
1313
"strings"
1414
"testing"
15+
"time"
1516

1617
access_model "code.gitea.io/gitea/models/perm/access"
1718
repo_model "code.gitea.io/gitea/models/repo"
@@ -61,7 +62,8 @@ func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*cont
6162
base.Locale = &translation.MockLocale{}
6263

6364
ctx := context.NewWebContext(base, opt.Render, nil)
64-
65+
ctx.PageData = map[string]interface{}{}
66+
ctx.Data["PageStartTime"] = time.Now()
6567
chiCtx := chi.NewRouteContext()
6668
ctx.Base.AppendContextValue(chi.RouteCtxKey, chiCtx)
6769
return ctx, resp

templates/base/paginate.tmpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
{{$paginationLink := .Page.GetParams}}
1+
{{$paginationParams := .Page.GetParams}}
2+
{{$paginationLink := $.Link}}
3+
{{if eq $paginationLink AppSubUrl}}{{$paginationLink = print $paginationLink "/"}}{{end}}
24
{{with .Page.Paginater}}
35
{{if gt .TotalPages 1}}
46
<div class="center page buttons">
57
<div class="ui borderless pagination menu">
6-
<a class="{{if .IsFirst}}disabled{{end}} item navigation" {{if not .IsFirst}}href="{{$.Link}}{{if $paginationLink}}?{{$paginationLink}}{{end}}"{{end}}>
8+
<a class="{{if .IsFirst}}disabled{{end}} item navigation" {{if not .IsFirst}}href="{{$paginationLink}}{{if $paginationParams}}?{{$paginationParams}}{{end}}"{{end}}>
79
{{svg "gitea-double-chevron-left" 16 "gt-mr-2"}}
810
<span class="navigation_label">{{ctx.Locale.Tr "admin.first_page"}}</span>
911
</a>
10-
<a class="{{if not .HasPrevious}}disabled{{end}} item navigation" {{if .HasPrevious}}href="{{$.Link}}?page={{.Previous}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
12+
<a class="{{if not .HasPrevious}}disabled{{end}} item navigation" {{if .HasPrevious}}href="{{$paginationLink}}?page={{.Previous}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
1113
{{svg "octicon-chevron-left" 16 "gt-mr-2"}}
1214
<span class="navigation_label">{{ctx.Locale.Tr "repo.issues.previous"}}</span>
1315
</a>
1416
{{range .Pages}}
1517
{{if eq .Num -1}}
1618
<a class="disabled item">...</a>
1719
{{else}}
18-
<a class="{{if .IsCurrent}}active {{end}}item gt-content-center" {{if not .IsCurrent}}href="{{$.Link}}?page={{.Num}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>{{.Num}}</a>
20+
<a class="{{if .IsCurrent}}active {{end}}item gt-content-center" {{if not .IsCurrent}}href="{{$paginationLink}}?page={{.Num}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>{{.Num}}</a>
1921
{{end}}
2022
{{end}}
21-
<a class="{{if not .HasNext}}disabled{{end}} item navigation" {{if .HasNext}}href="{{$.Link}}?page={{.Next}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
23+
<a class="{{if not .HasNext}}disabled{{end}} item navigation" {{if .HasNext}}href="{{$paginationLink}}?page={{.Next}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
2224
<span class="navigation_label">{{ctx.Locale.Tr "repo.issues.next"}}</span>
2325
{{svg "octicon-chevron-right" 16 "gt-ml-2"}}
2426
</a>
25-
<a class="{{if .IsLast}}disabled{{end}} item navigation" {{if not .IsLast}}href="{{$.Link}}?page={{.TotalPages}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
27+
<a class="{{if .IsLast}}disabled{{end}} item navigation" {{if not .IsLast}}href="{{$paginationLink}}?page={{.TotalPages}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
2628
<span class="navigation_label">{{ctx.Locale.Tr "admin.last_page"}}</span>
2729
{{svg "gitea-double-chevron-right" 16 "gt-ml-2"}}
2830
</a>

0 commit comments

Comments
 (0)