Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix collection prev and other links #152

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading