From a3bd61264e5675a8ca933caf5cc3e24a81119921 Mon Sep 17 00:00:00 2001 From: afterlifepro Date: Thu, 27 Nov 2025 18:05:02 +0000 Subject: [PATCH] appview/pages,appview/issues: improve pagnation ui on issues Signed-off-by: afterlifepro --- appview/issues/issues.go | 9 ++ appview/pages/funcmap.go | 9 ++ appview/pages/pages.go | 1 + .../pages/templates/repo/issues/issues.html | 121 ++++++++++++++---- 4 files changed, 114 insertions(+), 26 deletions(-) diff --git a/appview/issues/issues.go b/appview/issues/issues.go index fcd15150..89254819 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -804,6 +804,13 @@ func (rp *Issues) RepoIssues(w http.ResponseWriter, r *http.Request) { return } + totalIssues := 0 + if isOpen { + totalIssues = f.RepoStats.IssueCount.Open + } else { + totalIssues = f.RepoStats.IssueCount.Closed + } + keyword := params.Get("q") var issues []models.Issue @@ -820,6 +827,7 @@ func (rp *Issues) RepoIssues(w http.ResponseWriter, r *http.Request) { return } l.Debug("searched issues with indexer", "count", len(res.Hits)) + totalIssues = int(res.Total) issues, err = db.GetIssues( rp.db, @@ -869,6 +877,7 @@ func (rp *Issues) RepoIssues(w http.ResponseWriter, r *http.Request) { LoggedInUser: rp.oauth.GetUser(r), RepoInfo: f.RepoInfo(user), Issues: issues, + IssueCount: totalIssues, LabelDefs: defs, FilteringByOpen: isOpen, FilterQuery: keyword, diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index 132b690f..ee42b6c5 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -100,6 +100,15 @@ func (p *Pages) funcMap() template.FuncMap { "sub": func(a, b int) int { return a - b }, + "mul": func (a, b int) int { + return a * b + }, + "div": func (a, b int) int { + return a / b + }, + "mod": func(a, b int) int { + return a % b + }, "f64": func(a int) float64 { return float64(a) }, diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 79281e4b..3719d9b8 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -908,6 +908,7 @@ type RepoIssuesParams struct { RepoInfo repoinfo.RepoInfo Active string Issues []models.Issue + IssueCount int LabelDefs map[string]*models.LabelDefinition Page pagination.Page FilteringByOpen bool diff --git a/appview/pages/templates/repo/issues/issues.html b/appview/pages/templates/repo/issues/issues.html index 0d9db443..eed3528d 100644 --- a/appview/pages/templates/repo/issues/issues.html +++ b/appview/pages/templates/repo/issues/issues.html @@ -70,40 +70,109 @@
{{ template "repo/issues/fragments/issueListing" (dict "Issues" .Issues "RepoPrefix" .RepoInfo.FullName "LabelDefs" .LabelDefs) }}
- {{ block "pagination" . }} {{ end }} + {{if gt .IssueCount .Page.Limit }} + {{ block "pagination" . }} {{ end }} + {{ end }} {{ end }} {{ define "pagination" }} -
- {{ $currentState := "closed" }} - {{ if .FilteringByOpen }} - {{ $currentState = "open" }} - {{ end }} +
+ {{ $currentState := "closed" }} + {{ if .FilteringByOpen }} + {{ $currentState = "open" }} + {{ end }} + + {{ $prev := .Page.Previous.Offset }} + {{ $next := .Page.Next.Offset }} + {{ $lastPage := sub .IssueCount (mod .IssueCount .Page.Limit) }} + - {{ i "chevron-left" "w-4 h-4" }} - previous - - {{ else }} -
+ hx-boost="true" + href = "/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&q={{ .FilterQuery }}&offset={{ $prev }}&limit={{ .Page.Limit }}" {{ end }} + > + {{ i "chevron-left" "w-4 h-4" }} + previous + + + + {{ if gt .Page.Offset 0 }} + + 1 + + {{ end }} + + + {{ if gt $prev .Page.Limit }} + ... + {{ end }} + + + {{ if gt $prev 0 }} + + {{ add (div $prev .Page.Limit) 1 }} + + {{ end }} + + + + {{ add (div .Page.Offset .Page.Limit) 1 }} + + + + {{ if lt $next $lastPage }} + + {{ add (div $next .Page.Limit) 1 }} + + {{ end }} + + + {{ if lt ($next) (sub .IssueCount (mul (2) .Page.Limit)) }} + ... + {{ end }} + + {{ if lt .Page.Offset $lastPage }} + + {{ add (div $lastPage .Page.Limit) 1 }} + + {{ end }} + + - next - {{ i "chevron-right" "w-4 h-4" }} - + hx-boost="true" + href="/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&q={{ .FilterQuery }}&offset={{ $next }}&limit={{ .Page.Limit }}" {{ end }} + > + next + {{ i "chevron-right" "w-4 h-4" }} +
{{ end }} -- 2.52.0