From a821c28cf71fed14d0c5213397fbaf0a0816dd08 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Fri, 27 Mar 2015 16:33:09 +0000 Subject: [PATCH] Created one page for all pools --- app/controllers/static_pages_controller.rb | 8 ++--- app/models/weight.rb | 8 ++++- app/views/static_pages/_pool.html.erb | 35 ++++++++++++++++++++++ app/views/static_pages/brackets.html.erb | 20 +++++++++---- 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 app/views/static_pages/_pool.html.erb diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 938d21c..f46dc1e 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -40,10 +40,10 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(@weight.tournament_id) @matches = @tournament.upcomingMatches.select{|m| m.weight_id == @weight.id} @wrestlers = Wrestler.where(weight_id: @weight.id) - @poolOneWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 1} - @poolTwoWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 2} - @poolThreeWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 3} - @poolFourWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 4} + #@poolOneWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 1} + #@poolTwoWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 2} + #@poolThreeWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 3} + #@poolFourWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 4} end diff --git a/app/models/weight.rb b/app/models/weight.rb index c8fbf90..7920927 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -2,7 +2,7 @@ class Weight < ActiveRecord::Base belongs_to :tournament has_many :wrestlers, dependent: :destroy - attr_accessor :pools, :bracket_size, :bracket_type + attr_accessor :pools, :bracket_size, :bracket_type, :poolRounds def pools @wrestlers = self.wrestlers @@ -111,4 +111,10 @@ class Weight < ActiveRecord::Base return @matches end + def poolRounds(matches) + @matchups = matches.select{|m| m.weight_id == self.id} + @poolMatches = @matchups.select{|m| m.bracket_position == nil} + return @poolMatches.sort_by{|m| m.round}.last.round + end + end diff --git a/app/views/static_pages/_pool.html.erb b/app/views/static_pages/_pool.html.erb new file mode 100644 index 0000000..7d39920 --- /dev/null +++ b/app/views/static_pages/_pool.html.erb @@ -0,0 +1,35 @@ +<% @round = 1 %> +<% @pool = 1 %> +<% until @wrestlers.select{|w| w.generatePoolNumber == @pool}.blank? %> +
Pool <%= @pool %>
+ + + + + <% until @matches.select{|m| m.round == @round}.blank? %> + <% if @round <= @weight.poolRounds(@matches) %> + + <% end %> + <% @round = @round + 1 %> + <% end %> + + + + <% @wrestlers.select{|w| w.generatePoolNumber == @pool}.each do |w| %> + + + <% @round = 1 %> + <% until @matches.select{|m| m.round == @round}.blank? %> + <% if @round <= @weight.poolRounds(@matches) %> + + <% end %> + <% @round = @round + 1 %> + <% end %> + + + <% end %> + +
NameR<%= @round %>
<%= w.original_seed %> <%= w.name %> <%= w.season_win %>-<%= w.season_loss %> <%= w.school.name %><%= w.boutByRound(@round,@matches) %>
Result
+<% @pool = @pool + 1 %> +<% @round = 1 %> +<% end %> \ No newline at end of file diff --git a/app/views/static_pages/brackets.html.erb b/app/views/static_pages/brackets.html.erb index 0099db3..2a25911 100644 --- a/app/views/static_pages/brackets.html.erb +++ b/app/views/static_pages/brackets.html.erb @@ -6,10 +6,18 @@

<%= @weight.max %> lbs Bracket

-<% if @weight.pools == 4 %> - <%= render 'fourPool' %> -<% elsif @weight.pools == 2 %> - <%= render 'twoPool' %> -<% elsif @weight.pools == 1 %> - <%= render 'onePool' %> + +<%= render 'pool' %> + +<% if @bracketType == "twoPoolsToFinal" %> + <%= render 'twoPoolFinalBracket' %> +<% end %> +<% if @bracketType == "twoPoolsToSemi" %> + <%= render 'twoPoolSemiBracket' %> +<% end %> +<% if @bracketType == "fourPoolsToQuarter" %> + <%= render 'fourPoolQuarterBracket' %> +<% end %> +<% if @bracketType == "fourPoolsToSemi" %> + <%= render 'fourPoolSemiBracket' %> <% end %> \ No newline at end of file