Updated search results pagination
authorThierry Florac <tflorac@ulthar.net>
Wed, 15 Jul 2020 17:55:47 +0200
changeset 517 ab5a456901ec
parent 516 9eaa98fb60c4
child 518 934cadc1b497
Updated search results pagination
src/pyams_default_theme/features/search/portlet/templates/search-panels.pt
src/pyams_default_theme/features/search/portlet/templates/search-results.pt
--- a/src/pyams_default_theme/features/search/portlet/templates/search-panels.pt	Wed Jul 15 17:06:26 2020 +0200
+++ b/src/pyams_default_theme/features/search/portlet/templates/search-panels.pt	Wed Jul 15 17:55:47 2020 +0200
@@ -78,32 +78,42 @@
 					tal:define="(current, total) settings.get_pages(start, length, count)"
 					data-ams-current-page="${current}">
 					<tal:if condition="renderer_settings.allow_pagination and (total > 1)">
-						<tal:if condition="current > 1">
-							<li class="prev">
-								<a href="#" i18n:translate=""
-								   data-ams-click-handler="PyAMS_default.search.previousPage">Previous page</a>
-							</li>
-						</tal:if>
-						<li tal:repeat="page range(current)">
-							<a tal:condition="current != page+1"
-							   href="#"
-							   data-ams-click-handler="PyAMS_default.search.gotoPage">${page+1}</a>
-							<span tal:condition="current == page+1"
-								  class="current">${page+1}</span>
+						<li class="prev"
+							tal:condition="current > 1">
+							<a href="#" i18n:translate=""
+							   data-ams-click-handler="PyAMS_default.search.previousPage">Previous page</a>
+						</li>
+						<li>
+							<span class="current"
+								  tal:condition="current == 1">1</span>
+							<a href="#"
+							   tal:condition="current > 1"
+							   data-ams-click-handler="PyAMS_default.search.gotoPage">1</a>
+						</li>
+						<li tal:condition="current > 5">
+							<a class="disabled">…</a>
 						</li>
-						<tal:if condition="current < total">
-							<li tal:condition="current < total-1">
-								<a class="disabled">…</a>
-							</li>
+						<tal:loop repeat="page range(max(1, current-4), min(current+3, total))">
 							<li>
-								<a href="#"
-								   data-ams-click-handler="PyAMS_default.search.gotoPage">${total}</a>
+								<a tal:condition="current != page+1"
+								   href="#"
+								   data-ams-click-handler="PyAMS_default.search.gotoPage">${page+1}</a>
+								<span tal:condition="current == page+1"
+									  class="current">${page+1}</span>
 							</li>
-							<li class="next">
-								<a href="#" i18n:translate=""
-								   data-ams-click-handler="PyAMS_default.search.nextPage">Next page</a>
-							</li>
-						</tal:if>
+						</tal:loop>
+						<li tal:condition="current < total-4">
+							<a class="disabled">…</a>
+						</li>
+						<li tal:condition="current < total-3">
+							<a href="#"
+							   data-ams-click-handler="PyAMS_default.search.gotoPage">${total}</a>
+						</li>
+						<li class="next"
+							tal:condition="current < total">
+							<a href="#" i18n:translate=""
+							   data-ams-click-handler="PyAMS_default.search.nextPage">Next page</a>
+						</li>
 					</tal:if>
 				</ol>
 			</nav>
--- a/src/pyams_default_theme/features/search/portlet/templates/search-results.pt	Wed Jul 15 17:06:26 2020 +0200
+++ b/src/pyams_default_theme/features/search/portlet/templates/search-results.pt	Wed Jul 15 17:55:47 2020 +0200
@@ -71,32 +71,42 @@
 					tal:define="(current, total) settings.get_pages(start, length, count)"
 					data-ams-current-page="${current}">
 					<tal:if condition="renderer_settings.allow_pagination and (total > 1)">
-						<tal:if condition="current > 1">
-							<li class="prev">
-								<a href="#" i18n:translate=""
-								   data-ams-click-handler="PyAMS_default.search.previousPage">Previous page</a>
-							</li>
-						</tal:if>
-						<li tal:repeat="page range(current)">
-							<a tal:condition="current != page+1"
-							   href="#"
-							   data-ams-click-handler="PyAMS_default.search.gotoPage">${page+1}</a>
-							<span tal:condition="current == page+1"
-								  class="current">${page+1}</span>
+						<li class="prev"
+							tal:condition="current > 1">
+							<a href="#" i18n:translate=""
+							   data-ams-click-handler="PyAMS_default.search.previousPage">Previous page</a>
+						</li>
+						<li>
+							<span class="current"
+								  tal:condition="current == 1">1</span>
+							<a href="#"
+							   tal:condition="current > 1"
+							   data-ams-click-handler="PyAMS_default.search.gotoPage">1</a>
+						</li>
+						<li tal:condition="current > 5">
+							<a class="disabled">…</a>
 						</li>
-						<tal:if condition="current < total">
-							<li tal:condition="current < total-1">
-								<a class="disabled">…</a>
-							</li>
+						<tal:loop repeat="page range(max(1, current-4), min(current+3, total))">
 							<li>
-								<a href="#"
-								   data-ams-click-handler="PyAMS_default.search.gotoPage">${total}</a>
+								<a tal:condition="current != page+1"
+								   href="#"
+								   data-ams-click-handler="PyAMS_default.search.gotoPage">${page+1}</a>
+								<span tal:condition="current == page+1"
+									  class="current">${page+1}</span>
 							</li>
-							<li class="next">
-								<a href="#" i18n:translate=""
-								   data-ams-click-handler="PyAMS_default.search.nextPage">Next page</a>
-							</li>
-						</tal:if>
+						</tal:loop>
+						<li tal:condition="current < total-4">
+							<a class="disabled">…</a>
+						</li>
+						<li tal:condition="current < total-3">
+							<a href="#"
+							   data-ams-click-handler="PyAMS_default.search.gotoPage">${total}</a>
+						</li>
+						<li class="next"
+							tal:condition="current < total">
+							<a href="#" i18n:translate=""
+							   data-ams-click-handler="PyAMS_default.search.nextPage">Next page</a>
+						</li>
 					</tal:if>
 				</ol>
 			</nav>