mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added manual pool order button
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -58,7 +58,7 @@ li:first-child,li:last-child {
|
||||
}
|
||||
</style>
|
||||
<% cache ["#{@weight.id}_bracket", @weight] do %>
|
||||
<table class='smallText'>
|
||||
<table class='smallText'>
|
||||
<h5><strong><%= @tournament.name %> - <%= @weight.max %> lbs Bracket</strong></h5>
|
||||
<tr>
|
||||
<td valign="top" style="padding: 10px;">
|
||||
@@ -71,19 +71,19 @@ li:first-child,li:last-child {
|
||||
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<% 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 %>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -91,22 +91,20 @@ li:first-child,li:last-child {
|
||||
<% end %>
|
||||
|
||||
<% if can? :manage, @tournament %>
|
||||
<br><br>
|
||||
<h3>Swap Bracket Position</h3>
|
||||
<%= form_for(Wrestler.new, url: swap_wrestlers_path(@tournament)) do |f| %>
|
||||
<div class="field">
|
||||
<%= f.label 'Wrestler 1' %><br>
|
||||
<%= f.collection_select :originalId, @weight.wrestlers, :id, :name %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label 'Wrestler 2' %><br>
|
||||
<%= f.collection_select :swapId, @weight.wrestlers, :id, :name %>
|
||||
</div>
|
||||
<br>
|
||||
<%= submit_tag "Swap", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if can? :manage, @tournament %>
|
||||
<br><br>
|
||||
<h3>Swap Bracket Position</h3>
|
||||
<%= form_for(Wrestler.new, url: swap_wrestlers_path(@tournament)) do |f| %>
|
||||
<div class="field">
|
||||
<%= f.label 'Wrestler 1' %><br>
|
||||
<%= f.collection_select :originalId, @weight.wrestlers, :id, :name %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label 'Wrestler 2' %><br>
|
||||
<%= f.collection_select :swapId, @weight.wrestlers, :id, :name %>
|
||||
</div>
|
||||
<br>
|
||||
<%= submit_tag "Swap", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<br><br>
|
||||
<h3>Move wrestler to pool with a bye</h3>
|
||||
<%= form_tag '/wrestlers/update_pool' do %>
|
||||
@@ -121,4 +119,15 @@ li:first-child,li:last-child {
|
||||
<br>
|
||||
<%= submit_tag "Move", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<br><br>
|
||||
<h3>Rerun getting pool order</h3>
|
||||
<p>If you changed the result of a match that changes the ranking of a pool.</p>
|
||||
<%= form_tag "/weights/#{@weight.id}/pool_order", :method => :post do %>
|
||||
<div class="field">
|
||||
<%= label_tag 'Pool to order' %><br>
|
||||
<%= select_tag :pool_to_order, options_for_select((1..@weight.pools).step(1).to_a) %>
|
||||
</div>
|
||||
<br>
|
||||
<%= submit_tag "Get Pool Order", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -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".
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user