Skip to content

Commit ad712f2

Browse files
authored
Enhance/load times (#1126)
This pull request introduces several improvements to the Better Together platform, focusing on enhanced filtering, sorting, and pagination for pages and platform invitations, as well as UI and performance enhancements. The changes include new backend logic for filtering and sorting collections, improved pagination styling, and better preloading of associations to optimize queries. ### Platform Invitations: Filtering, Sorting, and Pagination * Added comprehensive filtering and sorting logic to the `PlatformInvitationsController`, allowing invitations to be filtered by status, email, date fields, and sorted by multiple attributes. Pagination is now applied to the invitations list for better usability. [[1]](diffhunk://#diff-5197dbd0633c5f56fd1b09d798ff9a5c902c5fbabe36ada2107c0a2ba580cb95R10-R35) [[2]](diffhunk://#diff-5197dbd0633c5f56fd1b09d798ff9a5c902c5fbabe36ada2107c0a2ba580cb95R148-R260) * Updated controller actions for create, destroy, and resend to consistently redirect to the invitations index page and improved error handling for form submissions. [[1]](diffhunk://#diff-5197dbd0633c5f56fd1b09d798ff9a5c902c5fbabe36ada2107c0a2ba580cb95L22-R74) [[2]](diffhunk://#diff-5197dbd0633c5f56fd1b09d798ff9a5c902c5fbabe36ada2107c0a2ba580cb95L57-R104) [[3]](diffhunk://#diff-5197dbd0633c5f56fd1b09d798ff9a5c902c5fbabe36ada2107c0a2ba580cb95L88-R126) ### Pages: Filtering, Sorting, and Performance * Refactored the `PagesController` to support filtering by title and slug, sorting by various attributes, and paginating results. Content blocks are now preloaded with their associations for improved performance. [[1]](diffhunk://#diff-f88a9949466215662c8d25574d12de2b72ccc9af3d089d6b847eea3b6cb33f5fL17-R30) [[2]](diffhunk://#diff-f88a9949466215662c8d25574d12de2b72ccc9af3d089d6b847eea3b6cb33f5fR165-R251) * Simplified and modularized permitted parameters for page creation and update, improving maintainability and clarity. ### UI and Styles * Added a new `pagination.scss` file and imported it into the main stylesheet, providing custom styles for pagination components and enhancing accessibility and responsiveness. [[1]](diffhunk://#diff-5499b5855ee11d3be02ebb1d25ee68dbe0331c7a2fc94250b73f716f42b803c6R39) [[2]](diffhunk://#diff-75ee5cb95b10419a7583f3d14d33fe4db015a119b41b60e9094959e658cdc0dfR1-R79) ### Performance * Improved performance in the events controller by removing unnecessary preloading of text translations for events. ### Cleanup * Removed the unused `event_datetime_controller.js` file, cleaning up legacy code related to event time synchronization.
2 parents e345724 + 54fd526 commit ad712f2

File tree

62 files changed

+2785
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2785
-451
lines changed

app/assets/javascripts/better_together/controllers/event_datetime_controller.js

Lines changed: 0 additions & 127 deletions
This file was deleted.

app/assets/stylesheets/better_together/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@use 'metrics';
3737
@use 'navigation';
3838
@use 'notifications';
39+
@use 'pagination';
3940
@use 'profiles';
4041
@use 'share';
4142
@use 'sidebar_nav';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Better Together Pagination Styles */
2+
.pagination {
3+
--bs-pagination-padding-x: 0.75rem;
4+
--bs-pagination-padding-y: 0.5rem;
5+
--bs-pagination-font-size: 0.875rem;
6+
--bs-pagination-color: var(--bs-link-color);
7+
--bs-pagination-bg: transparent;
8+
--bs-pagination-border-width: 0;
9+
--bs-pagination-border-color: transparent;
10+
--bs-pagination-border-radius: 0.375rem;
11+
--bs-pagination-hover-color: var(--bs-primary);
12+
--bs-pagination-hover-bg: var(--bs-gray-100);
13+
--bs-pagination-hover-border-color: transparent;
14+
--bs-pagination-focus-color: var(--bs-primary);
15+
--bs-pagination-focus-bg: var(--bs-gray-100);
16+
--bs-pagination-focus-box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
17+
--bs-pagination-active-color: #fff;
18+
--bs-pagination-active-bg: var(--bs-primary);
19+
--bs-pagination-active-border-color: var(--bs-primary);
20+
--bs-pagination-disabled-color: var(--bs-secondary-color);
21+
--bs-pagination-disabled-bg: transparent;
22+
--bs-pagination-disabled-border-color: transparent;
23+
}
24+
25+
.pagination-info {
26+
display: flex;
27+
align-items: center;
28+
min-height: 2rem;
29+
}
30+
31+
.pagination-info small {
32+
font-weight: 500;
33+
letter-spacing: 0.025em;
34+
}
35+
36+
/* Responsive pagination */
37+
@media (max-width: 768px) {
38+
.pagination-info {
39+
margin-bottom: 0.75rem;
40+
text-align: center;
41+
width: 100%;
42+
}
43+
44+
.pagination {
45+
justify-content: center !important;
46+
}
47+
48+
.d-flex.justify-content-between.align-items-center.flex-wrap {
49+
flex-direction: column;
50+
align-items: center;
51+
}
52+
}
53+
54+
/* Enhanced focus states for accessibility */
55+
.page-link:focus {
56+
outline: 2px solid transparent;
57+
outline-offset: 2px;
58+
}
59+
60+
.page-link:focus-visible {
61+
box-shadow: var(--bs-pagination-focus-box-shadow);
62+
outline: 2px solid var(--bs-primary);
63+
outline-offset: 2px;
64+
}
65+
66+
/* Smooth transitions */
67+
.page-link {
68+
transition: all 0.15s ease-in-out;
69+
}
70+
71+
/* Card styling for pagination container */
72+
.pagination .card {
73+
background: var(--bs-gray-50);
74+
border: 1px solid var(--bs-border-color-translucent);
75+
}
76+
77+
.pagination .card-body {
78+
background: transparent;
79+
}

app/controllers/better_together/events_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ def preload_event_associations! # rubocop:todo Metrics/CyclomaticComplexity, Met
325325

326326
# Preload translations for the event itself
327327
@event.string_translations.load
328-
@event.text_translations.load
329328

330329
# Preload cover image attachment to avoid attachment queries
331330
@event.cover_image_attachment&.blob&.load if @event.cover_image.attached?

app/controllers/better_together/pages_controller.rb

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ class PagesController < FriendlyResourceController # rubocop:todo Metrics/ClassL
1414

1515
def index
1616
authorize resource_class
17-
@pages = resource_collection
17+
18+
@pages = build_filtered_collection
19+
@pages = apply_sorting(@pages)
20+
@pages = @pages.page(params[:page]).per(25)
1821
end
1922

2023
def show
2124
# Hide pages that don't exist or aren't viewable to the current user as 404s
2225
render_not_found and return if @page.nil?
2326

24-
@content_blocks = @page.content_blocks
27+
# Preload content blocks with their associations for better performance
28+
@content_blocks = @page.content_blocks.includes(
29+
background_image_file_attachment: :blob
30+
)
2531
@layout = 'layouts/better_together/page'
2632
@layout = @page.layout if @page.layout.present?
2733
end
@@ -141,29 +147,13 @@ def safe_page_redirect_url
141147

142148
def set_page
143149
@page = set_resource_instance
150+
return unless @page
151+
152+
@page = preload_page_associations(@page)
144153
rescue ActiveRecord::RecordNotFound
145154
render_not_found && return
146155
end
147156

148-
def page_params # rubocop:todo Metrics/MethodLength
149-
params.require(:page).permit(
150-
:meta_description, :keywords, :published_at, :sidebar_nav_id,
151-
:privacy, :layout, :template, *Page.localized_attribute_list,
152-
*Page.extra_permitted_attributes,
153-
page_blocks_attributes: [
154-
:id, :position, :_destroy,
155-
{
156-
block_attributes: [
157-
:id, :type, :identifier, :_destroy,
158-
*BetterTogether::Content::Block.localized_block_attributes,
159-
*BetterTogether::Content::Block.storext_keys,
160-
*BetterTogether::Content::Block.extra_permitted_attributes
161-
]
162-
}
163-
]
164-
)
165-
end
166-
167157
def resource_class
168158
::BetterTogether::Page
169159
end
@@ -172,8 +162,92 @@ def resource_collection
172162
policy_scope(resource_class)
173163
end
174164

165+
def apply_sorting(collection)
166+
sort_by = params[:sort_by]
167+
sort_direction = params[:sort_direction] == 'desc' ? :desc : :asc
168+
169+
case sort_by
170+
when 'title', 'slug'
171+
collection.i18n.order(sort_by.to_sym => sort_direction)
172+
else
173+
collection.order(collection.arel_table[:identifier].send(sort_direction))
174+
end
175+
end
176+
177+
def build_filtered_collection
178+
collection = base_collection
179+
collection = apply_title_filter(collection) if params[:title_filter].present?
180+
collection = apply_slug_filter(collection) if params[:slug_filter].present?
181+
collection
182+
end
183+
175184
def translatable_conditions
176185
[]
177186
end
187+
188+
def base_collection
189+
resource_collection.includes(
190+
:string_translations,
191+
page_blocks: {
192+
block: [{ background_image_file_attachment: :blob }]
193+
}
194+
)
195+
end
196+
197+
def apply_title_filter(collection)
198+
search_term = params[:title_filter].strip
199+
collection.i18n { title.matches("%#{search_term}%") }
200+
end
201+
202+
def apply_slug_filter(collection)
203+
search_term = params[:slug_filter].strip
204+
collection.i18n { slug.matches("%#{search_term}%") }
205+
end
206+
207+
def preload_page_associations(page)
208+
resource_class.includes(page_includes).find(page.id)
209+
end
210+
211+
def page_includes
212+
[
213+
:string_translations,
214+
:sidebar_nav,
215+
{ page_blocks: {
216+
block: [{ background_image_file_attachment: :blob }]
217+
} }
218+
]
219+
end
220+
221+
def page_params
222+
params.require(:page).permit(
223+
basic_page_attributes + page_blocks_permitted_attributes
224+
)
225+
end
226+
227+
def basic_page_attributes
228+
[
229+
:meta_description, :keywords, :published_at, :sidebar_nav_id,
230+
:privacy, :layout, :template, *Page.localized_attribute_list,
231+
*Page.extra_permitted_attributes
232+
]
233+
end
234+
235+
def page_blocks_permitted_attributes
236+
[
237+
page_blocks_attributes: [
238+
:id, :position, :_destroy,
239+
{ block_attributes: block_permitted_attributes }
240+
]
241+
]
242+
end
243+
244+
def block_permitted_attributes
245+
[
246+
:id, :type, :identifier, :_destroy,
247+
*BetterTogether::Content::Block.localized_block_attributes,
248+
*BetterTogether::Content::Block.storext_keys,
249+
*BetterTogether::Content::Block.extra_permitted_attributes
250+
]
251+
end
178252
end
179253
end

0 commit comments

Comments
 (0)