diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index 33013008c4..ff2700759c 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -11,7 +11,7 @@ class SamplesController < Groups::ApplicationController def index @timestamp = DateTime.current - @pagy, @samples = @query.results(action: 'query', limit: params[:limit], page: params[:page]) + @pagy, @samples = @query.results(limit: params[:limit] || 20, page: params[:page] || 1) @has_samples = authorized_samples.count.positive? end @@ -26,8 +26,7 @@ def select respond_to do |format| format.turbo_stream do if params[:select].present? - @sample_ids = @query.results(action: 'select') - .where(updated_at: ..params[:timestamp].to_datetime).select(:id).pluck(:id) + @sample_ids = @query.results.where(updated_at: ..params[:timestamp].to_datetime).select(:id).pluck(:id) end end end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index d24a6a4200..366250f491 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -13,7 +13,7 @@ class SamplesController < Projects::ApplicationController # rubocop:disable Metr def index @timestamp = DateTime.current - @pagy, @samples = @query.results(action: 'query', limit: params[:limit], page: params[:page]) + @pagy, @samples = @query.results(limit: params[:limit] || 20, page: params[:page] || 1) @has_samples = @project.samples.size.positive? end @@ -83,8 +83,7 @@ def select respond_to do |format| format.turbo_stream do if params[:select].present? - @sample_ids = @query.results(action: 'select') - .where(updated_at: ..params[:timestamp].to_datetime).select(:id).pluck(:id) + @sample_ids = @query.results.where(updated_at: ..params[:timestamp].to_datetime).select(:id).pluck(:id) end end end diff --git a/app/models/sample/query.rb b/app/models/sample/query.rb index 9a3c432439..16f5e3afea 100644 --- a/app/models/sample/query.rb +++ b/app/models/sample/query.rb @@ -37,14 +37,11 @@ def advanced_query? false end - def results(params) - case params[:action] - when 'query' - pagy_results(params[:limit] || 20, params[:page] || 1) - when 'select' - advanced_query ? searchkick_results : ransack_results + def results(**results_arguments) + if results_arguments[:limit] || results_arguments[:page] + pagy_results(results_arguments[:limit], results_arguments[:page]) else - raise ResultTypeError, "Unrecognized type: #{params[:action]}" + advanced_query ? searchkick_results : ransack_results end end