mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-04 13:43:48 +00:00
Moving pages to tournament from static_pages
This commit is contained in:
@@ -1,31 +1,7 @@
|
|||||||
class StaticPagesController < ApplicationController
|
class StaticPagesController < ApplicationController
|
||||||
before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in]
|
before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in]
|
||||||
|
|
||||||
def tournaments
|
|
||||||
@tournaments = Tournament.all.includes(:user,:matches,:mats)
|
|
||||||
end
|
|
||||||
def up_matches
|
|
||||||
if params[:tournament]
|
|
||||||
@tournament = Tournament.where(:id => params[:tournament]).includes(:matches,:mats).first
|
|
||||||
end
|
|
||||||
if @tournament
|
|
||||||
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
|
|
||||||
@mats = @tournament.mats.includes(:matches)
|
|
||||||
if @tournament.matches.empty?
|
|
||||||
redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def team_scores
|
|
||||||
if params[:tournament]
|
|
||||||
@tournament = Tournament.find(params[:tournament])
|
|
||||||
end
|
|
||||||
if @tournament
|
|
||||||
@schools = School.where(tournament_id: @tournament.id)
|
|
||||||
@schools.sort_by{|x|[x.score]}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def results
|
def results
|
||||||
if params[:tournament]
|
if params[:tournament]
|
||||||
@@ -58,15 +34,6 @@ class StaticPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def weights
|
|
||||||
if params[:tournament]
|
|
||||||
@tournament = Tournament.find(params[:tournament])
|
|
||||||
end
|
|
||||||
if @tournament
|
|
||||||
@weights = Weight.where(tournament_id: @tournament.id)
|
|
||||||
@weights = @weights.sort_by{|x|[x.max]}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def createCustomWeights
|
def createCustomWeights
|
||||||
@tournament = Tournament.find(params[:tournament])
|
@tournament = Tournament.find(params[:tournament])
|
||||||
@@ -77,20 +44,6 @@ class StaticPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def noMatches
|
|
||||||
if params[:tournament]
|
|
||||||
@tournament = Tournament.find(params[:tournament])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_matches
|
|
||||||
if params[:tournament]
|
|
||||||
@tournament = Tournament.find(params[:tournament])
|
|
||||||
end
|
|
||||||
if @tournament
|
|
||||||
@tournament.generateMatchups
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def weigh_in
|
def weigh_in
|
||||||
if params[:wrestler]
|
if params[:wrestler]
|
||||||
|
|||||||
@@ -1,32 +1,51 @@
|
|||||||
class TournamentsController < ApplicationController
|
class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: [:show, :edit, :update, :destroy]
|
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]
|
before_filter :check_access, only: [:update,:edit,:destroy,:generate_matches]
|
||||||
|
before_filter :check_for_matches, only: [:up_matches]
|
||||||
|
|
||||||
|
|
||||||
# GET /tournaments
|
def generate_matches
|
||||||
# GET /tournaments.json
|
@tournament.generateMatchups
|
||||||
def index
|
end
|
||||||
@tournaments = Tournament.all
|
|
||||||
|
def weights
|
||||||
|
@weights = @tournament.weights
|
||||||
|
@weights.sort_by{|w| w.max}
|
||||||
|
end
|
||||||
|
|
||||||
|
def team_scores
|
||||||
|
@schools = @tournament.schools
|
||||||
|
@schools.sort_by{|s| s.score}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def no_matches
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def up_matches
|
||||||
|
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
|
||||||
|
@mats = @tournament.mats.includes(:matches)
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@tournaments = Tournament.all.limit(50).includes(:schools,:weights,:mats,:matches,:user,:wrestlers)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /tournaments/1
|
|
||||||
# GET /tournaments/1.json
|
|
||||||
def show
|
def show
|
||||||
@schools = @tournament.schools
|
@schools = @tournament.schools
|
||||||
@weights = @tournament.weights.sort_by{|x|[x.max]}
|
@weights = @tournament.weights.sort_by{|x|[x.max]}
|
||||||
@mats = @tournament.mats
|
@mats = @tournament.mats
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /tournaments/new
|
|
||||||
def new
|
def new
|
||||||
@tournament = Tournament.new
|
@tournament = Tournament.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /tournaments/1/edit
|
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /tournaments
|
|
||||||
# POST /tournaments.json
|
|
||||||
def create
|
def create
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
else
|
else
|
||||||
@@ -44,8 +63,6 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH/PUT /tournaments/1
|
|
||||||
# PATCH/PUT /tournaments/1.json
|
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @tournament.update(tournament_params)
|
if @tournament.update(tournament_params)
|
||||||
@@ -58,8 +75,6 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /tournaments/1
|
|
||||||
# DELETE /tournaments/1.json
|
|
||||||
def destroy
|
def destroy
|
||||||
@tournament.destroy
|
@tournament.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@@ -71,16 +86,26 @@ class TournamentsController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_tournament
|
def set_tournament
|
||||||
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats).first
|
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def tournament_params
|
def tournament_params
|
||||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id)
|
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Check for tournament owner
|
||||||
def check_access
|
def check_access
|
||||||
if current_user != @tournament.user
|
if current_user != @tournament.user
|
||||||
redirect_to root_path
|
redirect_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_for_matches
|
||||||
|
if @tournament
|
||||||
|
if @tournament.matches.empty?
|
||||||
|
redirect_to "/tournaments/#{@tournament.id}/no_matches"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
</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" , "/static_pages/weights?tournament=#{@tournament.id}" %></li>
|
<li><%= link_to "Brackets" , "/tournaments/#{@tournament.id}/weights" %></li>
|
||||||
<li><%= link_to "Upcoming Matches" , "/static_pages/up_matches?tournament=#{@tournament.id}" %></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" , "/static_pages/results?tournament=#{@tournament.id}" %></li>
|
||||||
<li><%= link_to "Team Scores" , "/static_pages/team_scores?tournament=#{@tournament.id}" %></li>
|
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
|
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<%= link_to "Back to #{@tournament.name} weights", "/static_pages/weights?tournament=#{@tournament.id}" %>
|
<%= link_to "Back to #{@tournament.name} weights", "/tournaments/#{@tournament.id}/weights" %>
|
||||||
<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>
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
<br>
|
<br>
|
||||||
<p>If you would like to run a tournament, please click log in and then click sign up.</p>
|
<p>If you would like to run a tournament, please click log in and then click sign up.</p>
|
||||||
<br>
|
<br>
|
||||||
<%= link_to "Browse Tournaments", '/static_pages/tournaments', class: "btn btn-large btn-primary" %>
|
<%= link_to "Browse Tournaments", '/tournaments', class: "btn btn-large btn-primary" %>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
<h1>Listing tournaments</h1>
|
<h1>Pick A Tournament</h1>
|
||||||
|
<script>
|
||||||
<table>
|
$(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>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Address</th>
|
|
||||||
<th>Director</th>
|
|
||||||
<th>Director email</th>
|
|
||||||
<th></th>
|
|
||||||
<th></th>
|
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -17,12 +22,12 @@
|
|||||||
<% @tournaments.each do |tournament| %>
|
<% @tournaments.each do |tournament| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= tournament.name %></td>
|
<td><%= tournament.name %></td>
|
||||||
<td><%= tournament.address %></td>
|
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
|
||||||
<td><%= tournament.director %></td>
|
<% if tournament_permissions(tournament) %>
|
||||||
<td><%= tournament.director_email %></td>
|
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
|
||||||
<td><%= link_to 'Show', tournament %></td>
|
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
||||||
<td><%= link_to 'Edit', edit_tournament_path(tournament) %></td>
|
<% end %>
|
||||||
<td><%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -30,4 +35,4 @@
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<%= link_to 'New Tournament', new_tournament_path %>
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<% if tournament_permissions(@tournament) %>
|
<% if tournament_permissions(@tournament) %>
|
||||||
<%= link_to "Edit #{@tournament.name}", edit_tournament_path(@tournament), :class=>"btn btn-primary" %> |
|
<%= link_to "Edit #{@tournament.name}", edit_tournament_path(@tournament), :class=>"btn btn-primary" %> |
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to 'Back', '/static_pages/tournaments', :class=>"btn btn-default" %>
|
<%= link_to 'Back', '/tournaments', :class=>"btn btn-default" %>
|
||||||
|
|
||||||
<h1>
|
<h1>
|
||||||
<%= @tournament.name %>
|
<%= @tournament.name %>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<br>
|
<br>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if tournament_permissions(@tournament) %>
|
||||||
<%= link_to "Generate Pool Matches" , "/static_pages/generate_matches?tournament=#{@tournament.id}", 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" , "/static_pages/weigh_in?tournament=#{@tournament.id}", :class=>"btn btn-primary" %>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -22,22 +22,23 @@ 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/tournaments'
|
|
||||||
get 'static_pages/brackets'
|
get 'static_pages/brackets'
|
||||||
get 'static_pages/all_brackets'
|
get 'static_pages/all_brackets'
|
||||||
get 'static_pages/weights'
|
|
||||||
get 'admin/index'
|
get 'admin/index'
|
||||||
get 'static_pages/up_matches'
|
|
||||||
get 'static_pages/control_match'
|
get 'static_pages/control_match'
|
||||||
get 'static_pages/results'
|
get 'static_pages/results'
|
||||||
get 'static_pages/team_scores'
|
|
||||||
get 'static_pages/noMatches'
|
|
||||||
get 'static_pages/createCustomWeights'
|
get 'static_pages/createCustomWeights'
|
||||||
get 'static_pages/generate_matches'
|
|
||||||
get 'static_pages/weigh_in'
|
get 'static_pages/weigh_in'
|
||||||
post 'static_pages/weigh_in'
|
post 'static_pages/weigh_in'
|
||||||
get 'static_pages/not_allowed'
|
get 'static_pages/not_allowed'
|
||||||
|
|
||||||
|
|
||||||
|
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/up_matches' => 'tournaments#up_matches'
|
||||||
|
get 'tournaments/:id/no_matches' => 'tournaments#no_matches'
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ class StaticPagesControllerTest < ActionController::TestCase
|
|||||||
@school = @tournament.schools.first
|
@school = @tournament.schools.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
|
||||||
get :new, tournament: @tournament.id
|
|
||||||
end
|
|
||||||
|
|
||||||
def sign_in_owner
|
def sign_in_owner
|
||||||
sign_in users(:one)
|
sign_in users(:one)
|
||||||
end
|
end
|
||||||
@@ -29,17 +25,6 @@ class StaticPagesControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to '/static_pages/not_allowed'
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
end
|
end
|
||||||
|
|
||||||
test "logged in tournament owner can generate matches" do
|
|
||||||
sign_in_owner
|
|
||||||
get :generate_matches, tournament: 1
|
|
||||||
success
|
|
||||||
end
|
|
||||||
|
|
||||||
test "logged in non tournament owner cannot generate matches" do
|
|
||||||
sign_in_non_owner
|
|
||||||
get :generate_matches, tournament: 1
|
|
||||||
redirect
|
|
||||||
end
|
|
||||||
|
|
||||||
test "logged in tournament owner can access weigh_ins" do
|
test "logged in tournament owner can access weigh_ins" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
|
|||||||
@@ -1,11 +1,39 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TournamentsControllerTest < ActionController::TestCase
|
class TournamentsControllerTest < ActionController::TestCase
|
||||||
# setup do
|
include Devise::TestHelpers
|
||||||
# @tournament = tournaments(:one)
|
|
||||||
# end
|
setup do
|
||||||
|
@tournament = Tournament.find(1)
|
||||||
|
@tournament.generateMatchups
|
||||||
|
@school = @tournament.schools.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_in_owner
|
||||||
|
sign_in users(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_in_non_owner
|
||||||
|
sign_in users(:two)
|
||||||
|
end
|
||||||
|
|
||||||
|
def success
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirect
|
||||||
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
|
test "logged in tournament owner can generate matches" do
|
||||||
|
sign_in_owner
|
||||||
|
get :generate_matches, id: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in non tournament owner cannot generate matches" do
|
||||||
|
sign_in_non_owner
|
||||||
|
get :generate_matches, id: 1
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
test "the truth" do
|
|
||||||
assert true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user