mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added functionality for a tournament director to move a wrestler to a pool that has a bye for greater flexibility
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class WrestlersController < ApplicationController
|
||||
before_action :set_wrestler, only: [:show, :edit, :update, :destroy]
|
||||
before_action :check_access, only: [:new,:create,:update,:destroy,:edit]
|
||||
before_action :set_wrestler, only: [:show, :edit, :update, :destroy, :update_pool]
|
||||
before_action :check_access, only: [:new,:create,:update,:destroy,:edit,:update_pool]
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,25 @@ class WrestlersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def update_pool
|
||||
@tournament = @wrestler.tournament
|
||||
@weight = @wrestler.weight
|
||||
@weights = @tournament.weights.sort_by{|w| w.max}
|
||||
@school = @wrestler.school
|
||||
if params[:wrestler]['pool']
|
||||
@wrestler.pool = params[:wrestler]['pool']
|
||||
respond_to do |format|
|
||||
if @wrestler.update(wrestler_params)
|
||||
format.html { redirect_to "/weights/#{@wrestler.weight.id}/", notice: 'Wrestler was successfully updated. Please re-generate this weight classes matches.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: 'edit' }
|
||||
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /wrestlers/1
|
||||
# DELETE /wrestlers/1.json
|
||||
def destroy
|
||||
@@ -88,14 +107,19 @@ class WrestlersController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def wrestler_params
|
||||
params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra,:offical_weight)
|
||||
params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra,:offical_weight,:pool)
|
||||
end
|
||||
def check_access
|
||||
if params[:school]
|
||||
@school = School.find(params[:school])
|
||||
#@tournament = Tournament.find(@school.tournament.id)
|
||||
elsif params[:wrestler]
|
||||
if params[:wrestler]["school_id"]
|
||||
@school = School.find(params[:wrestler]["school_id"])
|
||||
else
|
||||
@wrestler = Wrestler.find(params[:wrestler]["id"])
|
||||
@school = @wrestler.school
|
||||
end
|
||||
#@tournament = Tournament.find(@school.tournament.id)
|
||||
elsif @wrestler
|
||||
@school = @wrestler.school
|
||||
|
||||
@@ -17,6 +17,18 @@ class Weight < ActiveRecord::Base
|
||||
# self.tournament.destroyAllMatches
|
||||
end
|
||||
|
||||
def pools_with_bye
|
||||
pool = 1
|
||||
pools_with_a_bye = []
|
||||
until pool > self.pools do
|
||||
if wrestlersForPool(pool).first.hasAPoolBye
|
||||
pools_with_a_bye << pool
|
||||
end
|
||||
pool = pool + 1
|
||||
end
|
||||
pools_with_a_bye
|
||||
end
|
||||
|
||||
def wrestlersForPool(poolNumber)
|
||||
#For some reason this does not work
|
||||
# wrestlers.select{|w| w.pool == poolNumber}
|
||||
@@ -98,4 +110,8 @@ class Weight < ActiveRecord::Base
|
||||
PoolOrder.new(wrestlersForPool(pool)).getPoolOrder
|
||||
end
|
||||
|
||||
def wrestlersWithoutPool
|
||||
wrestlers.select{|w| w.pool == nil}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,11 +5,11 @@ class GeneratePoolNumbers
|
||||
|
||||
def savePoolNumbers
|
||||
if @weight.pools == 4
|
||||
saveFourPoolNumbers(@weight.wrestlers)
|
||||
saveFourPoolNumbers(@weight.wrestlersWithoutPool)
|
||||
elsif @weight.pools == 2
|
||||
saveTwoPoolNumbers(@weight.wrestlers)
|
||||
saveTwoPoolNumbers(@weight.wrestlersWithoutPool)
|
||||
elsif @weight.pools == 1
|
||||
saveOnePoolNumbers(@weight.wrestlers)
|
||||
saveOnePoolNumbers(@weight.wrestlersWithoutPool)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -104,3 +104,19 @@ li:first-child,li:last-child {
|
||||
<%= submit_tag "Swap", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if can? :manage, @tournament %>
|
||||
<br><br>
|
||||
<h3>Move wrestler to pool with a bye</h3>
|
||||
<%= form_tag '/wrestlers/update_pool' do %>
|
||||
<div class="field">
|
||||
<%= label_tag 'Wrestler to move' %><br>
|
||||
<%= collection_select(:wrestler, :id, @weight.wrestlers, :id, :name) %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= label_tag 'Pool to move to' %><br>
|
||||
<%= select :wrestler, :pool, @weight.pools_with_bye %>
|
||||
</div>
|
||||
<br>
|
||||
<%= submit_tag "Move", :class=>"btn btn-success"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -52,6 +52,7 @@ Wrestling::Application.routes.draw do
|
||||
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
|
||||
|
||||
post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight
|
||||
post "/wrestlers/update_pool" => "wrestlers#update_pool"
|
||||
|
||||
#API
|
||||
get "/api/tournaments" => "api#tournaments"
|
||||
|
||||
Reference in New Issue
Block a user