Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem "datagrid", "~> 1.x"
gem "dry-struct"
gem "faraday"
gem "kaminari" # TODO: Remove when removing datagrid
gem "pagy"
gem "pagy", "~> 43.0"
gem "pg"

# Reduces boot times through caching; required in config/boot.rb
Expand Down
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ GEM
validate_url
webfinger (~> 2.0)
orm_adapter (0.5.0)
pagy (9.3.3)
pagy (43.5.0)
json
uri
yaml
parallel (2.0.1)
parser (3.3.11.1)
ast (~> 2.4.1)
Expand Down Expand Up @@ -664,6 +667,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yaml (0.4.0)
yard (0.9.41)
zeitwerk (2.7.5)

Expand Down Expand Up @@ -718,7 +722,7 @@ DEPENDENCIES
omniauth (~> 2.1)
omniauth-rails_csrf_protection
omniauth_openid_connect (~> 0.8)
pagy
pagy (~> 43.0)
passenger (~> 6.0)
pg
puma
Expand Down Expand Up @@ -884,7 +888,7 @@ CHECKSUMS
omniauth_openid_connect (0.8.0) sha256=1f2f3890386e2a742221cee0d2e903b78d874e6fab9ea3bfa31c1462f4793d25
openid_connect (2.3.1) sha256=5d808380cff80d78e3d3d54cfaebe2d6461d835c674faa29e2314a402c1b2182
orm_adapter (0.5.0) sha256=aa5d0be5d540cbb46d3a93e88061f4ece6a25f6e97d6a47122beb84fe595e9b9
pagy (9.3.3) sha256=4831418eb4ec7cc5658ea57de559cc3a960286db36f98d4c1c65e19db0e2bb60
pagy (43.5.0) sha256=58885d5f659e8db5b92cf35eeba674113e4e7bda12649b603c2d6908402570a4
parallel (2.0.1) sha256=337782d3e39f4121e67563bf91dd8ece67f48923d90698614773a0ec9a5b2c7d
parser (3.3.11.1) sha256=d17ace7aabe3e72c3cc94043714be27cc6f852f104d81aa284c2281aecc65d54
passenger (6.1.2) sha256=235a5ab2ad6dd56000ff401cb2f8ec92d67d17390a99425806cce6618405ee55
Expand Down Expand Up @@ -985,6 +989,7 @@ CHECKSUMS
websocket-driver (0.8.0) sha256=ed0dba4b943c22f17f9a734817e808bc84cdce6a7e22045f5315aa57676d4962
websocket-extensions (0.1.5) sha256=1c6ba63092cda343eb53fc657110c71c754c56484aad42578495227d717a8241
xpath (3.2.0) sha256=6dfda79d91bb3b949b947ecc5919f042ef2f399b904013eb3ef6d20dd3a4082e
yaml (0.4.0) sha256=240e69d1e6ce3584d6085978719a0faa6218ae426e034d8f9b02fb54d3471942
yard (0.9.41) sha256=2fad2f362bceb63101f37aeb81d35cfc50b4ae1c11cf22f54b8d46626877a89f
zeitwerk (2.7.5) sha256=d8da92128c09ea6ec62c949011b00ed4a20242b255293dd66bf41545398f73dd

Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ body {
overflow-wrap: break-word;
}

