1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

A ton of stuff was done to finalize the app for use

This commit is contained in:
Jacob Cody Wimer
2014-01-25 05:28:42 -05:00
parent 7f8718af35
commit c5a7bc3815
45 changed files with 889 additions and 22 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Mats controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -19,11 +19,26 @@ class MatchesController < ApplicationController
# GET /matches/1/edit
def edit
if user_signed_in?
else
redirect_to root_path
end
if params[:match]
@match = Match.find (params[:match])
end
if @match
@w1 = Wrestler.find(@match.r_id)
@w2 = Wrestler.find(@match.g_id)
end
end
# POST /matches
# POST /matches.json
def create
if user_signed_in?
else
redirect_to root_path
end
@match = Match.new(match_params)
respond_to do |format|
@@ -40,9 +55,13 @@ class MatchesController < ApplicationController
# PATCH/PUT /matches/1
# PATCH/PUT /matches/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
respond_to do |format|
if @match.update(match_params)
format.html { redirect_to @match, notice: 'Match was successfully updated.' }
format.html { redirect_to root_path, notice: 'Match was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
@@ -54,6 +73,10 @@ class MatchesController < ApplicationController
# DELETE /matches/1
# DELETE /matches/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@match.destroy
respond_to do |format|
format.html { redirect_to matches_url }
@@ -69,6 +92,6 @@ class MatchesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def match_params
params.require(:match).permit(:r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score)
params.require(:match).permit(:r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score, :finished)
end
end

View File

@@ -0,0 +1,93 @@
class MatsController < ApplicationController
before_action :set_mat, only: [:show, :edit, :update, :destroy]
# GET /mats
# GET /mats.json
def index
@mats = Mat.all
end
# GET /mats/1
# GET /mats/1.json
def show
end
# GET /mats/new
def new
@mat = Mat.new
if params[:tournament]
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
end
# GET /mats/1/edit
def edit
@tournament_field = @mat.tournament_id
end
# POST /mats
# POST /mats.json
def create
if user_signed_in?
else
redirect_to root_path
end
@mat = Mat.new(mat_params)
@tournament = Tournament.find(mat_params[:tournament_id])
respond_to do |format|
if @mat.save
format.html { redirect_to @tournament, notice: 'Mat was successfully created.' }
format.json { render action: 'show', status: :created, location: @mat }
else
format.html { render action: 'new' }
format.json { render json: @mat.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /mats/1
# PATCH/PUT /mats/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@mat.tournament_id)
respond_to do |format|
if @mat.update(mat_params)
format.html { redirect_to @tournament, notice: 'Mat was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @mat.errors, status: :unprocessable_entity }
end
end
end
# DELETE /mats/1
# DELETE /mats/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@mat.tournament_id)
@mat.destroy
respond_to do |format|
format.html { redirect_to @tournament }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_mat
@mat = Mat.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def mat_params
params.require(:mat).permit(:name, :tournament_id)
end
end

View File

@@ -31,6 +31,10 @@ class SchoolsController < ApplicationController
# POST /schools
# POST /schools.json
def create
if user_signed_in?
else
redirect_to root_path
end
@school = School.new(school_params)
@tournament = Tournament.find(school_params[:tournament_id])
respond_to do |format|
@@ -47,6 +51,10 @@ class SchoolsController < ApplicationController
# PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@school.tournament_id)
respond_to do |format|
if @school.update(school_params)
@@ -62,6 +70,10 @@ class SchoolsController < ApplicationController
# DELETE /schools/1
# DELETE /schools/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@school.tournament_id)
@school.destroy
respond_to do |format|

View File

@@ -3,7 +3,25 @@ class StaticPagesController < ApplicationController
def index
@tournaments = Tournament.all
end
def up_matches
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@matches = Weight.where(tournament_id: @tournament.id)
end
@matches = Match.where(finished: nil)
end
def results
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@matches = Weight.where(tournament_id: @tournament.id)
end
@matches = Match.where(finished: 1)
end
def brackets
if params[:weight]
@weight = Weight.find(params[:weight])
@@ -34,4 +52,225 @@ class StaticPagesController < ApplicationController
end
end
def generate_matches
if user_signed_in?
else
redirect_to root_path
end
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@matches_all = Match.where(tournament_id: @tournament.id)
@matches_all.each do |match|
match.destroy
end
@weights = Weight.where(tournament_id: @tournament.id)
#ROUND 1
@weights.order("id asc").each do |weight|
@seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first
@seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first
@seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first
@seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first
@seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first
@seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first
@seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first
@seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first
@seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first
@seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first
@bracket_size = Wrestler.where(weight_id: weight.id).count
def createMatch(r_id,g_id,tournament)
@match = Match.new
@match.r_id = r_id
@match.g_id = g_id
@match.tournament_id = tournament
@match.round = 1
@match.save
end
if @bracket_size == 10
createMatch(@seed1.id,@seed10.id,@tournament.id)
createMatch(@seed5.id,@seed7.id,@tournament.id)
createMatch(@seed2.id,@seed9.id,@tournament.id)
createMatch(@seed6.id,@seed8.id,@tournament.id)
elsif @bracket_size == 9
createMatch(@seed1.id,@seed9.id,@tournament.id)
createMatch(@seed5.id,@seed7.id,@tournament.id)
createMatch(@seed6.id,@seed8.id,@tournament.id)
elsif @bracket_size == 8
createMatch(@seed5.id,@seed7.id,@tournament.id)
createMatch(@seed6.id,@seed8.id,@tournament.id)
elsif @bracket_size == 7
createMatch(@seed5.id,@seed7.id,@tournament.id)
end
end
#ROUND 2
@weights.order("id asc").each do |weight|
@seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first
@seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first
@seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first
@seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first
@seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first
@seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first
@seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first
@seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first
@seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first
@seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first
@bracket_size = Wrestler.where(weight_id: weight.id).count
def createMatch(r_id,g_id,tournament)
@match = Match.new
@match.r_id = r_id
@match.g_id = g_id
@match.tournament_id = tournament
@match.round = 2
@match.save
end
if @bracket_size == 10
createMatch(@seed1.id,@seed5.id,@tournament.id)
createMatch(@seed10.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed6.id,@tournament.id)
createMatch(@seed9.id,@seed3.id,@tournament.id)
elsif @bracket_size == 9
createMatch(@seed1.id,@seed5.id,@tournament.id)
createMatch(@seed9.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed6.id,@tournament.id)
elsif @bracket_size == 8
createMatch(@seed1.id,@seed5.id,@tournament.id)
createMatch(@seed2.id,@seed6.id,@tournament.id)
elsif @bracket_size == 7
createMatch(@seed1.id,@seed5.id,@tournament.id)
createMatch(@seed2.id,@seed6.id,@tournament.id)
end
end
#ROUND 3
@weights.order("id asc").each do |weight|
@seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first
@seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first
@seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first
@seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first
@seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first
@seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first
@seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first
@seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first
@seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first
@seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first
@bracket_size = Wrestler.where(weight_id: weight.id).count
def createMatch(r_id,g_id,tournament)
@match = Match.new
@match.r_id = r_id
@match.g_id = g_id
@match.tournament_id = tournament
@match.round = 3
@match.save
end
if @bracket_size == 10
createMatch(@seed1.id,@seed4.id,@tournament.id)
createMatch(@seed10.id,@seed7.id,@tournament.id)
createMatch(@seed2.id,@seed3.id,@tournament.id)
createMatch(@seed8.id,@seed9.id,@tournament.id)
elsif @bracket_size == 9
createMatch(@seed1.id,@seed4.id,@tournament.id)
createMatch(@seed9.id,@seed7.id,@tournament.id)
createMatch(@seed2.id,@seed3.id,@tournament.id)
elsif @bracket_size == 8
createMatch(@seed1.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed3.id,@tournament.id)
elsif @bracket_size == 7
createMatch(@seed1.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed3.id,@tournament.id)
end
end
#ROUND 4
@weights.order("id asc").each do |weight|
@seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first
@seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first
@seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first
@seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first
@seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first
@seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first
@seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first
@seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first
@seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first
@seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first
@bracket_size = Wrestler.where(weight_id: weight.id).count
def createMatch(r_id,g_id,tournament)
@match = Match.new
@match.r_id = r_id
@match.g_id = g_id
@match.tournament_id = tournament
@match.round = 4
@match.save
end
if @bracket_size == 10
createMatch(@seed1.id,@seed7.id,@tournament.id)
createMatch(@seed5.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed8.id,@tournament.id)
createMatch(@seed6.id,@seed3.id,@tournament.id)
elsif @bracket_size == 9
createMatch(@seed1.id,@seed7.id,@tournament.id)
createMatch(@seed5.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed8.id,@tournament.id)
createMatch(@seed6.id,@seed3.id,@tournament.id)
elsif @bracket_size == 8
createMatch(@seed1.id,@seed7.id,@tournament.id)
createMatch(@seed5.id,@seed4.id,@tournament.id)
createMatch(@seed2.id,@seed8.id,@tournament.id)
createMatch(@seed6.id,@seed3.id,@tournament.id)
elsif @bracket_size == 7
createMatch(@seed1.id,@seed7.id,@tournament.id)
createMatch(@seed5.id,@seed4.id,@tournament.id)
createMatch(@seed6.id,@seed3.id,@tournament.id)
end
end
#ROUND 5
@weights.order("id asc").each do |weight|
@seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first
@seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first
@seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first
@seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first
@seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first
@seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first
@seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first
@seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first
@seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first
@seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first
@bracket_size = Wrestler.where(weight_id: weight.id).count
def createMatch(r_id,g_id,tournament)
@match = Match.new
@match.r_id = r_id
@match.g_id = g_id
@match.tournament_id = tournament
@match.round = 5
@match.save
end
if @bracket_size == 10
createMatch(@seed10.id,@seed5.id,@tournament.id)
createMatch(@seed7.id,@seed4.id,@tournament.id)
createMatch(@seed9.id,@seed6.id,@tournament.id)
createMatch(@seed8.id,@seed3.id,@tournament.id)
elsif @bracket_size == 9
createMatch(@seed7.id,@seed4.id,@tournament.id)
createMatch(@seed9.id,@seed5.id,@tournament.id)
createMatch(@seed8.id,@seed3.id,@tournament.id)
elsif @bracket_size == 8
createMatch(@seed7.id,@seed4.id,@tournament.id)
createMatch(@seed8.id,@seed3.id,@tournament.id)
elsif @bracket_size == 7
createMatch(@seed7.id,@seed4.id,@tournament.id)
end
end
end
end
end

View File

@@ -12,6 +12,7 @@ class TournamentsController < ApplicationController
def show
@schools = @tournament.schools
@weights = @tournament.weights
@mats = @tournament.mats
end
# GET /tournaments/new
@@ -26,6 +27,10 @@ class TournamentsController < ApplicationController
# POST /tournaments
# POST /tournaments.json
def create
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.new(tournament_params)
respond_to do |format|
if @tournament.save
@@ -41,6 +46,10 @@ class TournamentsController < ApplicationController
# PATCH/PUT /tournaments/1
# PATCH/PUT /tournaments/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
respond_to do |format|
if @tournament.update(tournament_params)
format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' }
@@ -55,6 +64,10 @@ class TournamentsController < ApplicationController
# DELETE /tournaments/1
# DELETE /tournaments/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament.destroy
respond_to do |format|
format.html { redirect_to tournaments_url }

View File

@@ -21,16 +21,22 @@ class WeightsController < ApplicationController
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
@mats = Mat.where(tournament_id: @tournament.id)
end
# GET /weights/1/edit
def edit
@tournament_field = @weight.tournament_id
@mats = Mat.where(tournament_id: @weight.tournament.id)
end
# POST /weights
# POST /weights.json
def create
if user_signed_in?
else
redirect_to root_path
end
@weight = Weight.new(weight_params)
@tournament = Tournament.find(weight_params[:tournament_id])
respond_to do |format|
@@ -47,6 +53,10 @@ class WeightsController < ApplicationController
# PATCH/PUT /weights/1
# PATCH/PUT /weights/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@weight.tournament_id)
respond_to do |format|
if @weight.update(weight_params)
@@ -62,6 +72,10 @@ class WeightsController < ApplicationController
# DELETE /weights/1
# DELETE /weights/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@weight.tournament_id)
@weight.destroy
respond_to do |format|
@@ -78,6 +92,6 @@ class WeightsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def weight_params
params.require(:weight).permit(:max, :tournament_id)
params.require(:weight).permit(:max, :tournament_id, :mat_id)
end
end

View File

@@ -43,6 +43,10 @@ class WrestlersController < ApplicationController
# POST /wrestlers
# POST /wrestlers.json
def create
if user_signed_in?
else
redirect_to root_path
end
@wrestler = Wrestler.new(wrestler_params)
@school = School.find(wrestler_params[:school_id])
respond_to do |format|
@@ -59,6 +63,10 @@ class WrestlersController < ApplicationController
# PATCH/PUT /wrestlers/1
# PATCH/PUT /wrestlers/1.json
def update
if user_signed_in?
else
redirect_to root_path
end
@school = School.find(@wrestler.school_id)
respond_to do |format|
if @wrestler.update(wrestler_params)
@@ -74,6 +82,10 @@ class WrestlersController < ApplicationController
# DELETE /wrestlers/1
# DELETE /wrestlers/1.json
def destroy
if user_signed_in?
else
redirect_to root_path
end
@school = School.find(@wrestler.school_id)
@wrestler.destroy
respond_to do |format|

View File

@@ -0,0 +1,2 @@
module MatsHelper
end

4
app/models/mat.rb Normal file
View File

@@ -0,0 +1,4 @@
class Mat < ActiveRecord::Base
belongs_to :tournament
has_many :weights, dependent: :destroy
end

View File

@@ -1,3 +1,4 @@
class Match < ActiveRecord::Base
belongs_to :tournament
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"]
end

View File

@@ -3,11 +3,27 @@ class School < ActiveRecord::Base
has_many :wrestlers, dependent: :destroy
#calculate score here
#def score
# @score = 0
# self.wrestlers.each do |w|
# @score = @score + w.season_win * 2
# end
# self.score = @score
#end
def score
@score = 0
self.wrestlers.each do |wrestler|
@match_wins = Match.where(winner_id: wrestler.id)
@match_wins.each do |m|
@score = @score + 2
if m.win_type == "Major"
@score = @score + 1
elsif m.win_type == "Tech Fall"
@score = @score + 1.5
elsif m.win_type == "Pin"
@score = @score + 2
elsif m.win_type == "Forfeit"
@score = @score + 2
elsif m.win_type == "Injury Default"
@score = @score + 2
elsif m.win_type == "Default"
@score = @score + 2
end
end
end
self.score = @score
end
end

View File

@@ -2,5 +2,5 @@ class Tournament < ActiveRecord::Base
has_many :schools, dependent: :destroy
has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy
end

View File

@@ -7,7 +7,8 @@
<li><%= link_to "Home", root_path %></li>
<% if @tournament %>
<li><%= link_to "Brackets" , "/static_pages/weights?tournament=#{@tournament.id}" %></li>
<li><%= link_to "Bout Board" , '#' %></li>
<li><%= link_to "Upcoming Matches" , "/static_pages/up_matches?tournament=#{@tournament.id}" %></li>
<li><%= link_to "Results" , "/static_pages/results?tournament=#{@tournament.id}" %></li>
<% end %>
<% if user_signed_in? %>
<li><%= link_to "Log Out", destroy_user_session_path, method: :delete %></li>

View File

@@ -0,0 +1,36 @@
<%= form_for(@match) do |f| %>
<% if @match.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2>
<ul>
<% @match.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label "Win Type" %><br>
<%= f.select(:win_type, Match::WIN_TYPES) %>
</div>
<div class="field">
<%= f.label "Winner" %> Please put in the id of the winner<br>
<%= @w1.name %> ID: <%= @w1.id %><br>
<%= @w2.name %> ID: <%= @w2.id %><br>
<%= f.number_field :winner_id %>
</div>
<div class="field">
<%= f.label "Score" %> Also put pin time here if applicable. If default or forfeit, leave blank<br>
<%= f.text_field :score %>
</div>
<%= f.hidden_field :finished, :value => 1 %>
<%= f.hidden_field :round, :value => @match.round %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -1,6 +1,5 @@
<h1>Editing match</h1>
<h1><%= @w1.name %> VS. <%= @w2.name %></h1>
<%= render 'form' %>
<%= render 'edit_form' %>
<%= link_to 'Show', @match %> |
<%= link_to 'Back', matches_path %>
<%= link_to 'Back', root_path %>

View File

@@ -0,0 +1,31 @@
<%= form_for(@mat) do |f| %>
<% if @mat.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@mat.errors.count, "error") %> prohibited this mat from being saved:</h2>
<ul>
<% @mat.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<% if @tournament_field %>
<%= f.hidden_field :tournament_id, :value => @tournament_field %>
<% else %>
<div class="field">
<%= f.label 'Tournament' %><br>
<%= f.collection_select :tournament_id, Tournament.all, :id, :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing mat</h1>
<%= render 'form' %>
<%= link_to 'Show', @mat %> |
<%= link_to 'Back', mats_path %>

View File

@@ -0,0 +1,29 @@
<h1>Listing mats</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Tournament</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @mats.each do |mat| %>
<tr>
<td><%= mat.name %></td>
<td><%= mat.tournament_id %></td>
<td><%= link_to 'Show', mat %></td>
<td><%= link_to 'Edit', edit_mat_path(mat) %></td>
<td><%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Mat', new_mat_path %>

View File

@@ -0,0 +1,4 @@
json.array!(@mats) do |mat|
json.extract! mat, :id, :name, :tournament_id
json.url mat_url(mat, format: :json)
end

View File

@@ -0,0 +1,5 @@
<h1>New mat</h1>
<%= render 'form' %>
<%= link_to 'Back', mats_path %>

View File

@@ -0,0 +1,13 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @mat.name %>
</p>
<p>
<strong>Tournament:</strong>
<%= @mat.tournament_id %>
</p>
<%= link_to 'Edit', edit_mat_path(@mat) %> |

View File

@@ -0,0 +1 @@
json.extract! @mat, :id, :name, :tournament_id, :created_at, :updated_at

View File

@@ -1,4 +1,4 @@
<h1><%= @weight.max %> lbs Bracket</h1>
<h3>Pool 1</h3>
<table class="table table-striped table-bordered">
<thead>

View File

@@ -1,4 +1,3 @@
<h1><%= @weight.max %> lbs Bracket</h1>
<h3>Pool 1</h3>
<table class="table table-striped table-bordered">
<thead>

View File

@@ -1,4 +1,3 @@
<h1><%= @weight.max %> lbs Bracket</h1>
<h3>Pool 1</h3>
<table class="table table-striped table-bordered">
<thead>

View File

@@ -1,4 +1,3 @@
<h1><%= @weight.max %> lbs Bracket</h1>
<h3>Pool 1</h3>
<table class="table table-striped table-bordered">
<thead>

View File

@@ -1,6 +1,7 @@
<%= link_to "Back to #{@tournament.name} weights", "/static_pages/weights?tournament=#{@tournament.id}" %>
<br>
<br>
<h1><%= @weight.max %> lbs Bracket <%= Mat.find(@weight.mat_id).name %></h1>
<% if @bracket_size == 10 %>
<%= render 'man10' %>
<% elsif @bracket_size == 9 %>

View File

@@ -0,0 +1,3 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %>
<br>
Done!

View File

@@ -0,0 +1,105 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %>
<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

@@ -0,0 +1,45 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %>
<br>
<br>
<h3>Round 1</h3>
<% @matches.each do |m| %>
<% if m.round == 1 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>
<h3>Round 2</h3>
<% @matches.each do |m| %>
<% if m.round == 2 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>
<h3>Round 3</h3>
<% @matches.each do |m| %>
<% if m.round == 3 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>
<h3>Round 4</h3>
<% @matches.each do |m| %>
<% if m.round == 4 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>
<h3>Round 5</h3>
<% @matches.each do |m| %>
<% if m.round == 5 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>
<h3>Round 6</h3>
<% @matches.each do |m| %>
<% if m.round == 6 %>
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= @weight_class %> LBS <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %>
<br>
<% end %>
<% end %>

View File

@@ -22,10 +22,13 @@
<strong>Director email:</strong>
<%= @tournament.director_email %>
</p>
<br>
<br>
<% if user_signed_in? %>
<%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}" %>
<br>
BE CAREFUL <%= link_to "Generate Matches" , "/static_pages/generate_matches?tournament=#{@tournament.id}" %>
<% end %>
<br>
<br>
@@ -86,5 +89,35 @@
</table>
<br>
<br>
<% if user_signed_in? %>
<%= link_to "New #{@tournament.name} Mat" , "/mats/new?tournament=#{@tournament.id}" %>
<% end %>
<br>
<br>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<% @mats.each do |mat| %>
<tr>
<td><%= mat.name %></td>
<td>
<% if user_signed_in? %>
<%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -25,6 +25,13 @@
</div>
<% end %>
<div class="field">
<%= f.label 'Assigned Mat' %><br>
<%= f.collection_select :mat_id, @mats, :id, :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>

View File

@@ -1,4 +1,6 @@
Wrestling::Application.routes.draw do
resources :mats
resources :matches
devise_for :users
@@ -20,8 +22,12 @@ Wrestling::Application.routes.draw do
# You can have the root of your site routed with "root"
root 'static_pages#index'
get 'static_pages/brackets'
get 'static_pages/weights'
get 'static_pages/weights'
get 'admin/index'
get 'static_pages/generate_matches'
get 'static_pages/up_matches'
get 'static_pages/control_match'
get 'static_pages/results'
# Example of regular route:
# get 'products/:id' => 'catalog#view'

View File

@@ -0,0 +1,5 @@
class AddTournamentIdToMatches < ActiveRecord::Migration
def change
add_column :matches, :tournament_id, :integer
end
end

View File

@@ -0,0 +1,5 @@
class AddRoundToMatch < ActiveRecord::Migration
def change
add_column :matches, :round, :integer
end
end

View File

@@ -0,0 +1,10 @@
class CreateMats < ActiveRecord::Migration
def change
create_table :mats do |t|
t.string :name
t.integer :tournament_id
t.timestamps
end
end
end

View File

@@ -0,0 +1,5 @@
class AddMatIdToWeights < ActiveRecord::Migration
def change
add_column :weights, :mat_id, :integer
end
end

View File

@@ -0,0 +1,5 @@
class AddFinishedFieldToMatches < ActiveRecord::Migration
def change
add_column :matches, :finished, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140124174110) do
ActiveRecord::Schema.define(version: 20140125072649) do
create_table "matches", force: true do |t|
t.integer "r_id"
@@ -23,6 +23,16 @@ ActiveRecord::Schema.define(version: 20140124174110) do
t.string "score"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "tournament_id"
t.integer "round"
t.integer "finished"
end
create_table "mats", force: true do |t|
t.string "name"
t.integer "tournament_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "schools", force: true do |t|
@@ -65,6 +75,7 @@ ActiveRecord::Schema.define(version: 20140124174110) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "tournament_id"
t.integer "mat_id"
end
create_table "wrestlers", force: true do |t|

View File

@@ -0,0 +1,49 @@
require 'test_helper'
class MatsControllerTest < ActionController::TestCase
setup do
@mat = mats(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:mats)
end
test "should get new" do
get :new
assert_response :success
end
test "should create mat" do
assert_difference('Mat.count') do
post :create, mat: { name: @mat.name, tournament_id: @mat.tournament_id }
end
assert_redirected_to mat_path(assigns(:mat))
end
test "should show mat" do
get :show, id: @mat
assert_response :success
end
test "should get edit" do
get :edit, id: @mat
assert_response :success
end
test "should update mat" do
patch :update, id: @mat, mat: { name: @mat.name, tournament_id: @mat.tournament_id }
assert_redirected_to mat_path(assigns(:mat))
end
test "should destroy mat" do
assert_difference('Mat.count', -1) do
delete :destroy, id: @mat
end
assert_redirected_to mats_path
end
end

9
test/fixtures/mats.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
tournament_id: 1
two:
name: MyString
tournament_id: 1

View File

@@ -0,0 +1,4 @@
require 'test_helper'
class MatsHelperTest < ActionView::TestCase
end

7
test/models/mat_test.rb Normal file
View File

@@ -0,0 +1,7 @@
require 'test_helper'
class MatTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end