The personal finance app for everyone (by everyone)
Ruby
feat: Add pagination in merchants page (#1965)
Alessio Cappabc3e5a824f53
diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rbindex db77ee413e..d6420b01f3 100644--- a/app/controllers/family_merchants_controller.rb+++ b/app/controllers/family_merchants_controller.rb@@ -5,8 +5,8 @@ class FamilyMerchantsController < ApplicationController@breadcrumbs = [ [ t("breadcrumbs.home"), root_path ], [ t("breadcrumbs.merchants"), nil ] ]# Show all merchants for this family- @family_merchants = Current.family.merchants.alphabetically- @provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically+ @all_family_merchants = Current.family.merchants.alphabetically+ @all_provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically# Show recently unlinked ProviderMerchants (within last 30 days)# Exclude merchants that are already assigned to transactions (they appear in provider_merchants)@@ -14,12 +14,15 @@ class FamilyMerchantsController < ApplicationController.where(family: Current.family).recently_unlinked.pluck(:merchant_id)- assigned_ids = @provider_merchants.pluck(:id)+ assigned_ids = @all_provider_merchants.pluck(:id)@unlinked_merchants = ProviderMerchant.where(id: recently_unlinked_ids - assigned_ids).alphabetically- @enhanceable_count = @provider_merchants.where(website_url: [ nil, "" ]).count+ @enhanceable_count = @all_provider_merchants.where(website_url: [ nil, "" ]).count@llm_available = Provider::Registry.get_provider(:openai).present?+ @pagy_family_merchants, @family_merchants = pagy(@all_family_merchants, page_param: :family_page, limit: safe_per_page)+ @pagy_provider_merchants, @provider_merchants = pagy(@all_provider_merchants, page_param: :provider_page, limit: safe_per_page)+render layout: "settings"enddiff --git a/app/views/family_merchants/index.html.erb b/app/views/family_merchants/index.html.erbindex e647e5833b..ceb8cb07cf 100644--- a/app/views/family_merchants/index.html.erb+++ b/app/views/family_merchants/index.html.erb@@ -19,10 +19,10 @@<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase"><p><%= t(".family_title", moniker: family_moniker) %></p><span class="text-subdued">·</span>- <p><%= @family_merchants.count %></p>+ <p><%= @all_family_merchants.count %></p></div>- <% if @family_merchants.any? %>+ <% if @all_family_merchants.any? %><div class="rounded-xl bg-container-inset space-y-1 p-1"><div class="bg-container rounded-lg shadow-border-xs overflow-x-auto"><table class="w-full">@@ -52,13 +52,17 @@</div></div><% end %>++ <div class="pt-4">+ <%= render "shared/pagination", pagy: @pagy_family_merchants %>+ </div></section><section class="space-y-3"><div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase"><p><%= t(".provider_title") %></p><span class="text-subdued">·</span>- <p><%= @provider_merchants.count %></p>+ <p><%= @all_provider_merchants.count %></p></div><div class="p-4 bg-container-inset border border-secondary rounded-lg">@@ -84,7 +88,7 @@</div><% end %>- <% if @provider_merchants.any? %>+ <% if @all_provider_merchants.any? %><div class="rounded-xl bg-container-inset space-y-1 p-1"><div class="bg-container rounded-lg shadow-border-xs overflow-x-auto"><table class="w-full">@@ -106,6 +110,10 @@<p class="text-secondary text-sm text-center"><%= t(".provider_empty", moniker: family_moniker_downcase) %></p></div><% end %>++ <div class="pt-4">+ <%= render "shared/pagination", pagy: @pagy_provider_merchants %>+ </div></section><% if @unlinked_merchants.any? %>