diff --git a/app/components/blacklight/facet_field_pagination_component.html.erb b/app/components/blacklight/facet_field_pagination_component.html.erb index 3b738e22c..626ab9d38 100644 --- a/app/components/blacklight/facet_field_pagination_component.html.erb +++ b/app/components/blacklight/facet_field_pagination_component.html.erb @@ -32,7 +32,14 @@ <% if page == current_page %> <%= page %> <% else %> - <%= helpers.link_to_specific_page @facet_field.paginator, page.to_i, @total_unique_facets, params: @facet_field.search_state.to_h.merge(page: page, 'facet.page' => page), class: "page-link" %> + + <%= helpers.link_to_specific_page( + @facet_field.paginator, + { integer: page.to_i, string: "#{page}" }, + @total_unique_facets, + params: @facet_field.search_state.to_h.merge(page: page, 'facet.page' => page), + class: "page-link" + ) %> <% end %> diff --git a/app/overrides/lib/kanamari/helpers/helper_methods_override.rb b/app/overrides/lib/kanamari/helpers/helper_methods_override.rb index 97cba7208..f83ff360d 100644 --- a/app/overrides/lib/kanamari/helpers/helper_methods_override.rb +++ b/app/overrides/lib/kanamari/helpers/helper_methods_override.rb @@ -2,23 +2,20 @@ # [hyc-override] https://github.com/kaminari/kaminari/blob/v1.2.2/kaminari-core/lib/kaminari/helpers/helper_methods.rb Kaminari::Helpers::HelperMethods.module_eval do # Helper to generate a link to a specific page - def link_to_specific_page(scope, page, total_entries, **options) + def link_to_specific_page(scope, page_hash, total_entries, **options) begin - # Validate inputs - raise ArgumentError, "Page number must be a positive integer - got #{page}" unless page.is_a?(Integer) && page.positive? - - specific_page_path = path_to_specific_page(scope, page, total_entries, options) + specific_page_path = path_to_specific_page(scope, page_hash[:integer], total_entries, options) # Remove unnecessary keys :params and :param_name from the options hash before generating the link options.except! :params, :param_name # Setting aria instead of rel for accessibility - options[:aria] ||= { label: "Go to page #{page}" } + options[:aria] ||= { label: "Go to page #{page_hash[:string]}" } if specific_page_path - link_to("#{page}" || page, specific_page_path, options) + link_to(page_hash[:string] || page, specific_page_path, options) else - Rails.logger.warn "Specific page path could not be generated for page: #{page}" + Rails.logger.warn "Specific page path could not be generated for page: #{page_hash[:string]}" end rescue ArgumentError => e Rails.logger.error "Error in link_to_specific_page: #{e.message}" @@ -29,19 +26,19 @@ def link_to_specific_page(scope, page, total_entries, **options) end # Helper to generate the path for a specific page - def path_to_specific_page(scope, page, total_entries, options = {}) + def path_to_specific_page(scope, page_integer, total_entries, options = {}) begin # Calculate total pages manually limit = scope.instance_variable_get(:@limit) total_pages = (total_entries.to_f / limit).ceil - Rails.logger.info "path_to_specific_page: total_entries=#{total_entries}, limit=#{limit}, calculated total_pages=#{total_pages}, page=#{page}" + Rails.logger.info "path_to_specific_page: total_entries=#{total_entries}, limit=#{limit}, calculated total_pages=#{total_pages}, page=#{page_integer}" # Validate inputs - raise ArgumentError, 'Page number must be a positive integer' unless page.is_a?(Integer) && page.positive? - raise ArgumentError, "Page number exceeds total pages (#{total_pages})" if page > total_pages + raise ArgumentError, 'Page number must be a positive integer' unless page_integer.positive? + raise ArgumentError, "Page number exceeds total pages (#{total_pages})" if page_integer > total_pages # Generate URL using Kaminari's Page helper - Kaminari::Helpers::Page.new(self, **options.reverse_merge(page: page)).url + Kaminari::Helpers::Page.new(self, **options.reverse_merge(page: page_integer)).url rescue ArgumentError => e Rails.logger.info "Error in path_to_specific_page: #{e.message}" rescue StandardError => e