Skip to content

Commit

Permalink
utilize kwargs for query.results
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Dec 19, 2024
1 parent 3aebb7a commit 935db17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 2 additions & 3 deletions app/controllers/groups/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/projects/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions app/models/sample/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 935db17

Please sign in to comment.