1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Merge branch 'development'

This commit is contained in:
2018-01-31 09:17:18 -05:00

View File

@@ -1,36 +1,36 @@
class Mat < ActiveRecord::Base class Mat < ActiveRecord::Base
belongs_to :tournament belongs_to :tournament
has_many :matches has_many :matches
validates :name, presence: true validates :name, presence: true
before_destroy do before_destroy do
if tournament.matches.size > 0 if tournament.matches.size > 0
tournament.resetMats tournament.resetMats
matsToAssign = tournament.mats.select{|m| m.id != self.id} matsToAssign = tournament.mats.select{|m| m.id != self.id}
tournament.assignMats(matsToAssign) tournament.assignMats(matsToAssign)
end end
end end
after_create do after_create do
if tournament.matches.size > 0 if tournament.matches.size > 0
tournament.resetMats tournament.resetMats
matsToAssign = tournament.mats matsToAssign = tournament.mats
tournament.assignMats(matsToAssign) tournament.assignMats(matsToAssign)
end end
end end
def assignNextMatch def assignNextMatch
t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1} t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && bout_number != nil}
if t_matches.size > 0 if t_matches.size > 0
match = t_matches.sort_by{|m| m.bout_number}.first match = t_matches.sort_by{|m| m.bout_number}.first
match.mat_id = self.id match.mat_id = self.id
match.save match.save
end end
end end
def unfinishedMatches def unfinishedMatches
matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number} matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
end end
end end