1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Moved static pages actions to tournament where it made sense

This commit is contained in:
2015-11-05 02:38:39 +00:00
parent f86a577c8b
commit 4fae1c2896
21 changed files with 240 additions and 324 deletions

View File

@@ -1,77 +1,8 @@
class StaticPagesController < ApplicationController 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 def not_allowed
end end

View File

@@ -1,14 +1,60 @@
class TournamentsController < ApplicationController class TournamentsController < ApplicationController
before_action :set_tournament, only: [:show, :edit, :update, :destroy,:up_matches,:no_matches,:team_scores,:weights,:generate_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: [:update,:edit,:destroy,:generate_matches] 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] 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 def generate_matches
@tournament.generateMatchups @tournament.generateMatchups
end end
def weights def brackets
@weights = @tournament.weights @weights = @tournament.weights
@weights.sort_by{|w| w.max} @weights.sort_by{|w| w.max}
end end

View File

@@ -5,9 +5,9 @@
</div> </div>
<ul class="nav navbar-nav navbar-right navbar-custom-link"> <ul class="nav navbar-nav navbar-right navbar-custom-link">
<% if @tournament %> <% if @tournament %>
<li><%= link_to "Brackets" , "/tournaments/#{@tournament.id}/weights" %></li> <li><%= link_to "Brackets" , "/tournaments/#{@tournament.id}/brackets" %></li>
<li><%= link_to "Upcoming Matches" , "/tournaments/#{@tournament.id}/up_matches" %></li> <li><%= link_to "Upcoming Matches" , "/tournaments/#{@tournament.id}/up_matches" %></li>
<li><%= link_to "Results" , "/static_pages/results?tournament=#{@tournament.id}" %></li> <li><%= link_to "Results" , "/tournaments/#{@tournament.id}/results" %></li>
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li> <li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
<% end %> <% end %>
<% if user_signed_in? %> <% if user_signed_in? %>

View File

@@ -1,105 +0,0 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<br>
<br>
<h3>Round 1</h3>
<% @matches.each do |m| %>
<% if m.round == 1 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>
<h3>Round 2</h3>
<% @matches.each do |m| %>
<% if m.round == 2 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>
<h3>Round 3</h3>
<% @matches.each do |m| %>
<% if m.round == 3 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>
<h3>Round 4</h3>
<% @matches.each do |m| %>
<% if m.round == 4 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>
<h3>Round 5</h3>
<% @matches.each do |m| %>
<% if m.round == 5 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>
<h3>Round 6</h3>
<% @matches.each do |m| %>
<% if m.round == 6 %>
<% if Wrestler.find(m.g_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.g_id) %>
<% else %>
<% @loser = Wrestler.find(m.g_id) %>
<% end %>
<% if Wrestler.find(m.r_id).id == m.winner_id %>
<% @winner = Wrestler.find(m.r_id) %>
<% else %>
<% @loser = Wrestler.find(m.r_id) %>
<% end %>
<%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %>
<br>
<% end %>
<% end %>

View File

@@ -1,38 +0,0 @@
<h1>Pick A Tournament</h1>
<script>
$(document).ready(function() {
$('#tournamentList').dataTable();
pagingType: "bootstrap";
} );
</script>
<% if user_signed_in? %>
<%= link_to 'New Tournament', new_tournament_path, :class=>"btn btn-success" %>
<% end %>
</br>
</br>
<table class="display compact cell-border" id="tournamentList">
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<% @tournaments.each do |tournament| %>
<tr>
<td><%= tournament.name %></td>
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
<% if tournament_permissions(tournament) %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<br>

View File

@@ -13,7 +13,7 @@
} }
</script> </script>
<%= link_to "Back to #{@tournament.name} weights", "/tournaments/#{@tournament.id}/weights" %> <%= link_to "Back to #{@tournament.name} weights", "/tournaments/#{@tournament.id}/brackets" %>
<br> <br>
<br> <br>
<button type="submit" class="btn btn-primary" onclick="exportDataToRtf()">Export to file for printing</button> <button type="submit" class="btn btn-primary" onclick="exportDataToRtf()">Export to file for printing</button>

View File

@@ -0,0 +1,8 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<br>
<br>
<% @weights.each do |weight| %>
<%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/brackets/#{weight.id}" %>
<br>
<% end %>
<%= link_to "All Brackets", "/tournaments/#{@tournament.id}/all_brackets?print=true" %>

View File

@@ -0,0 +1,5 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<br>
<br>
<h3>Results</h3>
<p>Will be displayed here.</p>

View File

