Skip to content

Commit f9584e0

Browse files
committed
Add coach names to event groups view and restructure logic of group creation
1 parent 7e32ad0 commit f9584e0

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

app/controllers/admin/groups_controller.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,37 @@ def index
88
end
99

1010
def generate
11-
# This needs to be wrapped in a transaction
12-
@attendees = @event.applications.application_selected.confirmed
13-
@attendees.each_slice(6).with_index do |group, index|
11+
12+
@coaches = @event.coach_applications.approved.to_a
13+
@coaches.each_slice(2).with_index do |group, index|
1414
event_group = EventGroup.create(event: @event, name: "Group #{index + 1}")
15-
group.each do |application|
16-
event_group.applications << application
15+
group.each do |coach_application|
16+
event_group.coach_applications << coach_application
1717
end
1818
end
1919

20-
@coaches = @event.coach_applications.approved.to_a
20+
@attendees = @event.applications.application_selected.confirmed
2121
@event.event_groups.each do |event_group|
22-
# Check if we are assinging the last 2 coaches
23-
coach_group = @coaches.pop(2)
24-
event_group.coach_applications << coach_group unless coach_group.empty?
22+
attendee_group = @attendees.pop()
23+
event_group.applications << attendee_group unless attendee_group.empty?
2524
end
2625

26+
# This needs to be wrapped in a transaction
27+
# @attendees = @event.applications.application_selected.confirmed
28+
# @attendees.each_slice(6).with_index do |group, index|
29+
# event_group = EventGroup.create(event: @event, name: "Group #{index + 1}")
30+
# group.each do |application|
31+
# event_group.applications << application
32+
# end
33+
# end
34+
35+
# @coaches = @event.coach_applications.approved.to_a
36+
# @event.event_groups.each do |event_group|
37+
# # Check if we are assinging the last 2 coaches
38+
# coach_group = @coaches.pop(2)
39+
# event_group.coach_applications << coach_group unless coach_group.empty?
40+
# end
41+
2742
@event_groups = @event.event_groups
2843

2944
redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated"

app/views/admin/groups/index.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
<%= event_group.applications.map(&:name).join(", ") %>
1616
</td>
1717
<td>
18-
18+
<% event_group.coach_applications.map do |application| %>
19+
<%= application.coach.name %>
20+
<% end %>
1921
</td>
2022
</tr>
2123
</tbody>

0 commit comments

Comments
 (0)