From b5d07e103e1a75ee2256397714beab203beda496 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 31 Jan 2017 13:43:56 +0000 Subject: [PATCH 1/4] Swap wrestlers moved from edit wrestler to the bracket page --- app/controllers/tournaments_controller.rb | 2 +- app/views/tournaments/bracket.html.erb | 17 +++++++++++++++++ app/views/wrestlers/_form.html.erb | 14 +------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index b89d609..0f443b6 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -13,7 +13,7 @@ class TournamentsController < ApplicationController @wrestler = Wrestler.find(params[:wrestler][:originalId]) respond_to do |format| if SwapWrestlers.new.swapWrestlers(params[:wrestler][:originalId], params[:wrestler][:swapId]) - format.html { redirect_to @wrestler, notice: 'Wrestler was successfully swaped.' } + format.html { redirect_to "/tournaments/#{@wrestler.tournament.id}/brackets/#{@wrestler.weight.id}", notice: 'Wrestler was successfully swaped.' } format.json { render action: 'show', status: :created, location: @wrestler } end end diff --git a/app/views/tournaments/bracket.html.erb b/app/views/tournaments/bracket.html.erb index 3b476f2..04094b0 100644 --- a/app/views/tournaments/bracket.html.erb +++ b/app/views/tournaments/bracket.html.erb @@ -27,4 +27,21 @@ <% if @weight.wrestlers.size <= 6 && @weight.allPoolMatchesFinished(1) %> <%= render 'onePoolResults' %> <% end %> +<% end %> + +<% if can? :manage, @tournament %> +

+

Swap Bracket Position

+ <%= form_for(Wrestler.new, url: swap_wrestlers_path(@tournament)) do |f| %> +
+ <%= f.label 'Wrestler 1' %>
+ <%= f.collection_select :originalId, @weight.wrestlers, :id, :name %> +
+
+ <%= f.label 'Wrestler 2' %>
+ <%= f.collection_select :swapId, @weight.wrestlers, :id, :name %> +
+
+ <%= submit_tag "Swap", :class=>"btn btn-success"%> + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/wrestlers/_form.html.erb b/app/views/wrestlers/_form.html.erb index bb1a141..6faa35e 100644 --- a/app/views/wrestlers/_form.html.erb +++ b/app/views/wrestlers/_form.html.erb @@ -52,19 +52,7 @@ <% end %> -<% if can? :manage, @wrestler.tournament %> -

-

Swap Bracket Position

- <%= form_for(Wrestler.new, url: swap_wrestlers_path(@wrestler.tournament)) do |f| %> - <%= f.hidden_field :originalId, :value => @wrestler.id %> -
- <%= f.label 'Swap With' %>
- <%= f.collection_select :swapId, @wrestler.weight.wrestlers, :id, :name %> -
-
- <%= submit_tag "Swap", :class=>"btn btn-success"%> - <% end %> -<% end %> + From 86bb0b6f3cb7ebfb2e77475247238eda52107b73 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 31 Jan 2017 14:01:09 +0000 Subject: [PATCH 2/4] Fixed cache names so multiple tournaments cache at once --- app/views/tournaments/all_brackets.html.erb | 2 +- app/views/tournaments/bracket.html.erb | 2 +- app/views/tournaments/team_scores.html.erb | 2 +- app/views/tournaments/up_matches.html.erb | 2 +- app/views/wrestlers/show.html.erb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/tournaments/all_brackets.html.erb b/app/views/tournaments/all_brackets.html.erb index 9182666..3278faa 100644 --- a/app/views/tournaments/all_brackets.html.erb +++ b/app/views/tournaments/all_brackets.html.erb @@ -1,4 +1,4 @@ -<% cache ["all_brackets", @tournament] do %> +<% cache ["#{@tournament.id}_all_brackets", @tournament] do %> - - -
Championship Bracket After Pool
+
Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • - -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 1st -
  •  
  • +
  •  
<% end %>
-
-
3rd/4th
    <% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 3rd -
  •  
  • +
  •  
<% end %>
-
-
Consolation Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "5/6"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 5th -
  •  
  • +
  •  
