Skip to content

Commit

Permalink
Only use the Pagy gem for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Jul 1, 2024
1 parent be54421 commit d5bb6e2
Show file tree
Hide file tree
Showing 45 changed files with 153 additions and 378 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ gem 'openapi3_parser', '0.9.2'
gem 'rouge'
gem 'ruby-graphviz'

gem 'kaminari'

gem 'pagy'

# Adviser sign up integration
Expand Down
13 changes: 0 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,6 @@ GEM
rack (>= 0.2)
jwt (2.8.2)
base64
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
launchy (3.0.1)
addressable (~> 2.8)
Expand Down Expand Up @@ -908,7 +896,6 @@ DEPENDENCIES
json-schema
json_api_client
jwt
kaminari
launchy
listen (>= 3.0.5, < 3.10)
mail-notify
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% if application_forms.any? %>
<% application_forms.each do |application_form| %>
<% forms = application_forms.is_a?(Hash) ? application_forms[:records] : application_forms %>
<% if forms.any? %>
<% forms.each do |application_form| %>
<%= render SupportInterface::ApplicationCardComponent.new(application_form: application_form, heading_level: @row_heading_level) %>
<% end %>
<% else %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<% @pagy, @audits = audits %>

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Time</th>
<th scope="col" class="govuk-table__header govuk-!-width-three-quarter">Event</th>
</tr>
</thead>

<tbody class="govuk-table__body">
<% audits.each do |audit| %>
<% @audits.each do |audit| %>
<%= render SupportInterface::AuditTrailItemComponent.new(audit: audit) %>
<% end %>
</tbody>
</table>

<%= render(PaginatorComponent.new(scope: audits)) %>
<%= govuk_pagination(pagy: @pagy) %>
5 changes: 4 additions & 1 deletion app/components/support_interface/audit_trail_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module SupportInterface
class AuditTrailComponent < ViewComponent::Base
include Pagy::Backend
include ViewHelper

def initialize(audited_thing:)
Expand All @@ -19,7 +20,9 @@ def audits
audits = audits.where(auditable_type: params[:auditable_type])
end

audits.includes(:user).order('created_at desc').page(params[:page] || 1).per(60)
audits = audits.includes(:user).order(created_at: :desc)

pagy(audits, page: params[:page], items: 60)
end

attr_reader :audited_thing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
</tbody>
</table>

<%= render(PaginatorComponent.new(scope: data_exports)) %>
<%= govuk_pagination(pagy: @pagy) %>
<% end %>
2 changes: 0 additions & 2 deletions app/components/utility/paginated_filter_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<%= render FilterComponent.new(filter: filter) do |component| %>
<%= content %>
<%= render(PaginatorComponent.new(scope: collection)) %>
<% end %>
</div>
11 changes: 0 additions & 11 deletions app/components/utility/paginator_component.html.erb

This file was deleted.

80 changes: 0 additions & 80 deletions app/components/utility/paginator_component.rb

This file was deleted.

14 changes: 9 additions & 5 deletions app/controllers/provider_interface/activity_log_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module ProviderInterface
class ActivityLogController < ProviderInterfaceController
include Pagy::Backend

def index
@events = GetActivityLogEvents.call(
application_choices: GetApplicationChoicesForProviders.call(
providers: current_provider_user.providers,
),
).page(params[:page] || 1).per(50)
application_choices = GetApplicationChoicesForProviders.call(
providers: current_provider_user.providers,
)
events = GetActivityLogEvents.call(
application_choices: application_choices,
)
@pagy, @events = pagy(events, items: 50)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ProviderInterface
class ApplicationChoicesController < ProviderInterfaceController
include Pagy::Backend
include ClearWizardCache

before_action :set_application_choice, :set_workflow_flags, except: %i[index]
Expand Down Expand Up @@ -32,7 +33,8 @@ def index
application_choices: with_includes.where(id: application_choices),
)

@application_choices = application_choices.page(params[:page] || 1).per(30).load
@pagy, @application_choices = pagy(application_choices, items: 30)
@application_choices.load
end

def show
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module ProviderInterface
class InterviewSchedulesController < ProviderInterfaceController
include Pagy::Backend

def show
@interviews = Interview.for_application_choices(application_choices_for_user_providers)
.undiscarded
.upcoming
.includes([:provider, application_choice: [:course_option, application_form: [:candidate]]])
.order(:date_and_time)
.page(params[:page] || 1).per(50)
interviews = Interview.for_application_choices(application_choices_for_user_providers)
.undiscarded
.upcoming
.includes([:provider, application_choice: [:course_option, application_form: [:candidate]]])
.order(:date_and_time)

@pagy, @interviews = pagy(interviews, items: 50)
@grouped_interviews = @interviews.group_by(&:date)
end

def past
@interviews = Interview.for_application_choices(application_choices_for_user_providers)
.undiscarded
.past
.includes([:provider, application_choice: [:course_option, application_form: [:candidate]]])
.order(date_and_time: :desc)
.page(params[:page] || 1).per(50)
interviews = Interview.for_application_choices(application_choices_for_user_providers)
.undiscarded
.past
.includes([:provider, application_choice: [:course_option, application_form: [:candidate]]])
.order(date_and_time: :desc)

