Skip to content

Commit 9b1ead1

Browse files
committed
Add group tables
1 parent 102fbff commit 9b1ead1

File tree

8 files changed

+48
-45
lines changed

8 files changed

+48
-45
lines changed

app/controllers/admin/groups_controller.rb

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@ class Admin::GroupsController < ApplicationController
44
before_action :find_event
55

66
def index
7+
@event_groups = @event.event_groups
78
end
89

910
def generate
10-
# 50 Teilnehmer insgesamt
11-
# mach 10 Gruppen á 5 Teilnehmer
12-
# mach für jede Gruppe einen DB Eintrag mit name = "Group " + index Zahl
11+
@attendees = @event.applications.application_selected.confirmed
12+
@attendees.each_slice(6).with_index do |group, index|
13+
event_group = EventGroup.create(event: @event, name: "Group #{index}")
14+
group.each do |application|
15+
event_group.applications << application
16+
end
17+
end
1318

14-
# (Anzahl der Gruppen = Anzahl der Attendees, die attended haben / 6 )
15-
#p application.attended
16-
#
17-
# if @event.applications.attended && @event.applications.language_de
18-
# attendants = @event.applications.attendants
19-
20-
@attendants = @event.applications.application_selected.confirmed
21-
puts ('huhuu')
22-
puts @attendants
23-
24-
# attendants.each do |attendant|
25-
# puts ('huhuuu')
26-
# puts @attendant
27-
# end
28-
puts @event.applications #.attendants
29-
#attended = 'true')
30-
# end
31-
# Gruppennummer zuordnen put application_id in event_group_attendees
32-
#
19+
@event_groups = @event.event_groups
3320

3421
redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated"
3522
end

app/models/coach.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ class Coach < ApplicationRecord
33
belongs_to :user
44
accepts_nested_attributes_for :user
55
has_many :coach_applications
6+
has_and_belongs_to_many :event_groups
67
end

app/models/event.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Event < ApplicationRecord
22
has_many :applications
33
has_many :coach_applications
4+
has_many :event_groups
45
before_create :copy_templates
56

67
validates :name, :place, :scheduled_at, :application_start, :application_end, :confirmation_date, :start_time, :end_time, presence: true
@@ -26,9 +27,9 @@ def name_and_date
2627
end
2728

2829
def has_groups?
29-
false
30+
!event_groups.empty?
3031
end
31-
32+
3233
private
3334

3435
def right_order_of_dates

app/models/event_group.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class EventGroup < ApplicationRecord
2+
belongs_to :event
3+
has_and_belongs_to_many :coaches
4+
has_and_belongs_to_many :applications, join_table: "event_groups_applications"
5+
end

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ has Groups
1313
<tbody>
1414
<tr>
1515
<td>
16-
<%= @application.name %>
16+
<%= event_group.applications.map(&:name).join(", ") %>
1717
</td>
1818
<td>
19-
<%= @coach.name %>
2019
</td>
2120
</tr>
2221
</tbody>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ChangeEventGroupCoachesToEventGroupsCoaches < ActiveRecord::Migration[5.2]
2+
def change
3+
rename_table :event_group_coaches, :event_groups_coaches
4+
end
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ChangeEventGroupAttendeesToEventGroupsApplicants < ActiveRecord::Migration[5.2]
2+
def change
3+
rename_table :event_group_attendees, :event_groups_applications
4+
end
5+
end

db/schema.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2020_02_24_192634) do
13+
ActiveRecord::Schema.define(version: 2020_04_23_182618) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -52,7 +52,7 @@
5252
t.integer "state", default: 0, null: false
5353
t.boolean "lightningtalk_approved", default: false
5454
t.datetime "contacted_at"
55-
t.boolean "first_time_coaching"
55+
t.boolean "first_time_coaching", default: false
5656
t.boolean "coach_the_coaches", default: false
5757
t.string "sponsor"
5858
t.index ["coach_id"], name: "index_coach_applications_on_coach_id"
@@ -71,30 +71,30 @@
7171
t.index ["user_id"], name: "index_coaches_on_user_id"
7272
end
7373

74-
create_table "event_group_attendees", force: :cascade do |t|
75-
t.bigint "application_id"
76-
t.bigint "event_group_id"
74+
create_table "event_groups", force: :cascade do |t|
75+
t.bigint "event_id"
76+
t.string "name"
7777
t.datetime "created_at", null: false
7878
t.datetime "updated_at", null: false
79-
t.index ["application_id"], name: "index_event_group_attendees_on_application_id"
80-
t.index ["event_group_id"], name: "index_event_group_attendees_on_event_group_id"
79+
t.index ["event_id"], name: "index_event_groups_on_event_id"
8180
end
8281

83-
create_table "event_group_coaches", force: :cascade do |t|
84-
t.bigint "coach_application_id"
82+
create_table "event_groups_applications", force: :cascade do |t|
83+
t.bigint "application_id"
8584
t.bigint "event_group_id"
8685
t.datetime "created_at", null: false
8786
t.datetime "updated_at", null: false
88-
t.index ["coach_application_id"], name: "index_event_group_coaches_on_coach_application_id"
89-
t.index ["event_group_id"], name: "index_event_group_coaches_on_event_group_id"
87+
t.index ["application_id"], name: "index_event_groups_applications_on_application_id"
88+
t.index ["event_group_id"], name: "index_event_groups_applications_on_event_group_id"
9089
end
9190

92-
create_table "event_groups", force: :cascade do |t|
93-
t.bigint "event_id"
94-
t.string "name"
91+
create_table "event_groups_coaches", force: :cascade do |t|
92+
t.bigint "coach_application_id"
93+
t.bigint "event_group_id"
9594
t.datetime "created_at", null: false
9695
t.datetime "updated_at", null: false
97-
t.index ["event_id"], name: "index_event_groups_on_event_id"
96+
t.index ["coach_application_id"], name: "index_event_groups_coaches_on_coach_application_id"
97+
t.index ["event_group_id"], name: "index_event_groups_coaches_on_event_group_id"
9898
end
9999

100100
create_table "events", id: :serial, force: :cascade do |t|
@@ -149,9 +149,9 @@
149149

150150
add_foreign_key "coach_applications", "coaches"
151151
add_foreign_key "coach_applications", "events"
152-
add_foreign_key "event_group_attendees", "applications"
153-
add_foreign_key "event_group_attendees", "event_groups"
154-
add_foreign_key "event_group_coaches", "coach_applications"
155-
add_foreign_key "event_group_coaches", "event_groups"
156152
add_foreign_key "event_groups", "events"
153+
add_foreign_key "event_groups_applications", "applications"
154+
add_foreign_key "event_groups_applications", "event_groups"
155+
add_foreign_key "event_groups_coaches", "coach_applications"
156+
add_foreign_key "event_groups_coaches", "event_groups"
157157
end

0 commit comments

Comments
 (0)