Skip to content

Commit

Permalink
Merge pull request #152 from developmentseed/patch/fix-collections-links
Browse files Browse the repository at this point in the history
fix collection prev and other links
  • Loading branch information
vincentsarago authored Dec 19, 2023
2 parents 5a0ce8d + 2d09b9e commit 1af49b8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tipg/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
5 changes: 2 additions & 3 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tipg/templates/collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Collections</h1>
// paging
//
var offset = 0; // defaults
var limit = 0;
var limit = 10;

{% if "offset" in template.params %}
offset = {{ template.params.offset }};
Expand All @@ -94,7 +94,7 @@ <h1>Collections</h1>

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

Expand Down

0 comments on commit 1af49b8

Please sign in to comment.