From ac0cdc25a32ccd6306a30c386fa3046c04fc6d34 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 14 Jan 2020 14:54:24 -0500 Subject: [PATCH] Added manual pool order button --- app/controllers/weights_controller.rb | 19 +++++++- app/views/tournaments/bracket.html.erb | 51 ++++++++++++--------- config/routes.rb | 1 + test/controllers/weights_controller_test.rb | 28 +++++++++++ 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb index 173186e..77b63b5 100644 --- a/app/controllers/weights_controller.rb +++ b/app/controllers/weights_controller.rb @@ -1,6 +1,6 @@ class WeightsController < ApplicationController - before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen] - before_action :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen] + before_action :set_weight, only: [:pool_order, :show, :edit, :update, :destroy,:re_gen] + before_action :check_access, only: [:pool_order, :new,:create,:update,:destroy,:edit, :re_gen] # GET /weights/1 @@ -78,6 +78,21 @@ class WeightsController < ApplicationController GenerateTournamentMatches.new(@tournament).generateWeight(@weight) end + def pool_order + pool = params[:pool_to_order].to_i + if @weight.all_pool_matches_finished(pool) + PoolOrder.new(@weight.wrestlers_in_pool(pool)).getPoolOrder + respond_to do |format| + format.html { redirect_to @tournament, notice: "Pool #{pool} placing is updating for weight class #{@weight.max}." } + end + else + respond_to do |format| + format.html { redirect_to @tournament, notice: "Pool #{pool} for weight class #{@weight.max} still has matches to finish." } + end + end + + end + private # Use callbacks to share common setup or constraints between actions. def set_weight diff --git a/app/views/tournaments/bracket.html.erb b/app/views/tournaments/bracket.html.erb index 0899194..980cd3d 100644 --- a/app/views/tournaments/bracket.html.erb +++ b/app/views/tournaments/bracket.html.erb @@ -58,7 +58,7 @@ li:first-child,li:last-child { } <% cache ["#{@weight.id}_bracket", @weight] do %> - +
<%= @tournament.name %> - <%= @weight.max %> lbs Bracket
@@ -91,22 +91,20 @@ li:first-child,li:last-child { <% 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 %> -<% 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 %>

Move wrestler to pool with a bye

<%= form_tag '/wrestlers/update_pool' do %> @@ -121,4 +119,15 @@ li:first-child,li:last-child {
<%= submit_tag "Move", :class=>"btn btn-success"%> <% end %> +

+

Rerun getting pool order

+

If you changed the result of a match that changes the ranking of a pool.

+ <%= form_tag "/weights/#{@weight.id}/pool_order", :method => :post do %> +
+ <%= label_tag 'Pool to order' %>
+ <%= select_tag :pool_to_order, options_for_select((1..@weight.pools).step(1).to_a) %> +
+
+ <%= submit_tag "Get Pool Order", :class=>"btn btn-success"%> + <% end %> <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0548b68..330fa12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ Wrestling::Application.routes.draw do resources :wrestlers post "/weights/:id" => "weights#show" + post "weights/:id/pool_order" => "weights#pool_order" # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/test/controllers/weights_controller_test.rb b/test/controllers/weights_controller_test.rb index 7701439..2b8730c 100644 --- a/test/controllers/weights_controller_test.rb +++ b/test/controllers/weights_controller_test.rb @@ -29,6 +29,10 @@ class WeightsControllerTest < ActionController::TestCase def get_edit get :edit, params: { id: @weight.id } end + + def get_pool_order + post :pool_order, params: {pool_to_order: 1, id: @weight.id} + end def sign_in_owner sign_in users(:one) @@ -182,6 +186,30 @@ class WeightsControllerTest < ActionController::TestCase redirect end + test "logged in tournament owner can calculate a pool" do + sign_in_owner + get_pool_order + assert_redirected_to tournament_path(@tournament.id) + end + + test "logged in tournament delegate can calculate a pool" do + sign_in_tournament_delegate + get_pool_order + assert_redirected_to tournament_path(@tournament.id) + end + + test "logged in user not tournament owner cannot calculate a pool" do + sign_in_non_owner + get_pool_order + redirect + end + + test "logged school delegate not tournament owner cannot calculate a pool" do + sign_in_school_delegate + get_pool_order + redirect + end + test "view wegiht" do get :show, params: { id: 1 } success
@@ -71,19 +71,19 @@ li:first-child,li:last-child { <% if @weight.pool_bracket_type == "twoPoolsToFinal" %> - <%= render 'twoPoolFinalBracket' %> + <%= render 'twoPoolFinalBracket' %> <% end %> <% if @weight.pool_bracket_type == "twoPoolsToSemi" %> - <%= render 'twoPoolSemiBracket' %> + <%= render 'twoPoolSemiBracket' %> <% end %> <% if @weight.pool_bracket_type == "fourPoolsToQuarter" %> - <%= render 'fourPoolQuarterBracket' %> + <%= render 'fourPoolQuarterBracket' %> <% end %> <% if @weight.pool_bracket_type == "eightPoolsToQuarter" %> <%= render 'fourPoolQuarterBracket' %> <% end %> <% if @weight.pool_bracket_type == "fourPoolsToSemi" %> - <%= render 'fourPoolSemiBracket' %> + <%= render 'fourPoolSemiBracket' %> <% end %>