diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index b4edeca..1adf228 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,77 +1,8 @@ class StaticPagesController < ApplicationController - before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in] + before_filter :check_access, only: [:weigh_in] - def results - if params[:tournament] - @tournament = Tournament.find(params[:tournament]) - end - if @tournament - @matches = @tournament.matches - end - @matches = @matches.where(finished: 1) - end - - def brackets - if params[:weight] - @weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers,:tournament).first - @tournament = @weight.tournament - @matches = @weight.matches - @wrestlers = @weight.wrestlers.includes(:school) - if @matches.empty? or @wrestlers.empty? - redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}" - else - @pools = @weight.poolRounds(@matches) - @bracketType = @weight.pool_bracket_type - end - end - end - - def all_brackets - if params[:tournament] - @tournament = Tournament.find(params[:tournament]) - end - end - - - def createCustomWeights - @tournament = Tournament.find(params[:tournament]) - @custom = params[:customValue].to_s - @tournament.createCustomWeights(@custom) - - redirect_to "/tournaments/#{@tournament.id}" - end - - - - def weigh_in - if params[:wrestler] - Wrestler.update(params[:wrestler].keys, params[:wrestler].values) - end - if params[:tournament] - @tournament = Tournament.where(:id => params[:tournament]).includes(:weights).first - @tournament_id = @tournament.id - @tournament_name = @tournament.name - end - if @tournament - @weights = @tournament.weights - @weights = @weights.sort_by{|x|[x.max]} - end - if params[:weight] - @weight = Weight.where(:id => params[:weight]).includes(:tournament,:wrestlers).first - @tournament_id = @weight.tournament.id - @tournament_name = @weight.tournament.name - @tournament = @weight.tournament - @weights = @tournament.weights - end - if @weight - @wrestlers = @weight.wrestlers - - end - end - - def not_allowed end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 5eb8b1c..490b8a1 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,14 +1,60 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy,:up_matches,:no_matches,:team_scores,:weights,:generate_matches] - before_filter :check_access, only: [:update,:edit,:destroy,:generate_matches] - before_filter :check_for_matches, only: [:up_matches] + before_action :set_tournament, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:results,:all_brackets] + before_filter :check_access, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:destroy,:generate_matches] + before_filter :check_for_matches, only: [:up_matches,:bracket] + def weigh_in_weight + if params[:wrestler] + Wrestler.update(params[:wrestler].keys, params[:wrestler].values) + end + if params[:weight] + @weight = Weight.where(:id => params[:weight]).includes(:wrestlers).first + @tournament_id = @tournament.id + @tournament_name = @tournament.name + @weights = @tournament.weights + end + if @weight + @wrestlers = @weight.wrestlers + end + end + + def weigh_in + if @tournament + @weights = @tournament.weights + @weights = @weights.sort_by{|x|[x.max]} + end + end + + def create_custom_weights + @custom = params[:customValue].to_s + @tournament.createCustomWeights(@custom) + redirect_to "/tournaments/#{@tournament.id}" + end + + + def all_brackets + + end + + def results + @matches = @tournament.matches + end + + def bracket + if params[:weight] + @weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first + @matches = @weight.matches + @wrestlers = @weight.wrestlers.includes(:school) + @pools = @weight.poolRounds(@matches) + @bracketType = @weight.pool_bracket_type + end + end def generate_matches @tournament.generateMatchups end - def weights + def brackets @weights = @tournament.weights @weights.sort_by{|w| w.max} end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 58fa920..514f72c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -5,9 +5,9 @@