@pagy, @interviews = pagy(interviews, items: 50)
@grouped_interviews = @interviews.group_by(&:date)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module SupportInterface
class ApplicationFormsController < SupportInterfaceController
def index
@filter = SupportInterface::ApplicationsFilter.new(params:)
@application_forms = @filter.filter_records(ApplicationForm)
result = @filter.filter_records(ApplicationForm)
@pagy = result[:pagy]
@application_forms = result[:records]
end

def show
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/support_interface/candidates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ class CandidatesController < SupportInterfaceController

def index
@candidates = Candidate
.includes(application_forms: :application_choices)
.order(updated_at: :desc)
.page(params[:page] || 1).per(30)
.includes(application_forms: :application_choices)
.order(updated_at: :desc)

@filter = SupportInterface::CandidatesFilter.new(params:)

Expand All @@ -18,6 +17,8 @@ def index
candidate_number = @filter.applied_filters[:candidate_number].tr('^0-9', '')
@candidates = @candidates.where(id: candidate_number)
end

@pagy, @candidates = pagy(@candidates, page: params[:page], items: 30)
end

def show
Expand Down
24 changes: 13 additions & 11 deletions app/controllers/support_interface/data_exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ def directory

def history
@data_exports = DataExport
.includes(:initiator)
.order(created_at: :desc)
.page(params[:page] || 1)
.per(PAGE_SIZE)
.select(DataExport.column_names - %w[data])
.includes(:initiator)
.order(created_at: :desc)
.select(DataExport.column_names - %w[data])

@pagy, @data_exports = pagy(@data_exports, items: PAGE_SIZE)
end


def view_export_information
@data_export = DataExport::EXPORT_TYPES[params[:data_export_type].to_sym]
end

def view_history
@data_exports = DataExport
.includes(:initiator)
.send(params[:data_export_type])
.order(created_at: :desc)
.page(params[:page] || 1)
.per(PAGE_SIZE)
.select(DataExport.column_names - %w[data])
.includes(:initiator)
.send(params[:data_export_type])
.order(created_at: :desc)

@pagy, @data_exports = pagy(@data_exports, items: PAGE_SIZE)

@data_exports = @data_exports.select(DataExport.column_names - %w[data])
end

def new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ class DuplicateMatchesController < SupportInterfaceController
DUPLICATE_MATCHES_PER_PAGE = 100

def index
@matches = duplicate_matches(resolved: resolved?).page(params[:page]).per(DUPLICATE_MATCHES_PER_PAGE)
@under_review_count = duplicate_matches(resolved: false).count

@filter = SupportInterface::DuplicateMatchesFilter.new(params:)

if @filter.applied_filters[:query].present?
@matches = @matches.joins(:candidates).where('CONCAT(email_address) ILIKE ?', "%#{@filter.applied_filters[:query]}%")
matches_scope = duplicate_matches(resolved: resolved?).joins(:candidates).where('CONCAT(email_address) ILIKE ?', "%#{@filter.applied_filters[:query]}%")
else
matches_scope = duplicate_matches(resolved: resolved?)
end

@pagy, @matches = pagy(matches_scope, items: DUPLICATE_MATCHES_PER_PAGE)
@under_review_count = duplicate_matches(resolved: false).count
end

def show
Expand Down
13 changes: 7 additions & 6 deletions app/controllers/support_interface/email_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ class EmailLogController < SupportInterfaceController
def index
@filter = SupportInterface::EmailsFilter.new(params:)

@emails = Email
emails = Email
.order(id: :desc)
.includes(:application_form)
.page(params[:page] || 1).per(30)

if @filter.applied_filters[:q].present?
@emails = @emails.where("CONCAT(\"to\", ' ', subject, ' ', notify_reference, ' ', body) ILIKE ?", "%#{@filter.applied_filters[:q]}%")
emails = emails.where("CONCAT(\"to\", ' ', subject, ' ', notify_reference, ' ', body) ILIKE ?", "%#{@filter.applied_filters[:q]}%")
end

if @filter.applied_filters[:delivery_status].present?
@emails = @emails.where(delivery_status: @filter.applied_filters[:delivery_status])
emails = emails.where(delivery_status: @filter.applied_filters[:delivery_status])
end

if @filter.applied_filters[:mailer].present?
@emails = @emails.where(mailer: @filter.applied_filters[:mailer])
emails = emails.where(mailer: @filter.applied_filters[:mailer])
end

%w[to subject mail_template notify_reference application_form_id].each do |column|
next if @filter.applied_filters[column].blank?

@emails = @emails.where(column => @filter.applied_filters[column])
emails = emails.where(column => @filter.applied_filters[column])
end

@pagy, @emails = pagy(emails, page: params[:page], items: 30)
end
end
end
Loading

0 comments on commit d5bb6e2

Please sign in to comment.