From 102fbffa3592dbd38f07bbaec5a2789852794a7b Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Thu, 23 Apr 2020 19:33:41 +0200 Subject: [PATCH 01/14] start groups table --- app/controllers/admin/groups_controller.rb | 24 ++++++++++++++++++++++ app/views/admin/groups/index.html.erb | 23 +++++++++++++++++++++ db/schema.rb | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 69175778..347c0b71 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -7,6 +7,30 @@ def index end def generate + # 50 Teilnehmer insgesamt + # mach 10 Gruppen á 5 Teilnehmer + # mach für jede Gruppe einen DB Eintrag mit name = "Group " + index Zahl + + # (Anzahl der Gruppen = Anzahl der Attendees, die attended haben / 6 ) + #p application.attended + # + # if @event.applications.attended && @event.applications.language_de + # attendants = @event.applications.attendants + + @attendants = @event.applications.application_selected.confirmed + puts ('huhuu') + puts @attendants + + # attendants.each do |attendant| + # puts ('huhuuu') + # puts @attendant + # end + puts @event.applications #.attendants + #attended = 'true') + # end + # Gruppennummer zuordnen put application_id in event_group_attendees + # + redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" end diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index b057b590..d41f835d 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -1,5 +1,28 @@ <% if @event.has_groups? %> has Groups + +<% @event_groups.each do |event_group| %> +

<%= event_group.name %>