@@ -33,7 +33,7 @@
<% if tournament_permissions(@tournament) %> <% if tournament_permissions(@tournament) %>
<%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' }, :class=>"btn btn-success" %> <%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' }, :class=>"btn btn-success" %>
<br><br> <br><br>
<%= link_to "Weigh In Page" , "/static_pages/weigh_in?tournament=#{@tournament.id}", :class=>"btn btn-primary" %> <%= link_to "Weigh In Page" , "/tournaments/#{@tournament.id}/weigh_in", :class=>"btn btn-primary" %>
<br> <br>
<br> <br>
<% end %> <% end %>
@@ -77,7 +77,7 @@
<% if tournament_permissions(@tournament) %> <% if tournament_permissions(@tournament) %>
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %> <%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
<br><br> <br><br>
<%= link_to "Create HS Weights" , "/static_pages/createCustomWeights?tournament=#{@tournament.id}&customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' }, :class=>"btn btn-success" %> <%= link_to "Create HS Weights" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' }, :class=>"btn btn-success" %>
<br> <br>
<br> <br>
<% end %> <% end %>

View File

@@ -0,0 +1,20 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
<br>
<br>
<% @weights.each do |weight| %>
<%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/weigh_in/#{weight.id}" %>
<br>
<% end %>
<br>
<% if tournament_permissions(@tournament) %>
<%= form_for(@tournament) do |f| %>
<div class="field">
<%= f.label :weigh_in_ref %><br>
<%= f.text_field :weigh_in_ref %>
</div>
<br>
<%= f.submit 'Submit', :class=>"btn btn-success" %>
<% end %>
<% end %>

View File

@@ -1,63 +1,43 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %> <%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
<br> <br>
<br> <br>
<% if params[:tournament] %> <%= link_to "Back to weigh ins","/tournaments/#{@tournament_id}/weigh_in", :class=>"btn btn-default" %>
<% @weights.each do |weight| %> <br><br>
<%= link_to "#{weight.max}" , "/static_pages/weigh_in?weight=#{weight.id}" %> <table class="table table-striped table-bordered">
<br> <thead>
<% end %> <tr>
<br> <th>Name</th>
<% if tournament_permissions(@tournament) %> <th>School</th>
<%= form_for(@tournament) do |f| %> <th>Seed</th>
<div class="field"> <th>Weight Class</th>
<%= f.label :weigh_in_ref %><br> <th>Offical Weight</th>
<%= f.text_field :weigh_in_ref %> </tr>
</div> </thead>
<br> <tbody>
<%= f.submit 'Submit', :class=>"btn btn-success" %> <%= form_tag @wrestlers_update_path do %>
<% end %> <% @wrestlers.order("original_seed asc").each do |wrestler| %>
<% end %> <% if wrestler.weight_id == @weight.id %>
<% end %> <tr>
<td><%= wrestler.name %></td>
<% if @weight %> <td><%= School.find(wrestler.school_id).name %></td>
<%= link_to "Back to weigh in weights","/static_pages/weigh_in?tournament=#{@tournament_id}", :class=>"btn btn-default" %> <td><%= wrestler.original_seed %></td>
<br><br> <td><%= wrestler.weight.max %></td>
<table class="table table-striped table-bordered"> <td>
<thead> <% if user_signed_in? %>
<tr> <%= fields_for "wrestler[]", wrestler do |w| %>
<th>Name</th> <%= w.number_field :offical_weight, :step => 'any' %>
<th>School</th> <% end %>
<th>Seed</th> <% else %>
<th>Weight Class</th> <%= wrestler.offical_weight %>
<th>Offical Weight</th> <% end %>
</tr> </td>
</thead> </tr>
<tbody> <% end %>
<%= form_tag @wrestlers_update_path do %> <% end %>
<% @wrestlers.order("original_seed asc").each do |wrestler| %> </tbody>
<% if wrestler.weight_id == @weight.id %> </table>
<tr> <%= hidden_field_tag :tournament, @tournament_id %>
<td><%= wrestler.name %></td> <% if tournament_permissions(@tournament) %>
<td><%= School.find(wrestler.school_id).name %></td> <%= submit_tag "Save", :class=>"btn btn-success"%>
<td><%= wrestler.original_seed %></td> <% end %>
<td><%= wrestler.weight.max %></td> <% end %>
<td>
<% if user_signed_in? %>
<%= fields_for "wrestler[]", wrestler do |w| %>
<%= w.number_field :offical_weight, :step => 'any' %>
<% end %>
<% else %>
<%= wrestler.offical_weight %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<%= hidden_field_tag :tournament, @tournament_id %>
<% if tournament_permissions(@tournament) %>
<%= submit_tag "Save", :class=>"btn btn-success"%>
<% end %>
<% end %>
<% end %>

View File

@@ -1,8 +0,0 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<br>
<br>
<% @weights.each do |weight| %>
<%= link_to "#{weight.max}" , "/static_pages/brackets?weight=#{weight.id}" %>
<br>
<% end %>
<%= link_to "All Brackets", "/static_pages/all_brackets?print=true&tournament=#{@tournament.id}" %>

View File

