mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Moving pages to tournament from static_pages
This commit is contained in:
@@ -1,31 +1,7 @@
|
||||
class StaticPagesController < ApplicationController
|
||||
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
|
||||
if params[:tournament]
|
||||
@@ -58,15 +34,6 @@ class StaticPagesController < ApplicationController
|
||||
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
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
@@ -77,20 +44,6 @@ class StaticPagesController < ApplicationController
|
||||
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
|
||||
if params[:wrestler]
|
||||
|
||||
@@ -1,32 +1,51 @@
|
||||
class TournamentsController < ApplicationController
|
||||
before_action :set_tournament, only: [:show, :edit, :update, :destroy]
|
||||
before_filter :check_access, only: [:update,:edit,: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,:generate_matches]
|
||||
before_filter :check_for_matches, only: [:up_matches]
|
||||
|
||||
|
||||
# GET /tournaments
|
||||
# GET /tournaments.json
|
||||
def index
|
||||
@tournaments = Tournament.all
|
||||
def generate_matches
|
||||
@tournament.generateMatchups
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
# GET /tournaments/1
|
||||
# GET /tournaments/1.json
|
||||
def show
|
||||
@schools = @tournament.schools
|
||||
@weights = @tournament.weights.sort_by{|x|[x.max]}
|
||||
@mats = @tournament.mats
|
||||
end
|
||||
|
||||
# GET /tournaments/new
|
||||
def new
|
||||
@tournament = Tournament.new
|
||||
end
|
||||
|
||||
# GET /tournaments/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /tournaments
|
||||
# POST /tournaments.json
|
||||
def create
|
||||
if user_signed_in?
|
||||
else
|
||||
@@ -44,8 +63,6 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /tournaments/1
|
||||
# PATCH/PUT /tournaments/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @tournament.update(tournament_params)
|
||||
@@ -58,8 +75,6 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /tournaments/1
|
||||
# DELETE /tournaments/1.json
|
||||
def destroy
|
||||
@tournament.destroy
|
||||
respond_to do |format|
|
||||
@@ -71,16 +86,26 @@ class TournamentsController < ApplicationController
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
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
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def tournament_params
|
||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id)
|
||||
end
|
||||
|
||||
#Check for tournament owner
|
||||
def check_access
|
||||
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
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
</div>
|
||||
<ul class="nav navbar-nav navbar-right navbar-custom-link">
|
||||
<% if @tournament %>
|
||||
<li><%= link_to "Brackets" , "/static_pages/weights?tournament=#{@tournament.id}" %></li>
|
||||
<li><%= link_to "Upcoming Matches" , "/static_pages/up_matches?tournament=#{@tournament.id}" %></li>
|
||||
<li><%= link_to "Brackets" , "/tournaments/#{@tournament.id}/weights" %></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 "Team Scores" , "/static_pages/team_scores?tournament=#{@tournament.id}" %></li>
|
||||
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
|
||||
<% end %>
|
||||
<% if user_signed_in? %>
|
||||
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
}
|
||||
</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>
|
||||
<button type="submit" class="btn btn-primary" onclick="exportDataToRtf()">Export to file for printing</button>
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
<br>
|
||||
<p>If you would like to run a tournament, please click log in and then click sign up.</p>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<h1>Listing tournaments</h1>
|
||||
|
||||
<table>
|
||||
<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>Address</th>
|
||||
<th>Director</th>
|
||||
<th>Director email</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -17,12 +22,12 @@
|
||||
<% @tournaments.each do |tournament| %>
|
||||
<tr>
|
||||
<td><%= tournament.name %></td>
|
||||
<td><%= tournament.address %></td>
|
||||
<td><%= tournament.director %></td>
|
||||
<td><%= tournament.director_email %></td>
|
||||
<td><%= link_to 'Show', tournament %></td>
|
||||
<td><%= link_to 'Edit', edit_tournament_path(tournament) %></td>
|
||||
<td><%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' } %></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>
|
||||
@@ -30,4 +35,4 @@
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Tournament', new_tournament_path %>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<% if tournament_permissions(@tournament) %>
|
||||
<%= link_to "Edit #{@tournament.name}", edit_tournament_path(@tournament), :class=>"btn btn-primary" %> |
|
||||
<% end %>
|
||||
<%= link_to 'Back', '/static_pages/tournaments', :class=>"btn btn-default" %>
|
||||
<%= link_to 'Back', '/tournaments', :class=>"btn btn-default" %>
|
||||
|
||||
<h1>
|
||||
<%= @tournament.name %>
|
||||
@@ -31,7 +31,7 @@
|
||||
</p>
|
||||
<br>
|
||||
<% 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>
|
||||
<%= link_to "Weigh In Page" , "/static_pages/weigh_in?tournament=#{@tournament.id}", :class=>"btn btn-primary" %>
|
||||
<br>
|
||||
|
||||
@@ -22,22 +22,23 @@ Wrestling::Application.routes.draw do
|
||||
|
||||
# You can have the root of your site routed with "root"
|
||||
root 'static_pages#home'
|
||||
get 'static_pages/tournaments'
|
||||
get 'static_pages/brackets'
|
||||
get 'static_pages/all_brackets'
|
||||
get 'static_pages/weights'
|
||||
get 'admin/index'
|
||||
get 'static_pages/up_matches'
|
||||
get 'static_pages/control_match'
|
||||
get 'static_pages/results'
|
||||
get 'static_pages/team_scores'
|
||||
get 'static_pages/noMatches'
|
||||
get 'static_pages/createCustomWeights'
|
||||
get 'static_pages/generate_matches'
|
||||
get 'static_pages/weigh_in'
|
||||
post 'static_pages/weigh_in'
|
||||
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:
|
||||
# get 'products/:id' => 'catalog#view'
|
||||
|
||||
|
||||
@@ -9,10 +9,6 @@ class StaticPagesControllerTest < ActionController::TestCase
|
||||
@school = @tournament.schools.first
|
||||
end
|
||||
|
||||
def new
|
||||
get :new, tournament: @tournament.id
|
||||
end
|
||||
|
||||
def sign_in_owner
|
||||
sign_in users(:one)
|
||||
end
|
||||
@@ -29,17 +25,6 @@ class StaticPagesControllerTest < ActionController::TestCase
|
||||
assert_redirected_to '/static_pages/not_allowed'
|
||||
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
|
||||
sign_in_owner
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TournamentsControllerTest < ActionController::TestCase
|
||||
# setup do
|
||||
# @tournament = tournaments(:one)
|
||||
# end
|
||||
include Devise::TestHelpers
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user