diff --git a/CHANGES.md b/CHANGES.md index a0d0fae8..682b8447 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2` +## [0.5.6] - 2023-12-19 + +- Fix collections `prev` links and collections html templates + ## [0.5.5] - 2023-12-19 - Fix `prev` offset value diff --git a/tipg/dependencies.py b/tipg/dependencies.py index c8d7b676..63a25623 100644 --- a/tipg/dependencies.py +++ b/tipg/dependencies.py @@ -503,5 +503,5 @@ def CollectionsParams( collections=collections_list, matched=matched, next=offset + returned if matched - returned > offset else None, - prev=max(offset - returned, 0) if offset else None, + prev=max(offset - limit, 0) if offset else None, ) diff --git a/tipg/factory.py b/tipg/factory.py index 5442ea41..9f8789db 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -449,9 +449,8 @@ def collections( qp = dict(request.query_params) qp.pop("offset", None) query_params = QueryParams({**qp, "offset": prev_token}) - url = self.url_for(request, "collections") - if qp: + if query_params: url += f"?{query_params}" links.append( @@ -830,7 +829,7 @@ async def items( # noqa: C901 qp.pop("offset") query_params = QueryParams({**qp, "offset": prev_token}) url = self.url_for(request, "items", collectionId=collection.id) - if qp: + if query_params: url += f"?{query_params}" links.append( diff --git a/tipg/templates/collections.html b/tipg/templates/collections.html index 745f4aa1..e71c5b7a 100644 --- a/tipg/templates/collections.html +++ b/tipg/templates/collections.html @@ -83,7 +83,7 @@

Collections

// paging // var offset = 0; // defaults - var limit = 0; + var limit = 10; {% if "offset" in template.params %} offset = {{ template.params.offset }}; @@ -94,7 +94,7 @@

Collections

var current_page = 1; if (limit > 0) { - current_page = (offset + limit)/limit; + current_page = Math.ceil((offset + limit) / limit); } $("#current_page").html(current_page);