mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a bout board
This commit is contained in:
@@ -8,7 +8,8 @@ class StaticPagesController < ApplicationController
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
end
|
||||
if @tournament
|
||||
@matches = @tournament.matches
|
||||
@matches = @tournament.matches.where(mat_id: nil)
|
||||
@mats = @tournament.mats
|
||||
if @matches.empty?
|
||||
redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}"
|
||||
end
|
||||
|
||||
@@ -23,6 +23,7 @@ module GeneratesTournamentMatches
|
||||
def generateMatches
|
||||
assignBouts
|
||||
assignLoserNames
|
||||
assignFirstMatchesToMats
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
class Mat < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
has_many :matches
|
||||
|
||||
def assignNextMatch
|
||||
t_matches = tournament.matches.where(mat_id: nil)
|
||||
match = t_matches.order(:bout_number).first
|
||||
match.mat_id = self.id
|
||||
match.save
|
||||
end
|
||||
|
||||
def unfinishedMatches
|
||||
matches.where(finished: nil).order(:bout_number)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Match < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
belongs_to :weight
|
||||
belongs_to :mat
|
||||
|
||||
|
||||
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
|
||||
|
||||
@@ -41,4 +41,12 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def assignFirstMatchesToMats
|
||||
until mats.order(:id).last.matches.count == 4
|
||||
mats.order(:id).each do |m|
|
||||
m.assignNextMatch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -4,11 +4,45 @@
|
||||
$('#matchList').dataTable();
|
||||
} );
|
||||
</script>
|
||||
<script>
|
||||
setTimeout("location.reload(true);",30000);
|
||||
</script>
|
||||
<br>
|
||||
<br>
|
||||
<h5 style="color:red">This page reloads every 30s</h5>
|
||||
<br>
|
||||
<br>
|
||||
<h3>Upcoming Matches</h3>
|
||||
<br>
|
||||
<br>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Mat</th>
|
||||
<th>On Mat</th>
|
||||
<th>On Deck</th>
|
||||
<th>In The Hole</th>
|
||||
<th>Warm Up</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @mats.each.map do |m| %>
|
||||
<tr>
|
||||
<td>Mat <%= m.name %></td>
|
||||
<td><%=m.unfinishedMatches.first.bout_number%><br><%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %></td>
|
||||
<td><%=m.unfinishedMatches.second.bout_number%><br><%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %></td>
|
||||
<td><%=m.unfinishedMatches.third.bout_number%><br><%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %></td>
|
||||
<td><%=m.unfinishedMatches.fourth.bout_number%><br><%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
<h3>Matches not assigned</h3>
|
||||
<br>
|
||||
<br>
|
||||
<table class="display compact cell-border" id="matchList">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
6
db/migrate/20150619142023_add_mat_id_to_match.rb
Normal file
6
db/migrate/20150619142023_add_mat_id_to_match.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddMatIdToMatch < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :matches, :mat_id, :integer
|
||||
add_index :matches, :mat_id
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150523121319) do
|
||||
ActiveRecord::Schema.define(version: 20150619142023) do
|
||||
|
||||
create_table "matches", force: :cascade do |t|
|
||||
t.integer "w1"
|
||||
@@ -32,8 +32,10 @@ ActiveRecord::Schema.define(version: 20150523121319) do
|
||||
t.integer "bracket_position_number"
|
||||
t.string "loser1_name"
|
||||
t.string "loser2_name"
|
||||
t.integer "mat_id"
|
||||
end
|
||||
|
||||
add_index "matches", ["mat_id"], name: "index_matches_on_mat_id"
|
||||
add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id"
|
||||
add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ if Rails.env.development?
|
||||
Weight.create(id: 202, max: 113, tournament_id: 200 )
|
||||
Weight.create(id: 203, max: 120, tournament_id: 200 )
|
||||
Weight.create(id: 204, max: 126, tournament_id: 200 )
|
||||
Mat.create(id: 200, name: "1", tournament_id: 200 )
|
||||
Mat.create(id: 201, name: "2", tournament_id: 200 )
|
||||
Mat.create(id: 202, name: "3", tournament_id: 200 )
|
||||
Mat.create(id: 203, name: "4", tournament_id: 200 )
|
||||
Wrestler.create(name: 'Guy 1', school_id: 200, weight_id: 200, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||
Wrestler.create(name: 'Guy 2', school_id: 201, weight_id: 200, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||
Wrestler.create(name: 'Guy 3', school_id: 202, weight_id: 200, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
|
||||
|
||||
Reference in New Issue
Block a user