From c0379784a92603cadcc0c3ef12435c53fae00860 Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Wed, 22 Mar 2017 15:42:21 -0400 Subject: [PATCH 1/3] Added wristband field to participant view to help with wristband distribution #220 --- app/controllers/participants_controller.rb | 12 ++++++++++++ app/models/organization_category.rb | 13 +++++++------ app/views/participants/show.html.erb | 8 +++++--- ...d_building_status_to_organization_category.rb | 5 +++++ db/seeds.rb | 16 ++++++++-------- 5 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20170322191208_add_building_status_to_organization_category.rb diff --git a/app/controllers/participants_controller.rb b/app/controllers/participants_controller.rb index 6b0e2b2c..d42bc79c 100644 --- a/app/controllers/participants_controller.rb +++ b/app/controllers/participants_controller.rb @@ -34,6 +34,18 @@ def lookup # GET /participants/1.json def show @memberships = @participant.memberships.all + + building_statuses = @memberships.map { |m| m.organization.organization_category.building_status } + building = building_statuses.include?(true) + if @memberships.empty? + @wristband = "None - No organizations" + elsif !@participant.has_signed_waiver + @wristband = "None - No waiver signature" + elsif building + @wristband = "Red" + else + @wristband = "Blue" + end end # GET /participants/new diff --git a/app/models/organization_category.rb b/app/models/organization_category.rb index ae501a71..51529665 100644 --- a/app/models/organization_category.rb +++ b/app/models/organization_category.rb @@ -4,12 +4,13 @@ # # ### Columns # -# Name | Type | Attributes -# ----------------- | ------------------ | --------------------------- -# **`created_at`** | `datetime` | -# **`id`** | `integer` | `not null, primary key` -# **`name`** | `string(255)` | -# **`updated_at`** | `datetime` | +# Name | Type | Attributes +# ---------------------- | ------------------ | --------------------------- +# **`building_status`** | `boolean` | +# **`created_at`** | `datetime` | +# **`id`** | `integer` | `not null, primary key` +# **`name`** | `string(255)` | +# **`updated_at`** | `datetime` | # class OrganizationCategory < ActiveRecord::Base diff --git a/app/views/participants/show.html.erb b/app/views/participants/show.html.erb index 016bcc17..9751d33a 100644 --- a/app/views/participants/show.html.erb +++ b/app/views/participants/show.html.erb @@ -5,12 +5,14 @@
+
Wristband:
+
<%= @wristband %>
+
<%= model_class.human_attribute_name(:has_signed_waiver) %>:
+
<%= @participant.has_signed_waiver ? "Yes" : "No" %>
<% if can?(:read_phone_number, @participant) %>
<%= model_class.human_attribute_name(:phone_number) %>:
<%= @participant.formatted_phone_number %> - <% end %> -
<%= model_class.human_attribute_name(:has_signed_waiver) %>:
-
<%= @participant.has_signed_waiver ? "yes" : "no" %>
+ <% end %>
<%= model_class.human_attribute_name(:department) %>:
<%= @participant.department %>
<%= model_class.human_attribute_name(:student_class) %>:
diff --git a/db/migrate/20170322191208_add_building_status_to_organization_category.rb b/db/migrate/20170322191208_add_building_status_to_organization_category.rb new file mode 100644 index 00000000..ec352394 --- /dev/null +++ b/db/migrate/20170322191208_add_building_status_to_organization_category.rb @@ -0,0 +1,5 @@ +class AddBuildingStatusToOrganizationCategory < ActiveRecord::Migration + def change + add_column :organization_categories, :building_status, :boolean + end +end diff --git a/db/seeds.rb b/db/seeds.rb index f9e6d14b..38a77ced 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,14 +15,14 @@ # Organization Categories ----------------------------------------------------- puts 'Organization Categories' -fraternity = OrganizationCategory.create({ name: 'Fraternity'}) -sorority = OrganizationCategory.create({ name: 'Sorority'}) -independent = OrganizationCategory.create({ name: 'Independent'}) -blitz = OrganizationCategory.create({ name: 'Blitz'}) -concessions = OrganizationCategory.create({ name: 'Concessions'}) -non_building = OrganizationCategory.create({ name: 'Non-Building' }) -scc = OrganizationCategory.create({ name: 'SCC'}) -staff = OrganizationCategory.create({ name: 'Staff' }) +fraternity = OrganizationCategory.create({ name: 'Fraternity', building_status: true }) +sorority = OrganizationCategory.create({ name: 'Sorority', building_status: true }) +independent = OrganizationCategory.create({ name: 'Independent', building_status: true}) +blitz = OrganizationCategory.create({ name: 'Blitz', building_status: true }) +concessions = OrganizationCategory.create({ name: 'Concessions', building_status: true }) +non_building = OrganizationCategory.create({ name: 'Non-Building', building_status: false }) +scc = OrganizationCategory.create({ name: 'SCC', building_status: false }) +staff = OrganizationCategory.create({ name: 'Staff', building_status: false }) # Organizations --------------------------------------------------------------- puts 'Organizations' From ff5cb9d709868bd99a03b5311f9b8c0be6e49d84 Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Thu, 23 Mar 2017 13:02:04 -0400 Subject: [PATCH 2/3] Added rake db:migrate to travis script so it can build with migrations --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5cbcbff5..924502e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ bundler_args: --without development staging production sudo: false before_script: - bundle exec rake db:test:prepare + - bundle exec rake db:migrate RAILS_ENV=test From 209149854baddbf0b53feb29e6bc7d508dbca0a1 Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Mon, 27 Mar 2017 23:19:04 -0400 Subject: [PATCH 3/3] Define wristband colors as constants --- app/controllers/participants_controller.rb | 18 +++++++++++------- ...building_status_to_organization_category.rb | 5 ----- ...add_is_building_to_organization_category.rb | 5 +++++ 3 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 db/migrate/20170322191208_add_building_status_to_organization_category.rb create mode 100644 db/migrate/20170322191208_add_is_building_to_organization_category.rb diff --git a/app/controllers/participants_controller.rb b/app/controllers/participants_controller.rb index d42bc79c..eef49089 100644 --- a/app/controllers/participants_controller.rb +++ b/app/controllers/participants_controller.rb @@ -1,7 +1,8 @@ class ParticipantsController < ApplicationController load_and_authorize_resource skip_load_resource only: [:create] before_action :set_participant, only: [:show, :edit, :update, :destroy] - + before_action :set_wristband_colors + # GET /participants # GET /participants.json def index @@ -35,16 +36,16 @@ def lookup def show @memberships = @participant.memberships.all - building_statuses = @memberships.map { |m| m.organization.organization_category.building_status } - building = building_statuses.include?(true) + building_statuses = @memberships.map { |m| m.organization.organization_category.is_building } + is_building = building_statuses.include?(true) if @memberships.empty? @wristband = "None - No organizations" elsif !@participant.has_signed_waiver @wristband = "None - No waiver signature" - elsif building - @wristband = "Red" + elsif is_building + @wristband = @wristband_colors[:building] else - @wristband = "Blue" + @wristband = @wristband_colors[:nonbuilding] end end @@ -92,5 +93,8 @@ def participant_create_params def participant_update_params params.require(:participant).permit(:phone_number, :has_signed_waiver, :has_signed_hardhat_waiver) end -end + def set_wristband_colors + @wristband_colors = { :building => "Red", :nonbuilding => "Blue" } + end +end diff --git a/db/migrate/20170322191208_add_building_status_to_organization_category.rb b/db/migrate/20170322191208_add_building_status_to_organization_category.rb deleted file mode 100644 index ec352394..00000000 --- a/db/migrate/20170322191208_add_building_status_to_organization_category.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddBuildingStatusToOrganizationCategory < ActiveRecord::Migration - def change - add_column :organization_categories, :building_status, :boolean - end -end diff --git a/db/migrate/20170322191208_add_is_building_to_organization_category.rb b/db/migrate/20170322191208_add_is_building_to_organization_category.rb new file mode 100644 index 00000000..4ae80946 --- /dev/null +++ b/db/migrate/20170322191208_add_is_building_to_organization_category.rb @@ -0,0 +1,5 @@ +class AddIsBuildingToOrganizationCategory < ActiveRecord::Migration + def change + add_column :organization_categories, :is_building, :boolean + end +end