<% end %>
-
-
7th/8th
    <% @matches.select{|m|m.bracket_position == "7/8"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 7th -
  •  
  • +
  •  
<% end %>
-
diff --git a/app/views/tournaments/_fourPoolSemiBracket.html.erb b/app/views/tournaments/_fourPoolSemiBracket.html.erb index d52c13c..c6da986 100644 --- a/app/views/tournaments/_fourPoolSemiBracket.html.erb +++ b/app/views/tournaments/_fourPoolSemiBracket.html.erb @@ -1,191 +1,123 @@ - - - -
Championship Bracket After Pool
+
Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 1st -
  •  
  • +
  •  
<% end %>
-
-
3rd/4th
    <% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 3rd -
  •  
  • +
  •  
<% end %>
-
-
Consolation Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "5/6"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 5th -
  •  
  • +
  •  
<% end %>
-
-
7th/8th
    <% @matches.select{|m|m.bracket_position == "7/8"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 7th -
  •  
  • +
  •  
<% end %>
-
diff --git a/app/views/tournaments/_twoPoolFinalBracket.html.erb b/app/views/tournaments/_twoPoolFinalBracket.html.erb index a058c12..fc3aeb7 100644 --- a/app/views/tournaments/_twoPoolFinalBracket.html.erb +++ b/app/views/tournaments/_twoPoolFinalBracket.html.erb @@ -1,108 +1,46 @@ - - -
-
Championship Match
+
Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 1st -
  •  
  • +
  •  
<% end %>
-
3rd/4th
    <% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 3rd -
  •  
  • +
  •  
<% end %>
diff --git a/app/views/tournaments/_twoPoolSemiBracket.html.erb b/app/views/tournaments/_twoPoolSemiBracket.html.erb index bb23f26..41ac11d 100644 --- a/app/views/tournaments/_twoPoolSemiBracket.html.erb +++ b/app/views/tournaments/_twoPoolSemiBracket.html.erb @@ -1,122 +1,59 @@ - - -
-
Championship Bracket After Pool
+
Bracket After Pool
    <% @matches.select{|m|m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
  • <% end %>
    <% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 1st -
  •  
  • +
  •  
<% end %>
-
-
3rd/4th
    <% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %> -
  •  
  • +
  •  
  • <%= match.w1_name %>
  • -
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • +
  • <%= match.bout_number %> <%= match.bracketScore %> 
  • <%= match.w2_name %>
  • -
  •  
  • +
  •  
    -
  •  
  • +
  •  
  • -
  • <%= match.winnerName %>
  • +
  • <%= match.winnerName %>
  • 3rd -
  •  
  • +
  •  
<% end %> diff --git a/app/views/tournaments/all_brackets.html.erb b/app/views/tournaments/all_brackets.html.erb index be740a9..fe213c7 100644 --- a/app/views/tournaments/all_brackets.html.erb +++ b/app/views/tournaments/all_brackets.html.erb @@ -1,6 +1,6 @@ <% cache ["#{@tournament.id}_all_brackets", @tournament] do %> - +/* + * Bracket Layout Specifics +*/ +main, ul { + display:flex; +} + +ul { + flex-direction:column; + width: 100px; + list-style:none; + padding:0; +} + +.game + li { + flex-grow:1; +} + +li:first-child,li:last-child { + flex-grow:.5; +} + +.game { + padding-left:5px; +} + +.winner { + font-weight:bold; +} + +.game span { + float:right; + margin-right:5px; +} + +.game-top { + border-bottom:1px solid #aaa; +} + +.game-top + li { + border-right:1px solid #aaa; min-height:30px; +} + +.bracket-winner { + border-bottom:1px solid #aaa; +} + +.game-bottom { + border-top:1px solid #aaa; +} +
<% @tournament.weights.sort_by{|w| w.max}.each do |w| %> diff --git a/app/views/tournaments/bracket.html.erb b/app/views/tournaments/bracket.html.erb index d5404c8..1ee6a27 100644 --- a/app/views/tournaments/bracket.html.erb +++ b/app/views/tournaments/bracket.html.erb @@ -1,4 +1,56 @@ + <% cache ["#{@weight.id}_bracket", @weight] do %>

@@ -7,26 +59,33 @@ <%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>

-

<%= @weight.max %> lbs Bracket

- - <%= 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 %> -

- <% if @weight.wrestlers.size <= 6 && @weight.allPoolMatchesFinished(1) %> - <%= render 'onePoolResults' %> - <% end %> + +
<%= @tournament.name %> - <%= @weight.max %> lbs Bracket
+ + + + + + +
+ <% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %> + <% @wrestlers = Wrestler.where(weight_id: @weight.id) %> + <% @pools = @weight.poolRounds(@matches) %> + <%= render 'pool' %> + + <% if @weight.pool_bracket_type == "twoPoolsToFinal" %> + <%= render 'twoPoolFinalBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "twoPoolsToSemi" %> + <%= render 'twoPoolSemiBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "fourPoolsToQuarter" %> + <%= render 'fourPoolQuarterBracket' %> + <% end %> + <% if @weight.pool_bracket_type == "fourPoolsToSemi" %> + <%= render 'fourPoolSemiBracket' %> + <% end %> +
<% end %> <% if can? :manage, @tournament %>