https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Bug ID: 19196 Summary: Add pagination helpers Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org In order to aid UI devs work on top of the REST api, we need to provide pagination information along with the responses. It was discussed on the mailing list that following RFC5988 [1] proposal for Link headers was desirable. And also adding a header telling the total objects count would be desirable, in the lines of this link [2]. [1] https://tools.ietf.org/html/rfc5988#section-6 [2] http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#paginat... -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | Change sponsored?|--- |Sponsored Depends on| |18137 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18137 [Bug 18137] REST API: Migrate from Mojolicious::Plugin::Swagger2 to Mojolicious::Plugin::OpenAPI -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Lari Taskula <lari.taskula@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lari.taskula@jns.fi -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #1 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66599 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66599&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #2 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66600 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66600&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds two helper methods: total_count_header ================== When used, it adds an _X-Total-Count_ header with the value it got passed like this: my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->total_count_header({ total_count => $count }); => Response contains X-Total-Count: $count links_header ============ When used, it adds a _Link_ header to the reponse with the calculated values for pagination, like this: my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->links_header({ total => $count, page => 2, per_page => 2 }); To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #3 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66601 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66601&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@bugs.koha-c | |ommunity.org, | |kyle@bywatersolutions.com Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66599|0 |1 is obsolete| | --- Comment #4 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66609 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66609&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66600|0 |1 is obsolete| | --- Comment #5 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66610 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66610&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds two helper methods: total_count_header ================== When used, it adds an _X-Total-Count_ header with the value it got passed like this: my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->total_count_header({ total => $count }); => Response contains X-Total-Count: $count links_header ============ When used, it adds a _Link_ header to the reponse with the calculated values for pagination, like this: my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->links_header({ total => $count, page => 2, per_page => 2 }); To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66601|0 |1 is obsolete| | --- Comment #6 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66611 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66611&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |18731 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18731 [Bug 18731] REST api: Add an endpoint for acquisition orders -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66609|0 |1 is obsolete| | --- Comment #7 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66656 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66656&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66610|0 |1 is obsolete| | --- Comment #8 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66657 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66657&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds a helper method: add_pagination_headers ====================== When used, it adds a _Link_ header to the reponse with the calculated values for pagination, and X-Total-Count containing the total results like this: my $params = $c->validation->output; my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->add_pagination_headers({ total => $count, page => $params->{page}, per_page => $params->{per_page} }); To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County lib -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66611|0 |1 is obsolete| | --- Comment #9 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66658 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66658&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66656|0 |1 is obsolete| | --- Comment #10 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66820 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66820&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66657|0 |1 is obsolete| | --- Comment #11 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66821 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66821&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds a helper method: add_pagination_headers ====================== When used, it adds a _Link_ header to the reponse with the calculated values for pagination, and X-Total-Count containing the total results like this: my $params = $c->validation->output; my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->add_pagination_headers({ total => $count, params => $params )}; To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66658|0 |1 is obsolete| | --- Comment #12 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 66822 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66822&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #13 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Patches reworked so the resulting pagination links preserve the query params :-D -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19250 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19250 [Bug 19250] Add pagination to /acquisitions/vendors -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |benjamin.rokseth@kul.oslo.k | |ommune.no --- Comment #14 from Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no> --- Great work Tomas. please fix typo in your example ;)
$c->add_pagination_headers({ total => $count, params => $params )};
and add some sensible defaults (10/10?) to page and per_page so Pagination.pm doesnt die if none is given as params. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19234 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19234 [Bug 19234] Add query parameters handling helpers -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66820|0 |1 is obsolete| | Attachment #66821|0 |1 is obsolete| | Attachment #66822|0 |1 is obsolete| | --- Comment #15 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 66988 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66988&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #16 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 66989 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66989&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds a helper method: add_pagination_headers ====================== When used, it adds a _Link_ header to the reponse with the calculated values for pagination, and X-Total-Count containing the total results like this: my $params = $c->validation->output; my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->add_pagination_headers({ total => $count, params => $params )}; To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #17 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 66990 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66990&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit | |y.org | Component|Architecture, internals, |REST api |and plumbing | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19278 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19278 [Bug 19278] Add a configurable default page size for endpoints -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |martin.renvoize@ptfs-europe | |.com --- Comment #18 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- I really like this.. only minor query would be can we document the decision as to why we've chosen to do page based instead of cursor based result 'paging'. I'm personally happy to go with either.. but to prevent FUD in future developers I think it's worth documenting the decision process so we can point to that when someone asks down the line ;) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66988|0 |1 is obsolete| | --- Comment #19 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 67338 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67338&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66989|0 |1 is obsolete| | --- Comment #20 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 67339 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67339&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds a helper method: add_pagination_headers ====================== When used, it adds a _Link_ header to the reponse with the calculated values for pagination, and X-Total-Count containing the total results like this: my $params = $c->validation->output; my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->add_pagination_headers({ total => $count, params => $params )}; To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County Edit: I fixed a mistake on the POD (tcohen) Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #66990|0 |1 is obsolete| | --- Comment #21 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 67340 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67340&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #22 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Martin Renvoize from comment #18)
I really like this.. only minor query would be can we document the decision as to why we've chosen to do page based instead of cursor based result 'paging'. I'm personally happy to go with either.. but to prevent FUD in future developers I think it's worth documenting the decision process so we can point to that when someone asks down the line ;)
I think we could implement both pagination methods on a as-needed basis and there should be no conflict. A new set of helper can be added based on this work, with proper tests c&p-ed from the ones on this bug. Regarding the specifics of why I chose to start with page-based results paging, I'd say: - It looked pretty *natural* when you look at SQL::Abstract syntax for it. - It is what Github uses (https://developer.github.com/v3/#pagination) and I really like its simplicity. - Cursor based pagination is really harder to implement, and the use cases I'm tackling wouldn't benefit much from it (i.e. it'ss just vendor orders, not stuffs that change very often and pagination would become really difficult, in which case other artifacts would get involved like websockets/server side events to notify changes). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #23 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 67346 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67346&action=edit Bug 19196: Rename page and per_page This patch just renames 'page' and 'per_page' params, for '_page' and '_per_page' respectively. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Lari Taskula <lari.taskula@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #67338|0 |1 is obsolete| | --- Comment #24 from Lari Taskula <lari.taskula@jns.fi> --- Created attachment 67366 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67366&action=edit Bug 19196: Unit tests This patch adds unit tests for the new pagination Mojo plugin. Sponsored-by: ByWater Solutions Sponsored-by: Camden County Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Lari Taskula <lari.taskula@jns.fi> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Lari Taskula <lari.taskula@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #67339|0 |1 is obsolete| | --- Comment #25 from Lari Taskula <lari.taskula@jns.fi> --- Created attachment 67367 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67367&action=edit Bug 19196: Add Koha::REST::Plugin::Pagination This patch introduces a Mojolicious plugin to be used on the REST api. It adds a helper method: add_pagination_headers ====================== When used, it adds a _Link_ header to the reponse with the calculated values for pagination, and X-Total-Count containing the total results like this: my $params = $c->validation->output; my $patrons = Koha::Patrons->search; my $count = $patrons->count; $c->add_pagination_headers({ total => $count, params => $params )}; To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => SUCCESS: Tests pass! - Sign off :-D Sponsored-by: ByWater solutions Sponsored-by: Camden County Edit: I fixed a mistake on the POD (tcohen) Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Lari Taskula <lari.taskula@jns.fi> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Lari Taskula <lari.taskula@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #67340|0 |1 is obsolete| | --- Comment #26 from Lari Taskula <lari.taskula@jns.fi> --- Created attachment 67368 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67368&action=edit Bug 19196: Make plugin available to endpoints This patch just initializes the plugin on the main controller class so it is available for all endpoints to use. As it is not used, in order to test just restart plack and make sure the endpoints work (run the t/db_dependent/api/v1 tests). Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Lari Taskula <lari.taskula@jns.fi> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Lari Taskula <lari.taskula@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #67346|0 |1 is obsolete| | --- Comment #27 from Lari Taskula <lari.taskula@jns.fi> --- Created attachment 67369 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=67369&action=edit Bug 19196: Rename page and per_page This patch just renames 'page' and 'per_page' params, for '_page' and '_per_page' respectively. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Lari Taskula <lari.taskula@jns.fi> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19410 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19410 [Bug 19410] Koha::Objects needs a ->search_for_api method -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|19278 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19278 [Bug 19278] Add a configurable default page size for endpoints -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |m.de.rooy@rijksmuseum.nl Status|Passed QA |Failed QA --- Comment #28 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- =head3 register =cut sub register { my ( $self, $app ) = @_; =head2 Helper methods This sub contains POD. Please adjust. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #29 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Marcel de Rooy from comment #28)
=head3 register
=cut
sub register { my ( $self, $app ) = @_;
=head2 Helper methods
This sub contains POD. Please adjust.
What do you suggest? I thought doing it 'inline' was better. Keep in mind that the 'register' sub is the only sub, and it contains the 'helpers' definitiions. The 'helpers' are the only important thing here. If you prefer, I can move them POD into a separate section like here: http://cpansearch.perl.org/src/JBERGER/Mojo-IOLoop-ForkCall-0.16/lib/Mojolic... but I still prefer this way. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Passed QA --- Comment #30 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Tomás Cohen Arazi from comment #29)
What do you suggest? I thought doing it 'inline' was better. Keep in mind that the 'register' sub is the only sub, and it contains the 'helpers' definitiions. The 'helpers' are the only important thing here. If you prefer, I can move them POD into a separate section like here:
http://cpansearch.perl.org/src/JBERGER/Mojo-IOLoop-ForkCall-0.16/lib/ Mojolicious/Plugin/ForkCall.pm
but I still prefer this way.
OK. You have a reason. Personally I would not prefer it, but it should not be a blocker. Passing it back to RM for final decision. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to Master --- Comment #31 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- Pushed to master for 17.11, thanks to everybody involved! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #32 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #33 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
Mojolicious version? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #34 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Tomás Cohen Arazi from comment #33)
(In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
Mojolicious version?
7.21 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #35 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Since commenting this line solves the problem: # $self->plugin( 'Koha::REST::Plugin::Pagination' ); I still hope to see something moving here ;) Anything with setting path for Mojo plugins or so? Mojo experts around? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #36 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Marcel de Rooy from comment #35)
Since commenting this line solves the problem: # $self->plugin( 'Koha::REST::Plugin::Pagination' ); I still hope to see something moving here ;) Anything with setting path for Mojo plugins or so? Mojo experts around?
For the record, I cannot reproduce. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Stefan Berndtsson <stefan.berndtsson@ub.gu.se> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |stefan.berndtsson@ub.gu.se --- Comment #37 from Stefan Berndtsson <stefan.berndtsson@ub.gu.se> --- (In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
Same issue here. Also 7.21 of Mojolicious. Commenting the line in Koha/REST/V1.pm works as a temporary fix here as well. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #38 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Stefan Berndtsson from comment #37)
(In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
Same issue here. Also 7.21 of Mojolicious. Commenting the line in Koha/REST/V1.pm works as a temporary fix here as well.
Thanks for your confirmation of this issue. We might convince Tomas ;) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #39 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Marcel de Rooy from comment #38)
(In reply to Stefan Berndtsson from comment #37)
(In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
Same issue here. Also 7.21 of Mojolicious. Commenting the line in Koha/REST/V1.pm works as a temporary fix here as well.
Thanks for your confirmation of this issue. We might convince Tomas ;)
I belive you! I just can't reproduce it -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #40 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
What happened? No idea, but (suddenly) I cannot reproduce this error any more. Glad to see that, but it is still intriguing. Hard to say what resolved the problem after a few weeks of merging master and commenting the plugin line in V1. If it comes up again, I will certainly tell you.. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Bug 19196 depends on bug 18137, which changed state. Bug 18137 Summary: REST API: Migrate from Mojolicious::Plugin::Swagger2 to Mojolicious::Plugin::OpenAPI https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18137 What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to Master |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19546 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19546 [Bug 19546] Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm breaks opac and staff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|19250 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19250 [Bug 19250] Add pagination to /acquisitions/vendors -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|19546 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19546 [Bug 19546] Make koha-plack run Starman from the instance's directory -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 --- Comment #41 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Marcel de Rooy from comment #40)
(In reply to Marcel de Rooy from comment #32)
Error while loading /etc/koha/plack.psgi: Can't load application from file "api/v1/app.pl": Can't locate Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: ./Mojolicious/Plugin/Koha/REST/Plugin/Pagination.pm: Permission denied at (eval 1295) line 1.
What happened? No idea, but (suddenly) I cannot reproduce this error any more. Glad to see that, but it is still intriguing. Hard to say what resolved the problem after a few weeks of merging master and commenting the plugin line in V1. If it comes up again, I will certainly tell you..
This was dealth with on bug 19546 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19196 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to Master |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org