From 1c824a450c0e9300c516340fcab4da5b424a178a Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 1 Jun 2019 17:01:20 +0200 Subject: [PATCH] fix cursor-based navigation --- app/controllers/dois_controller.rb | 6 ++++-- app/controllers/works_controller.rb | 9 --------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 403d538ca..a4265daa4 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -161,13 +161,15 @@ def index subjects: subjects }.compact + logger.info page.inspect + options[:links] = { self: request.original_url, - next: results.size < page[:size] ? nil : request.base_url + "/dois?" + { + next: results.size < page[:size] || page[:size] == 0 ? nil : request.base_url + "/dois?" + { query: params[:query], "provider-id" => params[:provider_id], "client-id" => params[:client_id], - "page[cursor]" => page[:cursor].present? ? Array.wrap(results.to_a.last.to_h[:sort]).first : nil, + "page[cursor]" => page[:cursor].present? ? Array.wrap(results.to_a.last[:sort]).first : nil, "page[number]" => page[:cursor].blank? && page[:number].present? ? page[:number] + 1 : nil, "page[size]" => page[:size] }.compact.to_query }.compact diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 9dbdc003d..e131a1b35 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -71,15 +71,6 @@ def index page: page[:number] }.compact - options[:links] = { - self: request.original_url, - next: @dois.blank? ? nil : request.base_url + "/dois?" + { - query: params[:query], - "member-id" => params[:provider_id], - "data-center-id" => params[:client_id], - "page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.to_a.last.to_h[:sort]).first : nil, - "page[size]" => page[:size] }.compact.to_query - }.compact options[:include] = @include options[:is_collection] = true options[:links] = nil