+ + + + + + + + + + + + + +
AttendeesCoaches
+ <%= @application.name %> + + <%= @coach.name %> +
+<%end %> + <% else %> <%= button_to "Generate groups", generate_admin_event_groups_path(@event), method: :post %> <% end %> diff --git a/db/schema.rb b/db/schema.rb index ce065c54..b6a43c85 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -52,7 +52,7 @@ t.integer "state", default: 0, null: false t.boolean "lightningtalk_approved", default: false t.datetime "contacted_at" - t.boolean "first_time_coaching", default: false + t.boolean "first_time_coaching" t.boolean "coach_the_coaches", default: false t.string "sponsor" t.index ["coach_id"], name: "index_coach_applications_on_coach_id" From 9b1ead15097671c2efd3320724b1da1dd0f23862 Mon Sep 17 00:00:00 2001 From: juopmu Date: Thu, 23 Apr 2020 21:37:47 +0200 Subject: [PATCH 02/14] Add group tables --- app/controllers/admin/groups_controller.rb | 31 +++++---------- app/models/coach.rb | 1 + app/models/event.rb | 5 ++- app/models/event_group.rb | 5 +++ app/views/admin/groups/index.html.erb | 3 +- ...t_group_coaches_to_event_groups_coaches.rb | 5 +++ ...up_attendees_to_event_groups_applicants.rb | 5 +++ db/schema.rb | 38 +++++++++---------- 8 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 app/models/event_group.rb create mode 100644 db/migrate/20200423182041_change_event_group_coaches_to_event_groups_coaches.rb create mode 100644 db/migrate/20200423182618_change_event_group_attendees_to_event_groups_applicants.rb diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 347c0b71..612c6095 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -4,32 +4,19 @@ class Admin::GroupsController < ApplicationController before_action :find_event def index + @event_groups = @event.event_groups end def generate - # 50 Teilnehmer insgesamt - # mach 10 Gruppen á 5 Teilnehmer - # mach für jede Gruppe einen DB Eintrag mit name = "Group " + index Zahl + @attendees = @event.applications.application_selected.confirmed + @attendees.each_slice(6).with_index do |group, index| + event_group = EventGroup.create(event: @event, name: "Group #{index}") + group.each do |application| + event_group.applications << application + end + end - # (Anzahl der Gruppen = Anzahl der Attendees, die attended haben / 6 ) - #p application.attended - # - # if @event.applications.attended && @event.applications.language_de - # attendants = @event.applications.attendants - - @attendants = @event.applications.application_selected.confirmed - puts ('huhuu') - puts @attendants - - # attendants.each do |attendant| - # puts ('huhuuu') - # puts @attendant - # end - puts @event.applications #.attendants - #attended = 'true') - # end - # Gruppennummer zuordnen put application_id in event_group_attendees - # + @event_groups = @event.event_groups redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" end diff --git a/app/models/coach.rb b/app/models/coach.rb index ff6ce02d..cd7cf2c3 100644 --- a/app/models/coach.rb +++ b/app/models/coach.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 0fc10e9f..4f05e0ef 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 @@ -26,9 +27,9 @@ def name_and_date end def has_groups? - false + !event_groups.empty? end - + private def right_order_of_dates diff --git a/app/models/event_group.rb b/app/models/event_group.rb new file mode 100644 index 00000000..f430eff0 --- /dev/null +++ b/app/models/event_group.rb @@ -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 diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index d41f835d..ecca20fa 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -13,10 +13,9 @@ has Groups - <%= @application.name %> + <%= event_group.applications.map(&:name).join(", ") %> - <%= @coach.name %> diff --git a/db/migrate/20200423182041_change_event_group_coaches_to_event_groups_coaches.rb b/db/migrate/20200423182041_change_event_group_coaches_to_event_groups_coaches.rb new file mode 100644 index 00000000..59e2725b --- /dev/null +++ b/db/migrate/20200423182041_change_event_group_coaches_to_event_groups_coaches.rb @@ -0,0 +1,5 @@ +class ChangeEventGroupCoachesToEventGroupsCoaches < ActiveRecord::Migration[5.2] + def change + rename_table :event_group_coaches, :event_groups_coaches + end +end diff --git a/db/migrate/20200423182618_change_event_group_attendees_to_event_groups_applicants.rb b/db/migrate/20200423182618_change_event_group_attendees_to_event_groups_applicants.rb new file mode 100644 index 00000000..d5405e67 --- /dev/null +++ b/db/migrate/20200423182618_change_event_group_attendees_to_event_groups_applicants.rb @@ -0,0 +1,5 @@ +class ChangeEventGroupAttendeesToEventGroupsApplicants < ActiveRecord::Migration[5.2] + def change + rename_table :event_group_attendees, :event_groups_applications + end +end diff --git a/db/schema.rb b/db/schema.rb index b6a43c85..c3535b38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -52,7 +52,7 @@ t.integer "state", default: 0, null: false t.boolean "lightningtalk_approved", default: false t.datetime "contacted_at" - t.boolean "first_time_coaching" + t.boolean "first_time_coaching", default: false t.boolean "coach_the_coaches", default: false t.string "sponsor" t.index ["coach_id"], name: "index_coach_applications_on_coach_id" @@ -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| @@ -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 From 7e32ad0c462d4868781edaa0f364f15aab529632 Mon Sep 17 00:00:00 2001 From: Simao Freitas Date: Wed, 29 Apr 2020 21:05:43 +0200 Subject: [PATCH 03/14] add coaches to events --- app/controllers/admin/groups_controller.rb | 10 ++++- app/models/coach_application.rb | 1 + app/models/event_group.rb | 2 +- app/views/admin/groups/index.html.erb | 42 +++++++++---------- ...ches_to_event_groups_coach_applications.rb | 5 +++ db/schema.rb | 12 +++--- 6 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20200429185626_change_event_groups_coaches_to_event_groups_coach_applications.rb diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 612c6095..ff482de4 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -8,14 +8,22 @@ def index end def generate + # This needs to be wrapped in a transaction @attendees = @event.applications.application_selected.confirmed @attendees.each_slice(6).with_index do |group, index| - event_group = EventGroup.create(event: @event, name: "Group #{index}") + event_group = EventGroup.create(event: @event, name: "Group #{index + 1}") group.each do |application| event_group.applications << application end end + @coaches = @event.coach_applications.approved.to_a + @event.event_groups.each do |event_group| + # Check if we are assinging the last 2 coaches + coach_group = @coaches.pop(2) + event_group.coach_applications << coach_group unless coach_group.empty? + end + @event_groups = @event.event_groups redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" diff --git a/app/models/coach_application.rb b/app/models/coach_application.rb index e6c195ce..01cbf0cb 100644 --- a/app/models/coach_application.rb +++ b/app/models/coach_application.rb @@ -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 } diff --git a/app/models/event_group.rb b/app/models/event_group.rb index f430eff0..f1ab6678 100644 --- a/app/models/event_group.rb +++ b/app/models/event_group.rb @@ -1,5 +1,5 @@ class EventGroup < ApplicationRecord belongs_to :event - has_and_belongs_to_many :coaches + 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 diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index ecca20fa..1dee22d6 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -1,26 +1,26 @@ <% if @event.has_groups? %> -has Groups -<% @event_groups.each do |event_group| %> -