@@ -22,19 +22,19 @@ Wrestling::Application.routes.draw do
# You can have the root of your site routed with "root" # You can have the root of your site routed with "root"
root 'static_pages#home' root 'static_pages#home'
get 'static_pages/brackets'
get 'static_pages/all_brackets'
get 'admin/index' get 'admin/index'
get 'static_pages/control_match' get 'static_pages/control_match'
get 'static_pages/results'
get 'static_pages/createCustomWeights'
get 'static_pages/weigh_in'
post 'static_pages/weigh_in'
get 'static_pages/not_allowed' get 'static_pages/not_allowed'
get 'tournaments/:id/weigh_in/:weight' => 'tournaments#weigh_in_weight'
post 'tournaments/:id/weigh_in/:weight' => 'tournaments#weigh_in_weight'
get 'tournaments/:id/weigh_in' => 'tournaments#weigh_in'
get 'tournaments/:id/create_custom_weights' => 'tournaments#create_custom_weights'
get 'tournaments/:id/all_brackets' => 'tournaments#all_brackets'
get 'tournaments/:id/results' => 'tournaments#results'
get 'tournaments/:id/brackets' => 'tournaments#brackets'
get 'tournaments/:id/brackets/:weight' => 'tournaments#bracket'
get 'tournaments/:id/generate_matches' => 'tournaments#generate_matches' get 'tournaments/:id/generate_matches' => 'tournaments#generate_matches'
get 'tournaments/:id/weights' => 'tournaments#weights'
get 'tournaments/:id/team_scores' => 'tournaments#team_scores' get 'tournaments/:id/team_scores' => 'tournaments#team_scores'
get 'tournaments/:id/up_matches' => 'tournaments#up_matches' get 'tournaments/:id/up_matches' => 'tournaments#up_matches'
get 'tournaments/:id/no_matches' => 'tournaments#no_matches' get 'tournaments/:id/no_matches' => 'tournaments#no_matches'

View File

@@ -26,28 +26,5 @@ class StaticPagesControllerTest < ActionController::TestCase
end end
test "logged in tournament owner can access weigh_ins" do
sign_in_owner
get :weigh_in, tournament: 1
success
end
test "logged in non tournament owner cannot access weigh_ins" do
sign_in_non_owner
get :weigh_in, tournament: 1
redirect
end
test "logged in tournament owner can create custom weights" do
sign_in_owner
get :createCustomWeights, tournament: 1, customValue: 'hs'
assert_redirected_to '/tournaments/1'
end
test "logged in non tournament owner cannot create custom weights" do
sign_in_non_owner
get :createCustomWeights, tournament: 1, customValue: 'hs'
redirect
end
end end

View File

@@ -9,6 +9,14 @@ include Devise::TestHelpers
@school = @tournament.schools.first @school = @tournament.schools.first
end end
def post_update
patch :update, id: 1, tournament: {name: @tournament.name}
end
def get_edit
get :edit, id: 1
end
def sign_in_owner def sign_in_owner
sign_in users(:one) sign_in users(:one)
end end
@@ -24,6 +32,12 @@ include Devise::TestHelpers
def redirect def redirect
assert_redirected_to '/static_pages/not_allowed' assert_redirected_to '/static_pages/not_allowed'
end end
def destroy
delete :destroy, id: 1
end
test "logged in tournament owner can generate matches" do test "logged in tournament owner can generate matches" do
sign_in_owner sign_in_owner
get :generate_matches, id: 1 get :generate_matches, id: 1
@@ -36,4 +50,90 @@ include Devise::TestHelpers
redirect redirect
end end
test "logged in tournament owner can create custom weights" do
sign_in_owner
get :create_custom_weights, id: 1, customValue: 'hs'
assert_redirected_to '/tournaments/1'
end
test "logged in non tournament owner cannot create custom weights" do
sign_in_non_owner
get :create_custom_weights, id: 1, customValue: 'hs'
redirect
end
test "logged in tournament owner can access weigh_ins" do
sign_in_owner
get :weigh_in, id: 1
success
end
test "logged in non tournament owner cannot access weigh_ins" do
sign_in_non_owner
get :weigh_in, id: 1
redirect
end
test "logged in tournament owner can access weigh_in_weight" do
sign_in_owner
get :weigh_in, id: 1, weight: 1
success
end
test "logged in non tournament owner cannot access weigh_in_weight" do
sign_in_non_owner
get :weigh_in_weight, id: 1, weight: 1
redirect
end
test "logged in tournament owner should get edit tournament page" do
sign_in_owner
get_edit
success
end
test "logged in user should not get edit tournament page if not owner" do
sign_in_non_owner
get_edit
redirect
end
test "non logged in user should not get edit tournament page" do
get_edit
redirect
end
test "non logged in user should get post update tournament" do
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in user should not post update tournament if not owner" do
sign_in_non_owner
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in tournament owner should post update tournament" do
sign_in_owner
post_update
assert_redirected_to tournament_path(1)
end
test "logged in tournament owner can destroy a tournament" do
sign_in_owner
destroy
assert_redirected_to tournaments_path
end
test "logged in user not tournament owner cannot destroy tournament" do
sign_in_non_owner
destroy
redirect
end
end end