Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update page

aichy126cae46c94cfab
diff --git a/internal/controller/template_render/controller.go b/internal/controller/template_render/controller.go
index f9ea8186..ecb0b542 100644
--- a/internal/controller/template_render/controller.go
+++ b/internal/controller/template_render/controller.go
@@ -35,18 +35,18 @@ func NewTemplateRenderController(
// Paginator page
// page : now page
-// prepage : Number per page
+// pageSize : Number per page
// nums : Total
// Returns the contents of the page in the format of 1, 2, 3, 4, and 5. If the contents are less than 5 pages, the page number is returned
-func Paginator(page, prepage int, nums int64) *schema.Paginator {
- if prepage == 0 {
- prepage = 10
+func Paginator(page, pageSize int, nums int64) *schema.Paginator {
+ if pageSize == 0 {
+ pageSize = 10
}
- var firstpage int //Previous page address
- var lastpage int //Address on the last page
+ var prevpage int //Previous page address
+ var nextpage int //Address on the last page
//Generate the total number of pages based on the total number of nums and the number of prepage pages
- totalpages := int(math.Ceil(float64(nums) / float64(prepage))) //Total number of Pages
+ totalpages := int(math.Ceil(float64(nums) / float64(pageSize))) //Total number of Pages
if page > totalpages {
page = totalpages
}
@@ -57,8 +57,8 @@ func Paginator(page, prepage int, nums int64) *schema.Paginator {
switch {
case page >= totalpages-5 && totalpages > 5: //The last 5 pages
start := totalpages - 5 + 1
- firstpage = page - 1
- lastpage = int(math.Min(float64(totalpages), float64(page+1)))
+ prevpage = page - 1
+ nextpage = int(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int, 5)
for i, _ := range pages {
pages[i] = start + i
@@ -66,25 +66,25 @@ func Paginator(page, prepage int, nums int64) *schema.Paginator {
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int, 5)
- firstpage = page - 3
+ prevpage = page - 3
for i, _ := range pages {
pages[i] = start + i
}
- firstpage = page - 1
- lastpage = page + 1
+ prevpage = page - 1
+ nextpage = page + 1
default:
pages = make([]int, int(math.Min(5, float64(totalpages))))
for i, _ := range pages {
pages[i] = i + 1
}
- firstpage = int(math.Max(float64(1), float64(page-1)))
- lastpage = page + 1
+ prevpage = int(math.Max(float64(1), float64(page-1)))
+ nextpage = page + 1
}
paginator := &schema.Paginator{}
paginator.Pages = pages
paginator.Totalpages = totalpages
- paginator.Firstpage = firstpage
- paginator.Lastpage = lastpage
+ paginator.Prevpage = prevpage
+ paginator.Nextpage = nextpage
paginator.Currpage = page
return paginator
}
diff --git a/internal/schema/template_schema.go b/internal/schema/template_schema.go
index 19bb3826..6446565e 100644
--- a/internal/schema/template_schema.go
+++ b/internal/schema/template_schema.go
@@ -3,7 +3,7 @@ package schema
type Paginator struct {
Pages []int
Totalpages int
- Firstpage int
- Lastpage int
+ Prevpage int
+ Nextpage int
Currpage int
}
diff --git a/ui/template/page.html b/ui/template/page.html
index a520f873..a93106eb 100644
--- a/ui/template/page.html
+++ b/ui/template/page.html
@@ -1,17 +1,13 @@
{{define "page"}}
<ul class="d-inline-flex mb-0 pagination pagination-sm">
- {{$currpage := .page.Currpage}}
- {{$totalpages := .page.Totalpages}}
- {{$firstpage := .page.Firstpage}}
- {{$lastpage := .page.Lastpage}}
- {{ if ne $currpage 1 }}
+ {{ if ne $.page.Currpage 1 }}
<li class="page-item">
- <a class="page-link" href="?page={{$firstpage}}"><span aria-hidden="true">Prev</span><span
+ <a class="page-link" href="?page={{$.page.Prevpage}}"><span aria-hidden="true">Prev</span><span
class="visually-hidden">Prev</span></a>
</li>
{{ end }}
{{ range $value := .page.Pages }}
- {{ if eq $currpage $value }}
+ {{ if eq $.page.Currpage $value }}
<li class="page-item active">
<span class="page-link" href="?page={{$value}}">{{$value}}
<span class="visually-hidden">(current)</span>
@@ -23,9 +19,9 @@
</li>
{{ end }}
{{ end }}
- {{ if lt $currpage $totalpages }}
+ {{ if lt $.page.Currpage $.page.Totalpages }}
<li class="page-item">
- <a class="page-link" href="?page={{$lastpage}}"><span aria-hidden="true">Next</span><span
+ <a class="page-link" href="?page={{$.page.Nextpage}}"><span aria-hidden="true">Next</span><span
class="visually-hidden">Next</span></a>
</li>
{{ end }}