From 4fae1c28962ee95e19e8d57fa68b3c9b4d0aacd9 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 5 Nov 2015 02:38:39 +0000 Subject: [PATCH] Moved static pages actions to tournament where it made sense --- app/controllers/static_pages_controller.rb | 71 +----------- app/controllers/tournaments_controller.rb | 54 ++++++++- app/views/layouts/_header.html.erb | 4 +- app/views/static_pages/results.html.erb | 105 ----------------- app/views/static_pages/tournaments.html.erb | 38 ------- .../_fourPoolQuarterBracket.html.erb | 0 .../_fourPoolSemiBracket.html.erb | 0 .../_pool.html.erb | 0 .../_twoPoolFinalBracket.html.erb | 0 .../_twoPoolSemiBracket.html.erb | 0 .../all_brackets.html.erb | 2 +- .../bracket.html.erb} | 0 app/views/tournaments/brackets.html.erb | 8 ++ app/views/tournaments/results.html.erb | 5 + app/views/tournaments/show.html.erb | 4 +- app/views/tournaments/weigh_in.html.erb | 20 ++++ .../weigh_in_weight.html.erb} | 106 +++++++----------- app/views/tournaments/weights.html.erb | 8 -- config/routes.rb | 16 +-- .../static_pages_controller_test.rb | 23 ---- .../tournaments_controller_test.rb | 100 +++++++++++++++++ 21 files changed, 240 insertions(+), 324 deletions(-) delete mode 100644 app/views/static_pages/results.html.erb delete mode 100644 app/views/static_pages/tournaments.html.erb rename app/views/{static_pages => tournaments}/_fourPoolQuarterBracket.html.erb (100%) rename app/views/{static_pages => tournaments}/_fourPoolSemiBracket.html.erb (100%) rename app/views/{static_pages => tournaments}/_pool.html.erb (100%) rename app/views/{static_pages => tournaments}/_twoPoolFinalBracket.html.erb (100%) rename app/views/{static_pages => tournaments}/_twoPoolSemiBracket.html.erb (100%) rename app/views/{static_pages => tournaments}/all_brackets.html.erb (98%) rename app/views/{static_pages/brackets.html.erb => tournaments/bracket.html.erb} (100%) create mode 100644 app/views/tournaments/brackets.html.erb create mode 100644 app/views/tournaments/results.html.erb create mode 100644 app/views/tournaments/weigh_in.html.erb rename app/views/{static_pages/weigh_in.html.erb => tournaments/weigh_in_weight.html.erb} (67%) delete mode 100644 app/views/tournaments/weights.html.erb 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 @@