Skip to content
Draft
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
!/tmp/.keep
.DS_Store
capybara-*
.vscode/

# Ignore Byebug command history file.
.byebug_history
72 changes: 72 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,75 @@ nav.email-templates-menu li a:hover {
input.grey {
background-color: #c4220d;
}

.grid-wrapper {
display: grid;
grid-template-columns: 250px 250px;
margin-bottom: .5em;
}

.info-wrapper {
display: flex;
/* justify-content: space-evenly; */
margin-bottom: 1em;
font-weight: bold;
color: #fff;
}

.info-wrapper .info {
border-right: 1px solid #ffff;
padding: 15px;
text-align: left;
width: 30em;
}

.cc-gradient {
background: linear-gradient(to right, #28B4F0, #F0A0C8);
}

.language-tag {
padding: 0 .7em;
font-size: 12px;
width: fit-content;
color: #fff;
border-radius: 5px;
}

/* Printer styles */

@media print {
header,
input,
footer,
.top-menu {
display: none;
}

body {
color: #000;
background-color: #fff;
}

.container {
width: 100%;
}

table {
break-inside: avoid;
}

h2 {
page-break-inside: avoid;
margin-top: 30px;
}

/* Hacky solution to make avoidance of page break work ^^
https://stackoverflow.com/a/53742871/9328428
*/
h2::after {
content: "";
display: block;
height: 200px;
margin-bottom: -200px;
}
}
64 changes: 64 additions & 0 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,78 @@ class Admin::GroupsController < ApplicationController
before_action :find_event

def index
@event_groups = @event.event_groups
@coaches_count = @event.coach_applications.approved.size
@attendees_count = @event.applications.application_selected.size
end

# An action to regenerate
# -> a controller method
# -> button (to call the action)
# -> a route
# -> isolate generate behaviour in its own method

def generate
fill_groups
@event_groups = @event.event_groups
redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated"
end

def regenerate
@event_groups = @event.event_groups
@event_groups.destroy_all
@event.reload

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

private

def fill_groups
# create a group for each pair of coaches
@coaches = @event.coach_applications.approved.to_a
@coaches.each_slice(2).with_index do |group, index|
event_group = EventGroup.create(event: @event, name: "Group #{index + 1}")
group.each do |coach_application|
event_group.coach_applications << coach_application
end
end

# get selected attendees from DB
@attendees = @event.applications.application_selected.confirmed.to_a

grouped_attendees_by_language = @attendees.group_by do |element|
[element.language_de, element.language_en]
end

attendees_de = grouped_attendees_by_language[[true, false]]
attendees_en = grouped_attendees_by_language[[false, true]]
attendees_de_en = grouped_attendees_by_language[[true, true]]

de_groups = attendees_de.in_groups_of(6, false)
en_groups = attendees_en.in_groups_of(6, false)

if (de_groups.last.size < 6)
de_groups.last.concat(attendees_de_en.pop(6 - de_groups.last.size))
end

if (en_groups.last.size < 6)
en_groups.last.concat(attendees_de_en.pop(6 - en_groups.last.size))
end

de_en_groups = attendees_de_en.in_groups_of(6, false)

all_groups = de_groups + en_groups + de_en_groups

# FIXME: This can cause attendees to not be assigned to event groups
@event.event_groups.each do |event_group|
group_to_add = all_groups.pop(1)
break if group_to_add.nil?
event_group.applications << group_to_add
end
end

def find_event
@event = Event.find(params[:event_id])
end
Expand Down
1 change: 1 addition & 0 deletions app/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Application < ApplicationRecord
scope :cancelled, -> { where(state: :cancelled) }
scope :not_marked_as_selected, -> { where(selected_on: nil) }
scope :confirmed, -> { where(attendance_confirmed: true) }
scope :language_de, -> { where(language_de: true) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed as we are not using it


enum state: { rejected: 0, waiting_list: 1, application_selected: 2, cancelled: 3 }

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
1 change: 1 addition & 0 deletions app/models/coach_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CoachApplication < ApplicationRecord
accepts_nested_attributes_for :event

scope :to_contact, -> { where(contacted_at: nil, state: :approved) }
scope :approved, ->{ where(state: :approved) }

enum state: { pending: 0, approved: 1, rejected: 2, cancelled: 3 }

Expand Down
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 :coach_applications, join_table: "event_groups_coach_applications"
has_and_belongs_to_many :applications, join_table: "event_groups_applications"
end
59 changes: 58 additions & 1 deletion app/views/admin/groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
<% if @event.has_groups? %>
has Groups

<div class="info-wrapper cc-gradient">
<div class="info">Attendees: <%= @attendees_count %></div>
<div class="info">Coaches: <%= @coaches_count %></div>
</div>
<%= button_to "Regenerate groups", regenerate_admin_event_groups_path(@event), method: :post %>
<% @event_groups.each do |event_group| %>
<h2><%= event_group.name %></h2>
<table>
<thead>
<tr>
<th>Attendees</th>
<th>Coaches</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<% event_group.applications.map do |application| %>
<div class="grid-wrapper">
<span>
<%= application.name %>
</span>
<span class="language-tag cc-gradient">
<% if application.language_de === true && application.language_en === true %>
both languages
<% elsif application.language_de === true && application.language_en === false %>
German
<% else %>
English
<% end %>
</span>
</div>
<% end %>
</td>
<td>
<% event_group.coach_applications.map do |application| %>
<div class="grid-wrapper">
<span>
<%= application.coach.name %>
</span>
<span class="language-tag cc-gradient">
<% if application.coach.language_de === true && application.coach.language_en === true %>
both languages
<% elsif application.coach.language_de === true && application.coach.language_en === false %>
German
<% else %>
English
<% end %>
</span>
</div>
<% end %>
</td>
</tr>
</tbody>
</table>
<%end %>

<% else %>
<%= button_to "Generate groups", generate_admin_event_groups_path(@event), method: :post %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
resources :groups, only: [:index] do
collection do
post :generate
post :regenerate
end
end
put :complete
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeEventGroupsCoachesToEventGroupsCoachApplications < ActiveRecord::Migration[5.2]
def change
rename_table :event_groups_coaches, :event_groups_coach_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_29_185626) 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_coach_applications", 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_coach_applications_on_coach_application_id"
t.index ["event_group_id"], name: "index_event_groups_coach_applications_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_coach_applications", "coach_applications"
add_foreign_key "event_groups_coach_applications", "event_groups"
end