<%= event_group.name %>

- - - - - - - - - - - - - -
AttendeesCoaches
- <%= event_group.applications.map(&:name).join(", ") %> - -
-<%end %> + <% @event_groups.each do |event_group| %> +

<%= event_group.name %>

+ + + + + + + + + + + + + +
AttendeesCoaches
+ <%= event_group.applications.map(&:name).join(", ") %> + + +
+ <%end %> <% else %> <%= button_to "Generate groups", generate_admin_event_groups_path(@event), method: :post %> diff --git a/db/migrate/20200429185626_change_event_groups_coaches_to_event_groups_coach_applications.rb b/db/migrate/20200429185626_change_event_groups_coaches_to_event_groups_coach_applications.rb new file mode 100644 index 00000000..630ebe48 --- /dev/null +++ b/db/migrate/20200429185626_change_event_groups_coaches_to_event_groups_coach_applications.rb @@ -0,0 +1,5 @@ +class ChangeEventGroupsCoachesToEventGroupsCoachApplications < ActiveRecord::Migration[5.2] + def change + rename_table :event_groups_coaches, :event_groups_coach_applications + end +end diff --git a/db/schema.rb b/db/schema.rb index c3535b38..4c02f9e6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_04_23_182618) 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" @@ -88,13 +88,13 @@ t.index ["event_group_id"], name: "index_event_groups_applications_on_event_group_id" end - create_table "event_groups_coaches", force: :cascade do |t| + 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 ["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" + 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| @@ -152,6 +152,6 @@ 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" + add_foreign_key "event_groups_coach_applications", "coach_applications" + add_foreign_key "event_groups_coach_applications", "event_groups" end From f9584e08ebf43a151daeaf614e4001811c34f8d6 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Sun, 3 May 2020 19:23:31 +0200 Subject: [PATCH 04/14] Add coach names to event groups view and restructure logic of group creation --- app/controllers/admin/groups_controller.rb | 33 ++++++++++++++++------ app/views/admin/groups/index.html.erb | 4 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index ff482de4..491e3cd0 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -8,22 +8,37 @@ def index end def generate - # This needs to be wrapped in a transaction - @attendees = @event.applications.application_selected.confirmed - @attendees.each_slice(6).with_index do |group, index| + + @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 |application| - event_group.applications << application + group.each do |coach_application| + event_group.coach_applications << coach_application end end - @coaches = @event.coach_applications.approved.to_a + @attendees = @event.applications.application_selected.confirmed @event.event_groups.each do |event_group| - # Check if we are assinging the last 2 coaches - coach_group = @coaches.pop(2) - event_group.coach_applications << coach_group unless coach_group.empty? + attendee_group = @attendees.pop() + event_group.applications << attendee_group unless attendee_group.empty? end + # This needs to be wrapped in a transaction + # @attendees = @event.applications.application_selected.confirmed + # @attendees.each_slice(6).with_index do |group, index| + # event_group = EventGroup.create(event: @event, name: "Group #{index + 1}") + # group.each do |application| + # event_group.applications << application + # end + # end + + # @coaches = @event.coach_applications.approved.to_a + # @event.event_groups.each do |event_group| + # # Check if we are assinging the last 2 coaches + # coach_group = @coaches.pop(2) + # event_group.coach_applications << coach_group unless coach_group.empty? + # end + @event_groups = @event.event_groups redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index 1dee22d6..13ec6c29 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -15,7 +15,9 @@ <%= event_group.applications.map(&:name).join(", ") %> - + <% event_group.coach_applications.map do |application| %> + <%= application.coach.name %> + <% end %> From 053061de2f59841f6f0b54b6a5d5fd6a15672ce6 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 8 May 2020 00:24:38 +0200 Subject: [PATCH 05/14] fix attendee distribution to event groups --- app/controllers/admin/groups_controller.rb | 28 +++++++--------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 491e3cd0..4724fe45 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -9,6 +9,7 @@ def index def generate + # 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}") @@ -17,28 +18,15 @@ def generate end end - @attendees = @event.applications.application_selected.confirmed - @event.event_groups.each do |event_group| - attendee_group = @attendees.pop() - event_group.applications << attendee_group unless attendee_group.empty? + # add one attendee to each group as long as there are attendees in array + @attendees = @event.applications.application_selected.confirmed.to_a + @attendees.each do |attendee| + @event.event_groups.each do |event_group| + attendee_group = @attendees.pop(1) + event_group.applications << attendee_group unless attendee_group.empty? + end end - # This needs to be wrapped in a transaction - # @attendees = @event.applications.application_selected.confirmed - # @attendees.each_slice(6).with_index do |group, index| - # event_group = EventGroup.create(event: @event, name: "Group #{index + 1}") - # group.each do |application| - # event_group.applications << application - # end - # end - - # @coaches = @event.coach_applications.approved.to_a - # @event.event_groups.each do |event_group| - # # Check if we are assinging the last 2 coaches - # coach_group = @coaches.pop(2) - # event_group.coach_applications << coach_group unless coach_group.empty? - # end - @event_groups = @event.event_groups redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" From ff4b739f72b0bd1ec364eb2057d9f2dba24ae06e Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 8 May 2020 00:26:06 +0200 Subject: [PATCH 06/14] Add .vscode/ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c33bf252..ecdaea19 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ !/tmp/.keep .DS_Store capybara-* +.vscode/ # Ignore Byebug command history file. .byebug_history From d17136a851374d3dd6659bca69c6ea7c22b41444 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Mon, 18 May 2020 20:33:42 +0200 Subject: [PATCH 07/14] create regenerate action --- app/controllers/admin/groups_controller.rb | 26 +++++++++++++++++----- app/views/admin/groups/index.html.erb | 1 + config/routes.rb | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 4724fe45..4658c8f1 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -7,8 +7,28 @@ def index @event_groups = @event.event_groups 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 + 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| @@ -26,14 +46,8 @@ def generate event_group.applications << attendee_group unless attendee_group.empty? end end - - @event_groups = @event.event_groups - - redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated" end - private - def find_event @event = Event.find(params[:event_id]) end diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index 13ec6c29..45e6d0d1 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -1,5 +1,6 @@ <% if @event.has_groups? %> + <%= button_to "Regenerate groups", regenerate_admin_event_groups_path(@event), method: :post %> <% @event_groups.each do |event_group| %>

