diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 77d8e7b..0db9b77 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -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 diff --git a/app/models/generates_tournament_matches.rb b/app/models/generates_tournament_matches.rb index 752292b..401c5bf 100644 --- a/app/models/generates_tournament_matches.rb +++ b/app/models/generates_tournament_matches.rb @@ -23,6 +23,7 @@ module GeneratesTournamentMatches def generateMatches assignBouts assignLoserNames + assignFirstMatchesToMats end end diff --git a/app/models/mat.rb b/app/models/mat.rb index 7907f1a..31ce709 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -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 diff --git a/app/models/match.rb b/app/models/match.rb index b5a95da..5f83be3 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -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"] diff --git a/app/models/tournament.rb b/app/models/tournament.rb index a103274..da20537 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -40,5 +40,13 @@ class Tournament < ActiveRecord::Base m.save! end end + + def assignFirstMatchesToMats + until mats.order(:id).last.matches.count == 4 + mats.order(:id).each do |m| + m.assignNextMatch + end + end + end end diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index ccf7276..13ff4f4 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -4,11 +4,45 @@ $('#matchList').dataTable(); } ); + +
+
+
This page reloads every 30s


Upcoming Matches



+ + + + + + + + + + + + + <% @mats.each.map do |m| %> + + + + + + + + <% end %> + +
MatOn MatOn DeckIn The HoleWarm Up
Mat <%= m.name %><%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %>
<%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %>
<%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %>
<%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %>
+
+
+

Matches not assigned

+
+
diff --git a/db/migrate/20150619142023_add_mat_id_to_match.rb b/db/migrate/20150619142023_add_mat_id_to_match.rb new file mode 100644 index 0000000..c51fc82 --- /dev/null +++ b/db/migrate/20150619142023_add_mat_id_to_match.rb @@ -0,0 +1,6 @@ +class AddMatIdToMatch < ActiveRecord::Migration + def change + add_column :matches, :mat_id, :integer + add_index :matches, :mat_id + end +end diff --git a/db/schema.rb b/db/schema.rb index ffedbe8..eaafe4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index d53f92c..1d4bac2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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')