Comments (7)
Hey there, @austenito! As you pointed, JSONAPI::Utils
still doesn't support neither custom paginators nor pagination strategy per resource; as well as there's a lack of support for cursor-based pagination strategy.
Now I'm implementing a better support for custom filters and I will probably do some refactoring on JSONAPI::Utils::Support::Pagination
, since the code there is same from the first POCs that I made for the gem.
It would be really great to see a PR implementing those features for pagination π
from jsonapi-utils.
@tiagopog I'll give it a shot!
Also, I believe cursor pagination was removed cerebris/jsonapi-resources#301
from jsonapi-utils.
Indeed it was removed in JR, but since there's a growing adoption of some databases with cursor-based pagination (e.g. Google Cloud Datastore) it would be nice to bring a paginator that supports it.
You could start by implementing the support for custom paginator and later we could think on a proper way to deal with cursos.
from jsonapi-utils.
π #27
from jsonapi-utils.
Just took a free time tonight to refactor the module JSONAPI::Utils::Support::Pagination
. Hope it helps you.
from jsonapi-utils.
@tiagopog nice refactor :)
One of the things I've been thinking about is how to handle the pagination via ranges since custom paginators handle ranges differently. For example:
def pagination_range
case JSONAPI.configuration.default_paginator
when :paged
number = page_params['number'].to_i.nonzero? || 1
size = page_params['size'].to_i.nonzero? || JSONAPI.configuration.default_page_size
(number - 1) * size..number * size - 1
when :offset
offset = page_params['offset'].to_i.nonzero? || 0
limit = page_params['limit'].to_i.nonzero? || JSONAPI.configuration.default_page_size
offset..offset + limit - 1
end
end
I was thinking about delegating to each paginator to return the appropriate range. Anyways, I hope to get a branch up soon for you π at :)
from jsonapi-utils.
Delegate this kinda job to paginators would be the ideal scenario, the thing is: JSONAPI::Resources
doesn't support rendering Array of Hashes βΒ the use case where range is used for pagination βΒ then we should open the default paginator classes or stuff to add this behavior. I'm avoiding to monkey patch things as much as I can, so that I prefered to write this method rather than changing a few objects at runtime.
Thanks for the coming PR, I'm sure it will be awesome! Cheers!
from jsonapi-utils.
Related Issues (20)
- Trying to override pagination...
- Decimals formatted as strings in json response
- Update jsonapi-resources 0.9.12 HOT 10
- Bump the rails version to 6.1 for tagged version 7.13.0 HOT 1
- Release a new version? HOT 1
- Support for operation processors? HOT 3
- Rendering scopes with `includes` is slow for no reason HOT 2
- Passing resource relationship in POST request HOT 1
- resource_params => NoMethodError: undefined method `keys' for nil:NilClass HOT 2
- Render multiple invalid AR objects
- Bring support to fast_jsonapi HOT 9
- Use the cache with jsonapi_render. HOT 1
- Getting Invalid resource for custom resource response on patch request
- Non-REST actions?
- JSONAPI::Utils::Exceptions::BadRequest undefined
- Relax jsonapi-resources dependency HOT 3
- Support for sorting and pagination from JR
- jsonapi/utils.rb:9:in `include': wrong number of arguments (given 0, expected 1+) (ArgumentError)
- Formatting of error's "detail" attribute
- Accept and Content-Type headers are not verified
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi-utils.