Skip to content
Open
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
24 changes: 23 additions & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class DashboardController < ApplicationController
skip_before_action :accept_terms, except: %i[dashboard show]

DEFAULT_UPCOMING_EVENTS = 5
MAX_WORKSHOP_QUERY = 10

helper_method :year_param

Expand All @@ -12,6 +13,7 @@ def show
@upcoming_workshops = upcoming_events.map.each_with_object({}) do |(key, value), hash|
hash[key] = EventPresenter.decorate_collection(value)
end
@has_more_events = total_upcoming_events_count > DEFAULT_UPCOMING_EVENTS

@testimonials = Testimonial.order(Arel.sql('RANDOM()')).limit(5).includes(:member)
end
Expand Down Expand Up @@ -56,7 +58,27 @@ def top_coach_query

def upcoming_events
workshops = Workshop.upcoming.includes(:chapter, :sponsors, :organisers)
all_events(workshops).sort_by(&:date_and_time).group_by(&:date)
.limit(MAX_WORKSHOP_QUERY)
sorted_events = all_events(workshops).sort_by(&:date_and_time)

limited_events = []
dates_shown = 0
prev_date = nil

sorted_events.each do |event|
dates_shown += 1 if event.date != prev_date
prev_date = event.date
break if dates_shown > 3 || limited_events.size >= DEFAULT_UPCOMING_EVENTS

limited_events << event
end

limited_events.group_by(&:date)
end

def total_upcoming_events_count
workshops = Workshop.upcoming.includes(:chapter, :sponsors, :organisers)
all_events(workshops).count
end

def upcoming_events_for_user
Expand Down
3 changes: 3 additions & 0 deletions app/views/dashboard/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
%h3.h5= date
= render workshops

- if @has_more_events
= link_to 'Explore all events →', events_path, class: 'btn btn-outline-primary mt-3'

.col-lg-4.pl-lg-5
%h3
= t('homepage.chapters.title')
Expand Down