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();
} );
+
+
+
+
| Mat | +On Mat | +On Deck | +In The Hole | +Warm 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 %> |
+