Bugzilla – Attachment 114893 Details for
Bug 27353
Return the number of total records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27353: Set X-Base-Total-Count header for REST API
Bug-27353-Set-X-Base-Total-Count-header-for-REST-A.patch (text/plain), 4.79 KB, created by
Jonathan Druart
on 2021-01-06 15:37:38 UTC
(
hide
)
Description:
Bug 27353: Set X-Base-Total-Count header for REST API
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-01-06 15:37:38 UTC
Size:
4.79 KB
patch
obsolete
>From 55013bb699002972144fda996ef626164040c07e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 6 Jan 2021 16:34:23 +0100 >Subject: [PATCH] Bug 27353: Set X-Base-Total-Count header for REST API > >We already set X-Total-Count to the total number of filtered rows, >but we don't have the total number of non-filtered rows. > >Test plan: >This is easy to test on top of bug 27352 or bug 27251, apply them if not >pushed yet. >1. Create 40 items with public notes = "xxx" for biblionumber=4 >then, using Postman (or whatever you prefer): >http://kohadev-intra.mydnsname.org:8081/api/v1/biblios/4/items?_page=1&_per_page=20&q=[{"me.public_notes"%3A{"like"%3A"%25x%25"}}]&_match=contains >Check the headers and confirm you see X-Total-Count=40 and >X-Base-Total-Count=44 > >2. go to /cgi-bin/koha/tools/quotes.pl >You see "Showing 1 to 20 of 28 entries" >Search "he" >Showing 1 to 20 of 22 entries (filtered from 28 total entries) >--- > Koha/REST/Plugin/Objects.pm | 23 ++++++++++++------- > Koha/REST/Plugin/Pagination.pm | 4 +++- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 3 +++ > 3 files changed, 21 insertions(+), 9 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index fec1fe794a..35742dc1ff 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -114,18 +114,25 @@ sub register { > } > # Perform search > my $objects = $result_set->search( $filtered_params, $attributes ); >+ my $total = $result_set->search->count; > > if ($objects->is_paged) { >- $c->add_pagination_headers({ >- total => $objects->pager->total_entries, >- params => $args, >- }); >+ $c->add_pagination_headers( >+ { >+ total => $objects->pager->total_entries, >+ base_total => $total, >+ params => $args, >+ } >+ ); > } > else { >- $c->add_pagination_headers({ >- total => $objects->count, >- params => $args, >- }); >+ $c->add_pagination_headers( >+ { >+ total => $objects->count, >+ base_total => $total, >+ params => $args, >+ } >+ ); > } > > return $objects->to_api({ embed => $embed }); >diff --git a/Koha/REST/Plugin/Pagination.pm b/Koha/REST/Plugin/Pagination.pm >index 911aa43aaf..90d220c1cf 100644 >--- a/Koha/REST/Plugin/Pagination.pm >+++ b/Koha/REST/Plugin/Pagination.pm >@@ -50,7 +50,7 @@ sub register { > > Adds a Link header to the response message $c carries, following RFC5988, including > the following relation types: 'prev', 'next', 'first' and 'last'. >-It also adds X-Total-Count, containing the total results count. >+It also adds X-Total-Count containing the total results count, and X-Base-Total-Count containing the total of the non-filtered results count. > > If page size is omitted, it defaults to the value of the RESTdefaultPageSize syspref. > >@@ -61,6 +61,7 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys > my ( $c, $args ) = @_; > > my $total = $args->{total}; >+ my $base_total = $args->{base_total}; > my $req_page = $args->{params}->{_page} // 1; > my $per_page = $args->{params}->{_per_page} // > C4::Context->preference('RESTdefaultPageSize') // 20; >@@ -114,6 +115,7 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys > > # Add X-Total-Count header > $c->res->headers->add( 'X-Total-Count' => $total ); >+ $c->res->headers->add( 'X-Base-Total-Count' => $base_total ); > return $c; > } > ); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index 13db0e495c..69fc5a998f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -544,6 +544,9 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > json.recordsTotal = total; > json.recordsFiltered = total; > } >+ if(total = this._xhr.getResponseHeader('x-base-total-count')) { >+ json.recordsTotal = total; >+ } > return JSON.stringify(json); > }, > 'data': function( data, settings ) { >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27353
:
114893
|
114896
|
114897
|
115039
|
115058
|
115059
|
115769
|
115771
|
115784
|
115785
|
115786
|
115807
|
115808
|
115809