Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group matching #271

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ class Admin::GroupsController < ApplicationController
before_action :find_event

def index
@event_groups = @event.event_groups
end

def generate
@attendees = @event.applications.application_selected.confirmed
@attendees.each_slice(6).with_index do |group, index|
event_group = EventGroup.create(event: @event, name: "Group #{index}")
simaofreitas marked this conversation as resolved.
Show resolved Hide resolved
group.each do |application|
event_group.applications << application
end
end

@event_groups = @event.event_groups

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

Expand Down
1 change: 1 addition & 0 deletions app/models/coach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class Coach < ApplicationRecord
belongs_to :user
accepts_nested_attributes_for :user
has_many :coach_applications
has_and_belongs_to_many :event_groups
end
5 changes: 3 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Event < ApplicationRecord
has_many :applications
has_many :coach_applications
has_many :event_groups
before_create :copy_templates

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

def has_groups?
false
!event_groups.empty?
end

private

def right_order_of_dates
Expand Down
5 changes: 5 additions & 0 deletions app/models/event_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class EventGroup < ApplicationRecord
belongs_to :event
has_and_belongs_to_many :coaches
has_and_belongs_to_many :applications, join_table: "event_groups_applications"
end
22 changes: 22 additions & 0 deletions app/views/admin/groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
<% if @event.has_groups? %>
has Groups
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can delete this now


<% @event_groups.each do |event_group| %>
simaofreitas marked this conversation as resolved.
Show resolved Hide resolved
<h2><%= event_group.name %></h2>
<table>
<thead>
<tr>
<th>Attendees</th>
<th>Coaches</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%= event_group.applications.map(&:name).join(", ") %>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<%end %>

<% else %>
<%= button_to "Generate groups", generate_admin_event_groups_path(@event), method: :post %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeEventGroupCoachesToEventGroupsCoaches < ActiveRecord::Migration[5.2]
def change
rename_table :event_group_coaches, :event_groups_coaches
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeEventGroupAttendeesToEventGroupsApplicants < ActiveRecord::Migration[5.2]
def change
rename_table :event_group_attendees, :event_groups_applications
end
end
36 changes: 18 additions & 18 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_02_24_192634) do
ActiveRecord::Schema.define(version: 2020_04_23_182618) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -71,30 +71,30 @@
t.index ["user_id"], name: "index_coaches_on_user_id"
end

create_table "event_group_attendees", force: :cascade do |t|
t.bigint "application_id"
t.bigint "event_group_id"
create_table "event_groups", force: :cascade do |t|
t.bigint "event_id"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["application_id"], name: "index_event_group_attendees_on_application_id"
t.index ["event_group_id"], name: "index_event_group_attendees_on_event_group_id"
t.index ["event_id"], name: "index_event_groups_on_event_id"
end

create_table "event_group_coaches", force: :cascade do |t|
t.bigint "coach_application_id"
create_table "event_groups_applications", force: :cascade do |t|
t.bigint "application_id"
t.bigint "event_group_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["coach_application_id"], name: "index_event_group_coaches_on_coach_application_id"
t.index ["event_group_id"], name: "index_event_group_coaches_on_event_group_id"
t.index ["application_id"], name: "index_event_groups_applications_on_application_id"
t.index ["event_group_id"], name: "index_event_groups_applications_on_event_group_id"
end

create_table "event_groups", force: :cascade do |t|
t.bigint "event_id"
t.string "name"
create_table "event_groups_coaches", force: :cascade do |t|
t.bigint "coach_application_id"
t.bigint "event_group_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["event_id"], name: "index_event_groups_on_event_id"
t.index ["coach_application_id"], name: "index_event_groups_coaches_on_coach_application_id"
t.index ["event_group_id"], name: "index_event_groups_coaches_on_event_group_id"
end

create_table "events", id: :serial, force: :cascade do |t|
Expand Down Expand Up @@ -149,9 +149,9 @@

add_foreign_key "coach_applications", "coaches"
add_foreign_key "coach_applications", "events"
add_foreign_key "event_group_attendees", "applications"
add_foreign_key "event_group_attendees", "event_groups"
add_foreign_key "event_group_coaches", "coach_applications"
add_foreign_key "event_group_coaches", "event_groups"
add_foreign_key "event_groups", "events"
add_foreign_key "event_groups_applications", "applications"
add_foreign_key "event_groups_applications", "event_groups"
add_foreign_key "event_groups_coaches", "coach_applications"
add_foreign_key "event_groups_coaches", "event_groups"
end