Monorepo for Tangled
at 74318eac9fdd72cf69e916276814351931ed0dcb 95 lines 2.6 kB view raw
1{{ define "fragments/pagination" }} 2 {{/* Params: Page (pagination.Page), TotalCount (int), BasePath (string), QueryParams (url.Values) */}} 3 {{ $page := .Page }} 4 {{ $totalCount := .TotalCount }} 5 {{ $basePath := .BasePath }} 6 {{ $queryParams := safeUrl .QueryParams.Encode }} 7 8 {{ $prev := $page.Previous.Offset }} 9 {{ $next := $page.Next.Offset }} 10 {{ $lastPage := sub $totalCount (mod $totalCount $page.Limit) }} 11 12 <div class="flex justify-center items-center mt-4 gap-2"> 13 <a 14 class=" 15 btn flex items-center gap-2 no-underline hover:no-underline 16 dark:text-white dark:hover:bg-gray-700 17 {{ if le $page.Offset 0 }} 18 cursor-not-allowed opacity-50 19 {{ end }} 20 " 21 {{ if gt $page.Offset 0 }} 22 hx-boost="true" 23 href="{{ $basePath }}?{{ $queryParams }}&offset={{ $prev }}&limit={{ $page.Limit }}" 24 {{ end }} 25 > 26 {{ i "chevron-left" "w-4 h-4" }} 27 previous 28 </a> 29 30 {{ if gt $page.Offset 0 }} 31 <a 32 hx-boost="true" 33 href="{{ $basePath }}?{{ $queryParams }}&offset=0&limit={{ $page.Limit }}" 34 > 35 1 36 </a> 37 {{ end }} 38 39 {{ if gt $prev $page.Limit }} 40 <span>...</span> 41 {{ end }} 42 43 {{ if gt $prev 0 }} 44 <a 45 hx-boost="true" 46 href="{{ $basePath }}?{{ $queryParams }}&offset={{ $prev }}&limit={{ $page.Limit }}" 47 > 48 {{ add (div $prev $page.Limit) 1 }} 49 </a> 50 {{ end }} 51 52 <span class="font-bold"> 53 {{ add (div $page.Offset $page.Limit) 1 }} 54 </span> 55 56 {{ if lt $next $lastPage }} 57 <a 58 hx-boost="true" 59 href="{{ $basePath }}?{{ $queryParams }}&offset={{ $next }}&limit={{ $page.Limit }}" 60 > 61 {{ add (div $next $page.Limit) 1 }} 62 </a> 63 {{ end }} 64 65 {{ if lt $next (sub $totalCount (mul 2 $page.Limit)) }} 66 <span>...</span> 67 {{ end }} 68 69 {{ if lt $page.Offset $lastPage }} 70 <a 71 hx-boost="true" 72 href="{{ $basePath }}?{{ $queryParams }}&offset={{ $lastPage }}&limit={{ $page.Limit }}" 73 > 74 {{ add (div $lastPage $page.Limit) 1 }} 75 </a> 76 {{ end }} 77 78 <a 79 class=" 80 btn flex items-center gap-2 no-underline hover:no-underline 81 dark:text-white dark:hover:bg-gray-700 82 {{ if lt $next $totalCount | not }} 83 cursor-not-allowed opacity-50 84 {{ end }} 85 " 86 {{ if lt $next $totalCount }} 87 hx-boost="true" 88 href="{{ $basePath }}?{{ $queryParams }}&offset={{ $next }}&limit={{ $page.Limit }}" 89 {{ end }} 90 > 91 next 92 {{ i "chevron-right" "w-4 h-4" }} 93 </a> 94 </div> 95{{ end }}