<%= event_group.name %>

diff --git a/config/routes.rb b/config/routes.rb index 084e2cd4..6ea8a91e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,6 +49,7 @@ resources :groups, only: [:index] do collection do post :generate + post :regenerate end end put :complete From d2127efa55c34b54bc28d2b8c9ae61020a1691ca Mon Sep 17 00:00:00 2001 From: Simao Freitas Date: Mon, 18 May 2020 20:44:52 +0200 Subject: [PATCH 08/14] reload event before adding new groups --- app/controllers/admin/groups_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 4658c8f1..4bedd3a5 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -7,7 +7,7 @@ def index @event_groups = @event.event_groups end - # An action to regenerate + # An action to regenerate # -> a controller method # -> button (to call the action) # -> a route @@ -22,6 +22,8 @@ def generate 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 From 18e9d164625f0b3300cc2cd9d6e76adad7df8492 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Wed, 20 May 2020 10:12:59 +0200 Subject: [PATCH 09/14] Add line breaks to event groups tables andadd printe styles --- app/assets/stylesheets/application.css | 39 ++++++++++++++++++++++++++ app/views/admin/groups/index.html.erb | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b238693d..db2bd45e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -497,3 +497,42 @@ nav.email-templates-menu li a:hover { input.grey { background-color: #c4220d; } + +/* 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; + } +} \ No newline at end of file diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index 45e6d0d1..20d485d7 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -13,11 +13,12 @@ From e870aa7ba756666ff5c026b323a50bad133f8a90 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 26 Jun 2020 10:52:18 +0200 Subject: [PATCH 10/14] group attendees by languages and distribute them to event groups --- app/controllers/admin/groups_controller.rb | 34 ++++++++++++++++++---- app/models/application.rb | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 4bedd3a5..33a480ce 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -42,11 +42,35 @@ def fill_groups # add one attendee to each group as long as there are attendees in array @attendees = @event.applications.application_selected.confirmed.to_a - @attendees.each do |attendee| - @event.event_groups.each do |event_group| - attendee_group = @attendees.pop(1) - event_group.applications << attendee_group unless attendee_group.empty? - end + + groupped_attendes_by_language = @attendees.group_by do |element| + [element.language_de, element.language_en] + end + + attendees_de = groupped_attendes_by_language[[true, false]] + attendees_en = groupped_attendes_by_language[[false, true]] + attendees_de_en = groupped_attendes_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 diff --git a/app/models/application.rb b/app/models/application.rb index 43c2aefc..d05ad55c 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -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) } enum state: { rejected: 0, waiting_list: 1, application_selected: 2, cancelled: 3 } From 8662f850c66c694105857a2692729a3e6fed5564 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 26 Jun 2020 10:58:25 +0200 Subject: [PATCH 11/14] edit comments and fix typos --- app/controllers/admin/groups_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 33a480ce..ba092d55 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -40,16 +40,16 @@ def fill_groups end end - # add one attendee to each group as long as there are attendees in array + # get selected attendees from DB @attendees = @event.applications.application_selected.confirmed.to_a - groupped_attendes_by_language = @attendees.group_by do |element| + grouped_attendees_by_language = @attendees.group_by do |element| [element.language_de, element.language_en] end - attendees_de = groupped_attendes_by_language[[true, false]] - attendees_en = groupped_attendes_by_language[[false, true]] - attendees_de_en = groupped_attendes_by_language[[true, true]] + 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) From 565e8c4215fbc7734834b590db83ef5c7440532e Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 26 Jun 2020 19:10:58 +0200 Subject: [PATCH 12/14] add language tags to event groups table view --- app/assets/stylesheets/application.css | 15 ++++++++++++ app/views/admin/groups/index.html.erb | 33 +++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index db2bd45e..7f2bd7cf 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -498,6 +498,21 @@ input.grey { background-color: #c4220d; } +.grid-wrapper { + display: grid; + grid-template-columns: 250px 250px; + margin-bottom: .5em; +} + +.language-tag { + padding: 0 .7em; + font-size: 12px; + width: fit-content; + background: linear-gradient(to right, #28B4F0, #F0A0C8); + color: #fff; + border-radius: 5px; +} + /* Printer styles */ @media print { diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index 20d485d7..28248a65 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -13,12 +13,39 @@ From b3b82a427edfa507f2afafad45017f2bb3d66ca1 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Sat, 27 Jun 2020 18:11:04 +0200 Subject: [PATCH 13/14] add attendees and coaches count info --- app/assets/stylesheets/application.css | 20 +++++++++++++++++++- app/controllers/admin/groups_controller.rb | 2 ++ app/views/admin/groups/index.html.erb | 8 ++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 7f2bd7cf..23050b23 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -504,11 +504,29 @@ input.grey { 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; - background: linear-gradient(to right, #28B4F0, #F0A0C8); color: #fff; border-radius: 5px; } diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index ba092d55..37f56693 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -5,6 +5,8 @@ class Admin::GroupsController < ApplicationController 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 diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index 28248a65..cc8f2ae2 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -1,5 +1,9 @@ <% if @event.has_groups? %> +
+
Attendees: <%= @attendees_count %>
+
Coaches: <%= @coaches_count %>
+
<%= button_to "Regenerate groups", regenerate_admin_event_groups_path(@event), method: :post %> <% @event_groups.each do |event_group| %>

