]> source.dussan.org Git - gitea.git/commitdiff
Add a trailing slash to dashboard links (#29555) (#29573)
authorwxiaoguang <wxiaoguang@gmail.com>
Mon, 4 Mar 2024 05:50:55 +0000 (13:50 +0800)
committerGitHub <noreply@github.com>
Mon, 4 Mar 2024 05:50:55 +0000 (13:50 +0800)
Backport #29555

modules/contexttest/context_tests.go
modules/translation/mock.go
modules/translation/translation.go
routers/web/user/home_test.go
templates/base/paginate.tmpl

index 97d912ea5783b5293a488ecedab4c1cb9e429e2e..b9c1ab29642e59d7d778c4f059cd2ee093712e93 100644 (file)
@@ -12,6 +12,7 @@ import (
        "net/url"
        "strings"
        "testing"
+       "time"
 
        access_model "code.gitea.io/gitea/models/perm/access"
        repo_model "code.gitea.io/gitea/models/repo"
@@ -61,7 +62,8 @@ func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*cont
        base.Locale = &translation.MockLocale{}
 
        ctx := context.NewWebContext(base, opt.Render, nil)
-
+       ctx.PageData = map[string]any{}
+       ctx.Data["PageStartTime"] = time.Now()
        chiCtx := chi.NewRouteContext()
        ctx.Base.AppendContextValue(chi.RouteCtxKey, chiCtx)
        return ctx, resp
index 2d0cb173246bafdb6fac00521865a7f6e889b18e..d4c60e25177d99f774ad5dad4a92df49b98757b1 100644 (file)
@@ -6,7 +6,9 @@ package translation
 import "fmt"
 
 // MockLocale provides a mocked locale without any translations
-type MockLocale struct{}
+type MockLocale struct {
+       Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
+}
 
 var _ Locale = (*MockLocale)(nil)
 
index dba4de6607da08e8873796e1ca46ee7b510c2c7e..0acfe48c979eec5f6b9054561067e968cac25519 100644 (file)
@@ -140,7 +140,7 @@ func Match(tags ...language.Tag) language.Tag {
 // locale represents the information of localization.
 type locale struct {
        i18n.Locale
-       Lang, LangName string // these fields are used directly in templates: .i18n.Lang
+       Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
        msgPrinter     *message.Printer
 }
 
index 1eb1fad057172c778e95833b00cccd54400e03f2..418dac7bb3379c89117bb393cefa3d0e562d5654 100644 (file)
@@ -10,8 +10,10 @@ import (
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unittest"
+       "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/contexttest"
        "code.gitea.io/gitea/modules/setting"
+       "code.gitea.io/gitea/modules/templates"
 
        "github.com/stretchr/testify/assert"
 )
@@ -117,3 +119,18 @@ func TestMilestonesForSpecificRepo(t *testing.T) {
        assert.Len(t, ctx.Data["Milestones"], 1)
        assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
 }
+
+func TestDashboardPagination(t *testing.T) {
+       ctx, _ := contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.HTMLRenderer()})
+       page := context.NewPagination(10, 3, 1, 3)
+
+       setting.AppSubURL = "/SubPath"
+       out, err := ctx.RenderToString("base/paginate", map[string]any{"Link": setting.AppSubURL, "Page": page})
+       assert.NoError(t, err)
+       assert.Contains(t, out, `<a class=" item navigation" href="/SubPath/?page=2">`)
+
+       setting.AppSubURL = ""
+       out, err = ctx.RenderToString("base/paginate", map[string]any{"Link": setting.AppSubURL, "Page": page})
+       assert.NoError(t, err)
+       assert.Contains(t, out, `<a class=" item navigation" href="/?page=2">`)
+}
index 503817c3398f643c5dc398c0b086c51ebdbc14fd..ef7d0b341bcfdfd36d53b3706521433bc3a5f297 100644 (file)
@@ -1,13 +1,15 @@
-{{$paginationLink := .Page.GetParams}}
+{{$paginationParams := .Page.GetParams}}
+{{$paginationLink := $.Link}}
+{{if eq $paginationLink AppSubUrl}}{{$paginationLink = print $paginationLink "/"}}{{end}}
 {{with .Page.Paginater}}
        {{if gt .TotalPages 1}}
                <div class="center page buttons">
                        <div class="ui borderless pagination menu">
-                               <a class="{{if .IsFirst}}disabled{{end}} item navigation" {{if not .IsFirst}}href="{{$.Link}}{{if $paginationLink}}?{{$paginationLink}}{{end}}"{{end}}>
+                               <a class="{{if .IsFirst}}disabled{{end}} item navigation" {{if not .IsFirst}}href="{{$paginationLink}}{{if $paginationParams}}?{{$paginationParams}}{{end}}"{{end}}>
                                        {{svg "gitea-double-chevron-left" 16 "gt-mr-2"}}
                                        <span class="navigation_label">{{ctx.Locale.Tr "admin.first_page"}}</span>
                                </a>
-                               <a class="{{if not .HasPrevious}}disabled{{end}} item navigation" {{if .HasPrevious}}href="{{$.Link}}?page={{.Previous}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
+                               <a class="{{if not .HasPrevious}}disabled{{end}} item navigation" {{if .HasPrevious}}href="{{$paginationLink}}?page={{.Previous}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
                                        {{svg "octicon-chevron-left" 16 "gt-mr-2"}}
                                        <span class="navigation_label">{{ctx.Locale.Tr "repo.issues.previous"}}</span>
                                </a>
                                        {{if eq .Num -1}}
                                                <a class="disabled item">...</a>
                                        {{else}}
-                                               <a class="{{if .IsCurrent}}active {{end}}item gt-content-center" {{if not .IsCurrent}}href="{{$.Link}}?page={{.Num}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>{{.Num}}</a>
+                                               <a class="{{if .IsCurrent}}active {{end}}item gt-content-center" {{if not .IsCurrent}}href="{{$paginationLink}}?page={{.Num}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>{{.Num}}</a>
                                        {{end}}
                                {{end}}
-                               <a class="{{if not .HasNext}}disabled{{end}} item navigation" {{if .HasNext}}href="{{$.Link}}?page={{.Next}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
+                               <a class="{{if not .HasNext}}disabled{{end}} item navigation" {{if .HasNext}}href="{{$paginationLink}}?page={{.Next}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
                                        <span class="navigation_label">{{ctx.Locale.Tr "repo.issues.next"}}</span>
                                        {{svg "octicon-chevron-right" 16 "gt-ml-2"}}
                                </a>
-                               <a class="{{if .IsLast}}disabled{{end}} item navigation" {{if not .IsLast}}href="{{$.Link}}?page={{.TotalPages}}{{if $paginationLink}}&{{$paginationLink}}{{end}}"{{end}}>
+                               <a class="{{if .IsLast}}disabled{{end}} item navigation" {{if not .IsLast}}href="{{$paginationLink}}?page={{.TotalPages}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
                                        <span class="navigation_label">{{ctx.Locale.Tr "admin.last_page"}}</span>
                                        {{svg "gitea-double-chevron-right" 16 "gt-ml-2"}}
                                </a>