enhance(ui): unify all paginations into one compact style (#40514)

Server lists and the dashboard repo list rendered pagination
differently, and the server one wasted a lot of space. All pagers now
show the first, last and current page plus neighbours in seven fixed
slots, so the arrows never move. Lists with an unknown total show
Previous, Next and the current page.

<img width="672" height="383" alt="Before and after of numbered,
dashboard and previous/next pagination on first, middle and last pages,
on desktop and phone"
src="https://github.com/user-attachments/assets/c1bef79b-9579-490e-b009-d98d784b9b1c">

The pull request list now uses the same arrow between branches as the
compare page.

| Before | After |
|---|---|
| <img width="250" alt="Double chevron between branches"
src="https://github.com/user-attachments/assets/889ad911-950a-46cf-b06e-c18e06f48a29">
| <img width="250" alt="Arrow between branches"
src="https://github.com/user-attachments/assets/694ff6f9-659e-4d46-9826-b04f7cf7889a">
|

Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
Gary Wangandsilverwind authored and GitHub committed 2026-11-27 04:40:28 +00:00
1 parent 19c7e76ac3
commit d692b8d1db
19 files changed
+118 -332

No files matched your search

+15 -116
View File
@@ -6,32 +6,6 @@ package paginator
import "gitea.dev/modules/util"
/*
In template:
```html
{{if not .Page.IsFirst}}[First](1){{end}}
{{if .Page.HasPrevious}}[Previous]({{.Page.Previous}}){{end}}
{{range .Page.Pages}}
{{if eq .Num -1}}
...
{{else}}
{{.Num}}{{if .IsCurrent}}(current){{end}}
{{end}}
{{end}}
{{if .Page.HasNext}}[Next]({{.Page.Next}}){{end}}
{{if not .Page.IsLast}}[Last]({{.Page.TotalPages}}){{end}}
```
Output:
```
[First](1) [Previous](2) ... 2 3(current) 4 ... [Next](4) [Last](5)
```
*/
// Paginator represents a set of results of pagination calculations.
type Paginator struct {
total int // total rows count, -1 means unknown
@@ -39,13 +13,12 @@ type Paginator struct {
current int // current page number
pagingNum int // how many rows in one page
numPages int // how many pages to show on the UI
hasNext *bool // used for total=-1 ("unlimited paging")
}
// New initialize a new pagination calculation and returns a Paginator as result.
func New(total, pagingNum, current, numPages int) *Paginator {
func New(total, pagingNum, current int) *Paginator {
pagingNum = max(pagingNum, 1)
totalPages := util.Iif(total == -1, -1, (total+pagingNum-1)/pagingNum)
if total >= 0 {
@@ -57,7 +30,6 @@ func New(total, pagingNum, current, numPages int) *Paginator {
totalPages: totalPages,
current: current,
pagingNum: pagingNum,
numPages: numPages,
}
}
@@ -129,92 +101,19 @@ func (p *Paginator) PagingNum() int {
return p.pagingNum
}
// Page presents a page in the paginator.
type Page struct {
num int
isCurrent bool
}
func (p *Page) Num() int {
return p.num
}
func (p *Page) IsCurrent() bool {
return p.isCurrent
}
func getMiddleIdx(numPages int) int {
return (numPages + 1) / 2
}
// Pages returns a list of nearby page numbers relative to current page.
// If value is -1 means "..." that more pages are not showing.
func (p *Paginator) Pages() []*Page {
if p.numPages == 0 {
return nil
} else if p.total == -1 || (p.numPages == 1 && p.TotalPages() == 1) {
// Only show current page.
return []*Page{{p.current, true}}
// Pages returns the page numbers to show with -1 for a gap, mirrored by getPaginationPages in web_src/js/utils.ts
func (p *Paginator) Pages() []int {
total, current := p.TotalPages(), p.current
switch {
case total == -1:
return []int{current}
case total <= 7:
return []int{1, 2, 3, 4, 5, 6, 7}[:max(total, 0)]
case current <= 4:
return []int{1, 2, 3, 4, 5, -1, total}
case current >= total-3:
return []int{1, -1, total - 4, total - 3, total - 2, total - 1, total}
default:
return []int{1, -1, current - 1, current, current + 1, -1, total}
}
// Total page number is less or equal.
if p.TotalPages() <= p.numPages {
pages := make([]*Page, p.TotalPages())
for i := range pages {
pages[i] = &Page{i + 1, i+1 == p.current}
}
return pages
}
numPages := p.numPages
offsetIdx := 0
hasMoreNext := false
// Check more previous and next pages.
previousNum := getMiddleIdx(p.numPages) - 1
if previousNum > p.current-1 {
previousNum -= previousNum - (p.current - 1)
}
nextNum := p.numPages - previousNum - 1
if p.current+nextNum > p.TotalPages() {
delta := nextNum - (p.TotalPages() - p.current)
nextNum -= delta
previousNum += delta
}
offsetVal := p.current - previousNum
if offsetVal > 1 {
numPages++
offsetIdx = 1
}
if p.current+nextNum < p.TotalPages() {
numPages++
hasMoreNext = true
}
pages := make([]*Page, numPages)
// There are more previous pages.
if offsetIdx == 1 {
pages[0] = &Page{-1, false}
}
// There are more next pages.
if hasMoreNext {
pages[len(pages)-1] = &Page{-1, false}
}
// Check previous pages.
for i := 0; i < previousNum; i++ {
pages[offsetIdx+i] = &Page{i + offsetVal, false}
}
pages[offsetIdx+previousNum] = &Page{p.current, true}
// Check next pages.
for i := 1; i <= nextNum; i++ {
pages[offsetIdx+previousNum+i] = &Page{p.current + i, false}
}
return pages
}
+15 -91
View File
@@ -12,7 +12,7 @@ import (
func TestPaginator(t *testing.T) {
t.Run("Basic logics", func(t *testing.T) {
p := New(0, -1, -1, 0)
p := New(0, -1, -1)
assert.Equal(t, 1, p.PagingNum())
assert.True(t, p.IsFirst())
assert.False(t, p.HasPrevious())
@@ -22,21 +22,21 @@ func TestPaginator(t *testing.T) {
assert.True(t, p.IsLast())
assert.Equal(t, 0, p.Total())
p = New(1, 10, 2, 0)
p = New(1, 10, 2)
assert.Equal(t, 10, p.PagingNum())
assert.True(t, p.IsFirst())
assert.False(t, p.HasPrevious())
assert.False(t, p.HasNext())
assert.True(t, p.IsLast())
p = New(10, 10, 1, 0)
p = New(10, 10, 1)
assert.Equal(t, 10, p.PagingNum())
assert.True(t, p.IsFirst())
assert.False(t, p.HasPrevious())
assert.False(t, p.HasNext())
assert.True(t, p.IsLast())
p = New(11, 10, 1, 0)
p = New(11, 10, 1)
assert.Equal(t, 10, p.PagingNum())
assert.True(t, p.IsFirst())
assert.False(t, p.HasPrevious())
@@ -44,7 +44,7 @@ func TestPaginator(t *testing.T) {
assert.Equal(t, 2, p.Next())
assert.False(t, p.IsLast())
p = New(11, 10, 2, 0)
p = New(11, 10, 2)
assert.Equal(t, 10, p.PagingNum())
assert.False(t, p.IsFirst())
assert.True(t, p.HasPrevious())
@@ -52,14 +52,14 @@ func TestPaginator(t *testing.T) {
assert.False(t, p.HasNext())
assert.True(t, p.IsLast())
p = New(20, 10, 2, 0)
p = New(20, 10, 2)
assert.Equal(t, 10, p.PagingNum())
assert.False(t, p.IsFirst())
assert.True(t, p.HasPrevious())
assert.False(t, p.HasNext())
assert.True(t, p.IsLast())
p = New(25, 10, 2, 0)
p = New(25, 10, 2)
assert.Equal(t, 10, p.PagingNum())
assert.False(t, p.IsFirst())
assert.True(t, p.HasPrevious())
@@ -67,89 +67,13 @@ func TestPaginator(t *testing.T) {
assert.False(t, p.IsLast())
})
t.Run("Generate pages", func(t *testing.T) {
p := New(0, 10, 1, 0)
pages := p.Pages()
assert.Empty(t, pages)
})
t.Run("Only current page", func(t *testing.T) {
p := New(0, 10, 1, 1)
pages := p.Pages()
assert.Empty(t, pages) // no "total", so no pages
p = New(1, 10, 1, 1)
pages = p.Pages()
assert.Len(t, pages, 1)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
})
assertPages := func(t *testing.T, total, current, numPages int, expected ...int) {
pages := New(total, 10, current, numPages).Pages()
assert.Len(t, pages, len(expected))
for i, number := range expected {
assert.Equal(t, number, pages[i].Num())
if number == current {
assert.True(t, pages[i].IsCurrent())
} else {
assert.False(t, pages[i].IsCurrent())
}
}
}
t.Run("Total page number is less or equal", func(t *testing.T) {
assertPages(t, 1, 1, 2, 1)
assertPages(t, 11, 1, 2, 1, 2)
assertPages(t, 11, 2, 2, 1, 2)
assertPages(t, 25, 2, 3, 1, 2, 3)
})
t.Run("Has more previous pages ", func(t *testing.T) {
// ... 2
assertPages(t, 11, 2, 1, -1, 2)
// ... 2 3
assertPages(t, 21, 2, 2, -1, 2, 3)
// ... 2 3 4
assertPages(t, 31, 3, 3, -1, 2, 3, 4)
// ... 3 4 5
assertPages(t, 41, 4, 3, -1, 3, 4, 5)
// ... 4 5 6 7 8 9 10
assertPages(t, 100, 9, 7, -1, 4, 5, 6, 7, 8, 9, 10)
})
t.Run("Has more next pages", func(t *testing.T) {
// 1 ...
assertPages(t, 21, 1, 1, 1, -1)
// 1 2 ...
assertPages(t, 21, 1, 2, 1, 2, -1)
// 1 2 3 ...
assertPages(t, 31, 2, 3, 1, 2, 3, -1)
// 1 2 3 ...
assertPages(t, 41, 2, 3, 1, 2, 3, -1)
// 1 2 3 4 5 6 7 ...
assertPages(t, 100, 1, 7, 1, 2, 3, 4, 5, 6, 7, -1)
// 1 2 3 4 5 6 7 ...
assertPages(t, 100, 2, 7, 1, 2, 3, 4, 5, 6, 7, -1)
})
t.Run("Has both more previous and next pages", func(t *testing.T) {
// ... 2 3 ...
assertPages(t, 35, 2, 2, -1, 2, 3, -1)
// ... 2 3 4 ...
assertPages(t, 49, 3, 3, -1, 2, 3, 4, -1)
t.Run("Pages", func(t *testing.T) {
assert.Empty(t, New(0, 10, 1).Pages())
assert.Equal(t, []int{3}, New(-1, 10, 3).Pages())
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7}, New(70, 10, 4).Pages())
assert.Equal(t, []int{1, 2, 3, 4, 5, -1, 8}, New(80, 10, 4).Pages())
assert.Equal(t, []int{1, -1, 4, 5, 6, 7, 8}, New(80, 10, 5).Pages())
assert.Equal(t, []int{1, -1, 35, 36, 37, -1, 40}, New(400, 10, 36).Pages())
assert.Equal(t, []int{1, -1, 36, 37, 38, 39, 40}, New(400, 10, 37).Pages())
})
}
+1 -2
View File
@@ -199,6 +199,7 @@
"aria.footer": "Footer",
"aria.footer.software": "About Software",
"aria.footer.links": "Links",
"aria.pagination": "Pagination",
"heatmap.number_of_contributions_in_the_last_12_months": "%s contributions in the last 12 months",
"heatmap.no_contributions": "No contributions",
"heatmap.less": "Less",
@@ -3077,8 +3078,6 @@
"admin.config_settings": "Settings",
"admin.notices": "System Notices",
"admin.monitor": "Monitoring",
"admin.first_page": "First",
"admin.last_page": "Last",
"admin.total": "Total: %d",
"admin.settings": "Admin Settings",
"admin.dashboard.new_version_hint": "Gitea %s is now available, you are running %s. Check <a target=\"_blank\" rel=\"noreferrer\" href=\"%s\">the blog</a> for more details.",
-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="svg gitea-double-chevron-left" width="16" height="16" aria-hidden="true"><g fill-rule="evenodd"><path d="M7.91 12.77a.75.75 0 0 1-1.06 0L2.61 8.52a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 1.06L4.2 8l3.72 3.72a.75.75 0 0 1 0 1.06z"/><path d="M13.39 12.77a.75.75 0 0 1-1.06 0L8.08 8.52a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 1.06L9.67 8l3.72 3.72a.75.75 0 0 1 0 1.06z"/></g></svg>

Before

Width:  |  Height:  |  Size: 461 B

-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="svg gitea-double-chevron-right" width="16" height="16" aria-hidden="true"><g fill-rule="evenodd"><path d="M8.09 3.23a.75.75 0 0 1 1.06 0l4.24 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.8 8 8.08 4.28a.75.75 0 0 1 0-1.06z"/><path d="M2.61 3.23a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L6.33 8 2.61 4.28a.75.75 0 0 1 0-1.06z"/></g></svg>

Before

Width:  |  Height:  |  Size: 462 B

+2 -2
View File
@@ -107,12 +107,12 @@ func TestMilestones(t *testing.T) {
func TestDashboardPagination(t *testing.T) {
ctx, _ := contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.PageRenderer()})
page := context.NewPagerBuilder(ctx).TotalCount(10).PerPageLimit(3).CurPage(1).NavPageNum(3).Build()
page := context.NewPagerBuilder(ctx).TotalCount(10).PerPageLimit(3).CurPage(1).Build()
for _, subURL := range []string{"/SubPath", ""} {
setting.AppSubURL = subURL
out, err := ctx.RenderToHTML("base/paginate", map[string]any{"Link": setting.AppSubURL, "Page": page})
assert.NoError(t, err)
assert.Contains(t, out, `<a class=" item navigation" href="`+subURL+`/?page=2">`)
assert.Contains(t, out, `href="`+subURL+`/?page=2" aria-label="repo.issues.next"`)
}
}
+1 -1
View File
@@ -131,7 +131,7 @@ func GetAPIContext(req *http.Request) *APIContext {
}
func genAPILinks(curURL *url.URL, total int64, pageSize, curPage int) []string {
p := paginator.New(int(total), pageSize, curPage, 0)
p := paginator.New(int(total), pageSize, curPage)
links := make([]string, 0, 4)
if p.HasNext() {
+3 -11
View File
@@ -13,7 +13,6 @@ import (
"strings"
"gitea.dev/modules/container"
"gitea.dev/modules/optional"
"gitea.dev/modules/paginator"
)
@@ -22,7 +21,6 @@ type PagerBuilder struct {
total int64
curPage int
perPageLimit int
navPageNum *int
}
func NewPagerBuilder(ctx *Context) *PagerBuilder {
@@ -44,14 +42,8 @@ func (pb *PagerBuilder) CurPage(n int) *PagerBuilder {
return pb
}
func (pb *PagerBuilder) NavPageNum(n int) *PagerBuilder {
pb.navPageNum = &n
return pb
}
func (pb *PagerBuilder) Build() *Pagination {
navPageNum := optional.FromPtr(pb.navPageNum).ValueOrDefault(5)
p := newPagination(pb.total, pb.perPageLimit, pb.curPage, navPageNum)
p := newPagination(pb.total, pb.perPageLimit, pb.curPage)
p.AddParamFromRequest(pb.ctx.Req)
return p
}
@@ -66,10 +58,10 @@ type Pagination struct {
// "total" is usually from database result "count int64", so it also uses int64
// "pagingNum" is "page size" or "limit", "current" is "page"
// total=-1 means only showing prev/next
func newPagination(total int64, pagingNum, current, numPages int) *Pagination {
func newPagination(total int64, pagingNum, current int) *Pagination {
totalInt := int(min(total, int64(math.MaxInt)))
p := &Pagination{}
p.Paginator = paginator.New(totalInt, pagingNum, current, numPages)
p.Paginator = paginator.New(totalInt, pagingNum, current)
return p
}
+5 -5
View File
@@ -13,7 +13,7 @@ import (
)
func TestPagination(t *testing.T) {
p := newPagination(1, 1, 1, 1)
p := newPagination(1, 1, 1)
params := url.Values{}
params.Add("k1", "11")
params.Add("k1", "12")
@@ -33,22 +33,22 @@ func TestPagination(t *testing.T) {
v, _ = url.ParseQuery(string(p.GetParams()))
assert.Equal(t, params, v)
p = newPagination(-1, 1, 1, 1)
p = newPagination(-1, 1, 1)
p.WithUnlimitedPaging(0, false)
assert.Zero(t, p.Paginator.TotalPages())
assert.False(t, p.Paginator.HasNext())
p = newPagination(-1, 1, 1, 1)
p = newPagination(-1, 1, 1)
p.WithUnlimitedPaging(10, false)
assert.Equal(t, 1, p.Paginator.TotalPages()) // first page, no next, so it should know that the total page number is 1
assert.False(t, p.Paginator.HasNext())
p = newPagination(-1, 1, 2, 1)
p = newPagination(-1, 1, 2)
p.WithUnlimitedPaging(10, false)
assert.Equal(t, -1, p.Paginator.TotalPages())
assert.False(t, p.Paginator.HasNext())
p = newPagination(-1, 1, 1, 1)
p = newPagination(-1, 1, 1)
p.WithUnlimitedPaging(10, true)
assert.Equal(t, -1, p.Paginator.TotalPages())
assert.True(t, p.Paginator.HasNext())
+24 -40
View File
@@ -2,45 +2,29 @@
{{$paginationLink := $.Link}}
{{if eq $paginationLink nil}}{{$paginationLink = ctx.RootData.Link}}{{end}}
{{if eq $paginationLink AppSubUrl}}{{$paginationLink = print $paginationLink "/"}}{{end}}
{{$paginationParams := $page.GetParams}}
{{with $page.Paginator}}
{{if or (eq .TotalPages -1) (gt .TotalPages 1)}}
{{$showFirstLast := gt .TotalPages 1}}
<div class="center page buttons">
<div class="ui borderless pagination menu">
{{if $showFirstLast}}
<a class="{{if .IsFirst}}disabled{{end}} item navigation" {{if not .IsFirst}}href="{{$paginationLink}}{{if $paginationParams}}?{{$paginationParams}}{{end}}"{{end}}>
{{svg "gitea-double-chevron-left" 16 "tw-mr-1"}}
<span class="navigation_label">{{ctx.Locale.Tr "admin.first_page"}}</span>
</a>
{{$pageLink := print $paginationLink "?" $page.GetParams}}
{{$paginator := $page.Paginator}}
{{if and $paginator (or (eq $paginator.TotalPages -1) (gt $paginator.TotalPages 1))}}
{{$unknownTotal := eq $paginator.TotalPages -1}}
{{$textPrevious := ctx.Locale.Tr "repo.issues.previous"}}
{{$textNext := ctx.Locale.Tr "repo.issues.next"}}
<div class="center page buttons">
<nav class="ui borderless pagination menu {{if $unknownTotal}}pagination-prev-next{{end}}" aria-label="{{ctx.Locale.Tr "aria.pagination"}}">
<a class="{{if not $paginator.HasPrevious}}disabled {{end}}item flex-text-inline" {{if $paginator.HasPrevious}}href="{{QueryBuild $pageLink "page" $paginator.Previous}}"{{else}}role="link" aria-disabled="true"{{end}} {{if not $unknownTotal}}aria-label="{{$textPrevious}}" data-tooltip-content="{{$textPrevious}}"{{end}}>
{{svg "octicon-chevron-left"}}{{if $unknownTotal}}{{$textPrevious}}{{end}}
</a>
{{range $num := $paginator.Pages}}
{{if eq $num -1}}
<span class="disabled item">…</span>
{{else if eq $num $paginator.Current}}
<span class="{{if not $unknownTotal}}active {{end}}item" aria-current="page">{{$num}}</span>
{{else}}
<a class="item" href="{{QueryBuild $pageLink "page" $num}}">{{$num}}</a>
{{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 "tw-mr-1"}}
<span class="navigation_label">{{ctx.Locale.Tr "repo.issues.previous"}}</span>
</a>
{{$pages := .Pages}}
{{$pagesLen := len $pages}}
{{range $pages}}
{{if eq .Num -1}}
<a class="disabled item">...</a>
{{else}}
{{/* do not highlight the current page if there is only one page */}}
<a class="{{if and .IsCurrent (gt $pagesLen 1)}}active {{end}}item" {{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="{{$paginationLink}}?page={{.Next}}{{if $paginationParams}}&{{$paginationParams}}{{end}}"{{end}}>
<span class="navigation_label">{{ctx.Locale.Tr "repo.issues.next"}}</span>
{{svg "octicon-chevron-right" 16 "tw-ml-1"}}
</a>
{{if $showFirstLast}}
<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 "tw-ml-1"}}
</a>
{{end}}
</div>
</div>
{{end}}
{{end}}
<a class="{{if not $paginator.HasNext}}disabled {{end}}item flex-text-inline" {{if $paginator.HasNext}}href="{{QueryBuild $pageLink "page" $paginator.Next}}"{{else}}role="link" aria-disabled="true"{{end}} {{if not $unknownTotal}}aria-label="{{$textNext}}" data-tooltip-content="{{$textNext}}"{{end}}>
{{if $unknownTotal}}{{$textNext}}{{end}}{{svg "octicon-chevron-right"}}
</a>
</nav>
</div>
{{end}}
+1 -1
View File
@@ -69,7 +69,7 @@
{{if ne $issue.RepoID $issue.PullRequest.BaseRepoID}}<span class="truncated-name">{{$issue.PullRequest.BaseRepo.OwnerName}}</span>:{{end}}<span class="truncated-name">{{$issue.PullRequest.BaseBranch}}</span>
</a>
</div>
{{svg "gitea-double-chevron-left" 12}}
{{svg "octicon-arrow-left" 12}}
{{if $issue.PullRequest.HeadRepo}}
<div class="branch">
<a href="{{$issue.PullRequest.HeadRepo.Link}}/src/branch/{{PathEscapeSegments $issue.PullRequest.HeadBranch}}">
-2
View File
@@ -29,10 +29,8 @@ const data = {
textMirrors: {{ctx.Locale.Tr "mirrors"}},
textCollaborative: {{ctx.Locale.Tr "collaborative"}},
textFirstPage: {{ctx.Locale.Tr "admin.first_page"}},
textPreviousPage: {{ctx.Locale.Tr "repo.issues.previous"}},
textNextPage: {{ctx.Locale.Tr "repo.issues.next"}},
textLastPage: {{ctx.Locale.Tr "admin.last_page"}},
textMyOrgs: {{ctx.Locale.Tr "home.my_orgs"}},
textNewOrg: {{ctx.Locale.Tr "new_org"}},
+18 -21
View File
@@ -286,6 +286,8 @@
margin: 0;
display: inline-flex;
vertical-align: middle;
max-width: calc(100% - 1rem);
min-height: 0;
}
.ui.pagination.menu .item:last-child {
border-radius: 0 0.28571429rem 0.28571429rem 0;
@@ -293,34 +295,29 @@
.ui.compact.menu .item:last-child {
border-radius: 0 0.28571429rem 0.28571429rem 0;
}
.ui.pagination.menu .item:last-child::before {
display: none;
}
.ui.pagination.menu .item {
min-width: 3em;
text-align: center;
flex-shrink: 1;
justify-content: center;
width: 36px;
min-width: min-content;
height: 36px;
padding: 0 2px;
}
.ui.pagination.menu .active.item,
.ui.pagination.menu a.item:hover,
.ui.pagination.menu button.item:hover {
background: var(--color-hover);
}
.ui.pagination.menu a.item:active,
.ui.pagination.menu button.item:active,
.ui.pagination.menu .active.item:hover {
border-top: none;
padding-top: 0.92857143em;
color: var(--color-text);
background: var(--color-active);
}
@media (max-width: 767.98px) {
.ui.pagination.menu .item:not(.active,.navigation),
.ui.pagination.menu .item.navigation span.navigation_label {
display: none;
}
}
.ui.pagination.menu.narrow .item {
padding-left: 8px;
padding-right: 8px;
min-width: 1em;
text-align: center;
.ui.pagination.menu.pagination-prev-next .item {
width: auto;
padding: 0 12px;
}
.ui.secondary.menu {
+15 -31
View File
@@ -3,6 +3,7 @@ import {computed, nextTick, onMounted, shallowRef, useTemplateRef, type ShallowR
import SvgIcon from './SvgIcon.vue';
import {GET} from '../modules/fetch.ts';
import {urlQueryEscape} from '../utils/url.ts';
import {getPaginationPages} from '../utils.ts';
import type {SvgName} from '../svg.ts';
const {appSubUrl, pageData} = window.config;
@@ -95,10 +96,8 @@ const pageDataDefaults = {
textForks: '',
textMirrors: '',
textCollaborative: '',
textFirstPage: '',
textPreviousPage: '',
textNextPage: '',
textLastPage: '',
textMyOrgs: '',
textNewOrg: '',
textOrgVisibilityLimited: '',
@@ -113,7 +112,7 @@ const {
textShowBothArchivedUnarchived, textShowOnlyUnarchived, textShowOnlyArchived,
textShowBothPrivatePublic, textShowOnlyPublic, textShowOnlyPrivate,
textAll, textSources, textForks, textMirrors, textCollaborative,
textFirstPage, textPreviousPage, textNextPage, textLastPage,
textPreviousPage, textNextPage,
textMyOrgs, textNewOrg, textOrgVisibilityLimited, textOrgVisibilityPrivate,
}: typeof pageDataDefaults = {...pageDataDefaults, ...pageData.dashboardRepoList};
@@ -260,8 +259,8 @@ async function changePage(newPage: number) {
if (newPage > finalPage.value) newPage = finalPage.value;
if (newPage < 1) newPage = 1;
if (newPage === page.value) return;
page.value = newPage;
repos.value = [];
await searchRepos();
}
@@ -480,33 +479,18 @@ async function reposFilterKeyControl(e: KeyboardEvent) {
</ul>
<div v-if="showMoreReposLink" class="tw-text-center">
<div class="divider tw-my-0"/>
<div class="ui borderless pagination menu narrow tw-my-2">
<a
class="item navigation tw-py-1" :class="{'disabled': page === 1}"
@click="changePage(1)" :title="textFirstPage"
>
<svg-icon name="gitea-double-chevron-left" :size="16" class="tw-mr-1"/>
</a>
<a
class="item navigation tw-py-1" :class="{'disabled': page === 1}"
@click="changePage(page - 1)" :title="textPreviousPage"
>
<svg-icon name="octicon-chevron-left" :size="16" class="tw-mr-1"/>
</a>
<a class="active item tw-py-1">{{ page }}</a>
<a
class="item navigation" :class="{'disabled': page === finalPage}"
@click="changePage(page + 1)" :title="textNextPage"
>
<svg-icon name="octicon-chevron-right" :size="16" class="tw-ml-1"/>
</a>
<a
class="item navigation tw-py-1" :class="{'disabled': page === finalPage}"
@click="changePage(finalPage)" :title="textLastPage"
>
<svg-icon name="gitea-double-chevron-right" :size="16" class="tw-ml-1"/>
</a>
</div>
<nav class="ui borderless pagination menu tw-my-2" :aria-label="textMyRepos">
<button type="button" class="item flex-text-inline" :disabled="page === 1" @click="changePage(page - 1)" :data-tooltip-content="textPreviousPage">
<svg-icon name="octicon-chevron-left"/>
</button>
<template v-for="(item, index) in getPaginationPages(page, finalPage)" :key="index">
<span v-if="item === -1" class="disabled item">…</span>
<button v-else type="button" class="item" :class="{active: item === page}" :aria-current="item === page ? 'page' : undefined" @click="changePage(item)">{{ item }}</button>
</template>
<button type="button" class="item flex-text-inline" :disabled="page === finalPage" @click="changePage(page + 1)" :data-tooltip-content="textNextPage">
<svg-icon name="octicon-chevron-right"/>
</button>
</nav>
</div>
</div>
</div>
-4
View File
@@ -1,7 +1,5 @@
import {parseDom, serializeXml} from './utils.ts';
import {htmlRaw} from './utils/html.ts';
import giteaDoubleChevronLeft from '../../public/assets/img/svg/gitea-double-chevron-left.svg';
import giteaDoubleChevronRight from '../../public/assets/img/svg/gitea-double-chevron-right.svg';
import giteaEmptyCheckbox from '../../public/assets/img/svg/gitea-empty-checkbox.svg';
import giteaExclamation from '../../public/assets/img/svg/gitea-exclamation.svg';
import giteaFavicon from '../../public/assets/img/favicon.svg';
@@ -93,8 +91,6 @@ import octiconZoomIn from '../../public/assets/img/svg/octicon-zoom-in.svg';
import octiconZoomOut from '../../public/assets/img/svg/octicon-zoom-out.svg';
const svgs = {
'gitea-double-chevron-left': giteaDoubleChevronLeft,
'gitea-double-chevron-right': giteaDoubleChevronRight,
'gitea-empty-checkbox': giteaEmptyCheckbox,
'gitea-exclamation': giteaExclamation,
'gitea-favicon': giteaFavicon,
+10 -1
View File
@@ -1,5 +1,5 @@
import {
dirname, basename, extname, formatBytes, isObject, stripTags, parseIssueHref,
dirname, basename, extname, formatBytes, getPaginationPages, isObject, stripTags, parseIssueHref,
translateMonth, translateDay, blobToDataURI,
encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseRepoOwnerPathInfo,
} from './utils.ts';
@@ -118,6 +118,15 @@ test('formatBytes', () => {
expect(formatBytes(1024 * 1024 * 1024)).toBe('1.0 GiB');
});
test('getPaginationPages', () => {
expect(getPaginationPages(1, 0)).toEqual([]);
expect(getPaginationPages(4, 7)).toEqual([1, 2, 3, 4, 5, 6, 7]);
expect(getPaginationPages(4, 8)).toEqual([1, 2, 3, 4, 5, -1, 8]);
expect(getPaginationPages(5, 8)).toEqual([1, -1, 4, 5, 6, 7, 8]);
expect(getPaginationPages(36, 40)).toEqual([1, -1, 35, 36, 37, -1, 40]);
expect(getPaginationPages(37, 40)).toEqual([1, -1, 36, 37, 38, 39, 40]);
});
test('file detection', () => {
const type = null;
for (const name of ['a.avif', 'a.jpg', '/a.jpeg', '.file.png', '.webp', 'file.svg']) {
+8
View File
@@ -198,6 +198,14 @@ export function formatBytes(num: number, precision = 2): string {
return `${value.toFixed(digits)} ${byteUnits[exp]}`;
}
// mirrors Paginator.Pages in modules/paginator/paginator.go
export function getPaginationPages(current: number, total: number): Array<number> {
if (total <= 7) return [1, 2, 3, 4, 5, 6, 7].slice(0, total);
if (current <= 4) return [1, 2, 3, 4, 5, -1, total];
if (current >= total - 3) return [1, -1, total - 4, total - 3, total - 2, total - 1, total];
return [1, -1, current - 1, current, current + 1, -1, total];
}
export function toggleFullScreen(fullScreenEl: HTMLElement, isFullScreen: boolean, sourceParentSelector?: string): void {
// hide other elements
const headerEl = document.querySelector('#navbar')!;
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><g fill-rule="evenodd"><path d="M7.91 12.77a.75.75 0 01-1.06 0L2.61 8.52a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.2 8l3.72 3.72a.75.75 0 010 1.06z"/><path d="M13.39 12.77a.75.75 0 01-1.06 0L8.08 8.52a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L9.67 8l3.72 3.72a.75.75 0 010 1.06z"/></g></svg>

Before

Width:  |  Height:  |  Size: 390 B

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><g fill-rule="evenodd"><path d="M8.09 3.23a.75.75 0 011.06 0l4.24 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06L11.8 8 8.08 4.28a.75.75 0 010-1.06z"/><path d="M2.61 3.23a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06L6.33 8 2.61 4.28a.75.75 0 010-1.06z"/></g></svg>

Before

Width:  |  Height:  |  Size: 390 B