-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathdashboard_controller.rb
More file actions
89 lines (71 loc) · 2.67 KB
/
dashboard_controller.rb
File metadata and controls
89 lines (71 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class DashboardController < ApplicationController
include AttendanceConcerns
before_action :is_logged_in?, only: %i[dashboard]
skip_before_action :accept_terms, except: %i[dashboard show]
DEFAULT_UPCOMING_EVENTS = 5
helper_method :year_param
def show
@chapters = Chapter.active.all.order(:created_at)
@user = current_user ? MemberPresenter.new(current_user) : nil
@upcoming_workshops = upcoming_events.map.inject({}) do |hash, (key, value)|
hash[key] = EventPresenter.decorate_collection(value)
hash
end
@attending_ids = attending_workshops
@testimonials = Testimonial.order(Arel.sql('RANDOM()')).limit(5).includes(:member)
end
def dashboard
@user = MemberPresenter.new(current_user)
@ordered_events = upcoming_events_for_user.map.inject({}) do |hash, (key, value)|
hash[key] = EventPresenter.decorate_collection(value)
hash
end
@announcements = current_user.announcements.active
@attending_ids = attending_workshops
end
def code; end
def faq; end
def about; end
def wall_of_fame
@coaches_count = top_coach_query.length
coaches = Member.where(id: top_coach_query
.year(year_param))
.includes(:skills)
@pagy, @coaches = pagy(coaches, items: 80)
end
def participant_guide; end
private
def year_param
params.permit(:year)[:year]&.to_i || Time.zone.today.year
end
def top_coach_query
WorkshopInvitation.to_coaches
.attended
.group(:member_id)
.order(Arel.sql('COUNT(member_id) DESC'))
.select(:member_id)
end
def upcoming_events
workshops = Workshop.upcoming.includes(:chapter, :sponsors)
all_events(workshops).sort_by(&:date_and_time).group_by(&:date)
end
def upcoming_events_for_user
chapter_workshops = Workshop.upcoming
.where(chapter: current_user.chapters)
.includes(:chapter, :sponsors)
.to_a
accepted_workshops = current_user.workshop_invitations.accepted
.joins(:workshop)
.merge(Workshop.upcoming)
.includes(workshop: %i[chapter sponsors])
.map(&:workshop)
all_events(chapter_workshops + accepted_workshops)
.sort_by(&:date_and_time)
.group_by(&:date)
end
def all_events(workshops)
meeting = Meeting.includes(:venue).next
events = Event.includes(:venue, :sponsors).upcoming.take(DEFAULT_UPCOMING_EVENTS)
[*workshops, *events, meeting].uniq.compact
end
end