<%= event_group.name %>

@@ -18,7 +22,7 @@ <%= application.name %> - + <% if application.language_de === true && application.language_en === true %> both languages <% elsif application.language_de === true && application.language_en === false %> @@ -36,7 +40,7 @@ <%= application.coach.name %> - + <% if application.coach.language_de === true && application.coach.language_en === true %> both languages <% elsif application.coach.language_de === true && application.coach.language_en === false %> From df4c2d98be4a407fb58678e7bcd9aef0f5a48700 Mon Sep 17 00:00:00 2001 From: Astrid Varga Date: Fri, 3 Jul 2020 19:36:19 +0200 Subject: [PATCH 14/14] Add logic to group attendees by OS additionally to language and add OS tag to groups view --- app/assets/stylesheets/application.css | 8 ++- app/controllers/admin/groups_controller.rb | 65 +++++++++++++++++----- app/views/admin/groups/index.html.erb | 13 ++++- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 23050b23..e17dadb4 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -500,7 +500,7 @@ input.grey { .grid-wrapper { display: grid; - grid-template-columns: 250px 250px; + grid-template-columns: 200px 200px 200px; margin-bottom: .5em; } @@ -523,7 +523,11 @@ input.grey { background: linear-gradient(to right, #28B4F0, #F0A0C8); } -.language-tag { +.cc-gradient-reverse { + background: linear-gradient(to right, #F0A0C8, #28B4F0); +} + +.tag { padding: 0 .7em; font-size: 12px; width: fit-content; diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 37f56693..768876a1 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -3,6 +3,8 @@ class Admin::GroupsController < ApplicationController before_action :require_admin before_action :find_event + GROUP_SIZE = 4 + def index @event_groups = @event.event_groups @coaches_count = @event.coach_applications.approved.size @@ -32,10 +34,14 @@ def regenerate private + def fetch_by_key(object, key) + object[key] || [] + end + 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| + @coaches.each_slice(1).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 @@ -46,27 +52,58 @@ def fill_groups @attendees = @event.applications.application_selected.confirmed.to_a grouped_attendees_by_language = @attendees.group_by do |element| - [element.language_de, element.language_en] + [element.language_de, element.language_en, element.os] 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) + attendees_de_mac = fetch_by_key(grouped_attendees_by_language, [true, false, "mac"]) + attendees_de_windows = fetch_by_key(grouped_attendees_by_language, [true, false, "windows"]) + attendees_de_linux = fetch_by_key(grouped_attendees_by_language, [true, false, "linux"]) + + attendees_en_mac = fetch_by_key(grouped_attendees_by_language, [false, true, "mac"]) + attendees_en_windows = fetch_by_key(grouped_attendees_by_language, [false, true, "windows"]) + attendees_en_linux = fetch_by_key(grouped_attendees_by_language, [false, true, "linux"]) + + attendees_de_en_mac = fetch_by_key(grouped_attendees_by_language, [true, true, "mac"]) + attendees_de_en_windows = fetch_by_key(grouped_attendees_by_language, [true, true, "windows"]) + attendees_de_en_linux = fetch_by_key(grouped_attendees_by_language, [true, true, "linux"]) + + attendees_de_mac_groups = attendees_de_mac.in_groups_of(GROUP_SIZE, false) + attendees_de_windows_groups = attendees_de_windows.in_groups_of(GROUP_SIZE, false) + attendees_de_linux_groups = attendees_de_linux.in_groups_of(GROUP_SIZE, false) + attendees_en_mac_groups = attendees_en_mac.in_groups_of(GROUP_SIZE, false) + attendees_en_windows_groups = attendees_en_windows.in_groups_of(GROUP_SIZE, false) + attendees_en_linux_groups = attendees_en_linux.in_groups_of(GROUP_SIZE, false) + + [attendees_de_mac_groups, attendees_en_mac_groups].each do |groups| + if groups.try :nonzero? + if (groups.last.size < GROUP_SIZE) + groups.last.concat(attendees_de_en_mac.pop(GROUP_SIZE - groups.last.size)) + end + end + end - if (de_groups.last.size < 6) - de_groups.last.concat(attendees_de_en.pop(6 - de_groups.last.size)) + [attendees_de_linux_groups, attendees_en_linux_groups].each do |groups| + if groups.try :nonzero? + if(groups.last.size < GROUP_SIZE) + groups.last.concat(attendees_de_en_linux.pop(GROUP_SIZE - groups.last.size)) + end + end end - if (en_groups.last.size < 6) - en_groups.last.concat(attendees_de_en.pop(6 - en_groups.last.size)) + [attendees_de_windows_groups, attendees_en_windows_groups].each do |groups| + if groups.try :nonzero? + if(groups.last.size < GROUP_SIZE) + groups.last.concat(attendees_de_en_windows.pop(GROUP_SIZE - groups.last.size)) + end + end end - de_en_groups = attendees_de_en.in_groups_of(6, false) + de_en_groups_mac = attendees_de_en_mac.in_groups_of(GROUP_SIZE, false) + de_en_groups_windows = attendees_de_en_windows.in_groups_of(GROUP_SIZE, false) + de_en_groups_linux = attendees_de_en_windows.in_groups_of(GROUP_SIZE, false) + + all_groups = attendees_de_mac_groups + attendees_de_windows_groups + attendees_de_linux_groups + attendees_en_mac_groups + attendees_en_windows_groups + attendees_en_linux_groups + de_en_groups_mac + de_en_groups_windows + de_en_groups_linux - 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| diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index cc8f2ae2..3ff358c1 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -22,7 +22,7 @@ <%= application.name %> - + <% if application.language_de === true && application.language_en === true %> both languages <% elsif application.language_de === true && application.language_en === false %> @@ -31,6 +31,15 @@ English <% end %> + + <% if application.os === "mac" %> + Mac + <% elsif application.os === "windows" %> + Windows + <% elsif application.os === "linux" %> + Linux + <% end %> + <% end %> @@ -40,7 +49,7 @@ <%= application.coach.name %> - + <% if application.coach.language_de === true && application.coach.language_en === true %> both languages <% elsif application.coach.language_de === true && application.coach.language_en === false %>
- <%= event_group.applications.map(&:name).join(", ") %> + <%= event_group.applications.map(&:name).join("
").html_safe %>
<% event_group.coach_applications.map do |application| %> <%= application.coach.name %> +
<% end %>
- <%= event_group.applications.map(&:name).join("
").html_safe %> + <% event_group.applications.map do |application| %> +
+ + <%= application.name %> + + + <% if application.language_de === true && application.language_en === true %> + both languages + <% elsif application.language_de === true && application.language_en === false %> + German + <% else %> + English + <% end %> + +
+ <% end %>
<% event_group.coach_applications.map do |application| %> - <%= application.coach.name %> -
+
+ + <%= application.coach.name %> + + + <% 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 %> + +
<% end %>