mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-20 14:09:17 +00:00
Added manual pool order button
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class WeightsController < ApplicationController
|
class WeightsController < ApplicationController
|
||||||
before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen]
|
before_action :set_weight, only: [:pool_order, :show, :edit, :update, :destroy,:re_gen]
|
||||||
before_action :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen]
|
before_action :check_access, only: [:pool_order, :new,:create,:update,:destroy,:edit, :re_gen]
|
||||||
|
|
||||||
|
|
||||||
# GET /weights/1
|
# GET /weights/1
|
||||||
@@ -78,6 +78,21 @@ class WeightsController < ApplicationController
|
|||||||
GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
|
GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
|
||||||
end
|
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
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_weight
|
def set_weight
|
||||||
|
|||||||
@@ -105,8 +105,6 @@ li:first-child,li:last-child {
|
|||||||
<br>
|
<br>
|
||||||
<%= submit_tag "Swap", :class=>"btn btn-success"%>
|
<%= submit_tag "Swap", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
<% if can? :manage, @tournament %>
|
|
||||||
<br><br>
|
<br><br>
|
||||||
<h3>Move wrestler to pool with a bye</h3>
|
<h3>Move wrestler to pool with a bye</h3>
|
||||||
<%= form_tag '/wrestlers/update_pool' do %>
|
<%= form_tag '/wrestlers/update_pool' do %>
|
||||||
@@ -121,4 +119,15 @@ li:first-child,li:last-child {
|
|||||||
<br>
|
<br>
|
||||||
<%= submit_tag "Move", :class=>"btn btn-success"%>
|
<%= submit_tag "Move", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% 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 %>
|
<% end %>
|
||||||
@@ -14,6 +14,7 @@ Wrestling::Application.routes.draw do
|
|||||||
resources :wrestlers
|
resources :wrestlers
|
||||||
|
|
||||||
post "/weights/:id" => "weights#show"
|
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.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
get :edit, params: { id: @weight.id }
|
get :edit, params: { id: @weight.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_pool_order
|
||||||
|
post :pool_order, params: {pool_to_order: 1, id: @weight.id}
|
||||||
|
end
|
||||||
|
|
||||||
def sign_in_owner
|
def sign_in_owner
|
||||||
sign_in users(:one)
|
sign_in users(:one)
|
||||||
end
|
end
|
||||||
@@ -182,6 +186,30 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
redirect
|
redirect
|
||||||
end
|
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
|
test "view wegiht" do
|
||||||
get :show, params: { id: 1 }
|
get :show, params: { id: 1 }
|
||||||
success
|
success
|
||||||
|
|||||||
Reference in New Issue
Block a user