nav.pagy-bootstrap.nav .pagination {
nav.pagy-bootstrap.series-nav .pagination {
margin-bottom: 0;
}

Expand Down
4 changes: 2 additions & 2 deletions app/components/export_dropdown_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def initialize(url:, pagy:, **params)

def current_page_export(format:)
params = @params.dup
params[@pagy.vars[:page_param].to_s] = @pagy.page
params[@pagy.options[:page_key]] = @pagy.page
public_send(@url, format:, **params)
end

def all_pages_export(format:)
public_send(@url, format:, **@params.except(@pagy.vars[:page_param].to_s))
public_send(@url, format:, **@params.except(@pagy.options[:page_key]))
end
end
17 changes: 8 additions & 9 deletions app/components/pagination_component.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# frozen_string_literal: true

class PaginationComponent < ApplicationComponent
include Pagy::Frontend

erb_template <<~ERB
<div class="pagination-component">
<%== pagy_bootstrap_nav(@pagy) %>
<%== @pagy.series_nav(:bootstrap) %>

<%= form_with url: url_for, method: :get, data: { controller: "form-update" },
class: "d-flex align-items-baseline gap-2" do |f| %>
<%= helpers.hash_to_hidden_fields(query_parameters) %>

<%= f.label @pagy.vars[:limit_param], t(".items_per_page"), class: "form-label text-nowrap text-secondary" %>
<%= f.select @pagy.vars[:limit_param], options_for_select(User::AVAILABLE_ITEMS_PER_PAGE, @pagy.limit),
{},
class: "form-select form-select-sm",
data: { action: "change->form-update#update" } %>
<%= f.label @pagy.options[:limit_key], t(".items_per_page"), class: "form-label text-nowrap text-secondary" %>
<%= f.select @pagy.options[:limit_key],
options_for_select(User::AVAILABLE_ITEMS_PER_PAGE, @pagy.limit),
{},
class: "form-select form-select-sm",
data: { action: "change->form-update#update" } %>
<% end %>
</div>
ERB
Expand All @@ -30,6 +29,6 @@ def initialize(pagy:, params: nil)
private

def query_parameters
(@params || request.query_parameters).merge(@pagy.vars[:page_param] => 1)
(@params || request.query_parameters).merge(@pagy.options[:page_key] => 1)
end
end
8 changes: 1 addition & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ApplicationController < ActionController::Base
include ChangelogContextApplication
include Localization
include Pagy::Backend
include Pagy::Method
include Authorization

acts_as_token_authentication_handler_for User
Expand Down Expand Up @@ -93,12 +93,6 @@ def current_user_has_permission?

private

def pagy_get_limit(vars)
limit_params = vars[:limit] || Pagy::DEFAULT[:limit_param]

params[limit_params] || current_user.items_per_page
end

def prepare_exception_notifier
request.env["exception_notifier.exception_data"] = {
current_user: current_user,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
.order(created_at: :desc)
@filter = ProcessorFilter.new(@cables, params)

@pagy, @cables = pagy(@filter.results.distinct)
@pagy, @cables = pagy(:countish, @filter.results.distinct, limit: pagy_get_limit(params))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/changelog_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
authorize! @changelog_entries, context: { scoped_object: }
@filter = ProcessorFilter.new(@changelog_entries, params)

@pagy, @changelog_entries = pagy(@filter.results)
@pagy, @changelog_entries = pagy(:countish, @filter.results, limit: pagy_get_limit(params))
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/external_app_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
@filter = ProcessorFilter.new(@external_app_records, params)
@external_app_records = @filter.results

@pagy, @external_app_records = pagy(@external_app_records)
@pagy, @external_app_records = pagy(@external_app_records, limit: pagy_get_limit(params))
end

def settings
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/power_distribution_units_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index

respond_to do |format|
format.json
format.html { @pagy, @pdus = pagy(@pdus) }
format.html { @pagy, @pdus = pagy(@pdus, limit: pagy_get_limit(params)) }
end
end

Expand Down
2 changes: 0 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

module ApplicationHelper
include Pagy::Frontend

CREATE_ANOTHER_ONE_ACTIONS = %w[new create].freeze

def accepted_format_for_attachment(model_klass, attribute_name)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def redirect_to_on_success_hidden_field_tag(redirect_to_on_success)

def pagy_to_hidden_fields(pagy)
hash_to_hidden_fields(
pagy.vars[:limit_param] => pagy.vars[pagy.vars[:limit_param]],
pagy.options[:limit_key] => pagy.options[pagy.options[:limit_key]],
)
end

Expand Down
Loading
Loading