mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-01 12:15:25 +00:00
Swap page is now working and also moved swaping logic from tournament model to its own class
This commit is contained in:
@@ -7,14 +7,14 @@ class Match < ActiveRecord::Base
|
||||
|
||||
|
||||
after_update do
|
||||
if self.finished == 1 && self.winner_id != nil
|
||||
if self.w1 && self.w2
|
||||
if self.finished == 1 && self.winner_id != nil
|
||||
if self.w1 && self.w2
|
||||
wrestler1.touch
|
||||
wrestler2.touch
|
||||
end
|
||||
advance_wrestlers
|
||||
calcSchoolPoints
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"]
|
||||
@@ -136,14 +136,5 @@ class Match < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
if self.w1 == wrestler1_id
|
||||
self.w1 = wrestler2_id
|
||||
self.save
|
||||
elsif self.w2 == wrestler1_id
|
||||
self.w2 = wrestler2_id
|
||||
self.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
42
app/models/swap_wrestlers.rb
Normal file
42
app/models/swap_wrestlers.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class SwapWrestlers
|
||||
attr_accessor :wrestler1_id, :wrestler2_id
|
||||
|
||||
|
||||
def swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
w1 = Wrestler.find(wrestler1_id)
|
||||
w2 = Wrestler.find(wrestler2_id)
|
||||
|
||||
#placeholder guy
|
||||
w3 = Wrestler.new
|
||||
w3.weight_id = w1.weight_id
|
||||
w3.original_seed = w1.original_seed
|
||||
w3.seed = w1.seed
|
||||
swapWrestlerMatches(w1.allMatches,w1.id,w3.id)
|
||||
|
||||
#Swap wrestler 1 and wrestler 2
|
||||
swapWrestlerMatches(w2.allMatches,w2.id,w1.id)
|
||||
w1.seed = w2.seed
|
||||
|
||||
|
||||
swapWrestlerMatches(w3.allMatches,w3.id,w2.id)
|
||||
w2.seed = w3.seed
|
||||
|
||||
|
||||
w1.save
|
||||
w2.save
|
||||
end
|
||||
|
||||
def swapWrestlerMatches(matchesToSwap,w1_id,w2_id)
|
||||
matchesToSwap.each do |m|
|
||||
if m.bracket_position == "Pool"
|
||||
if m.w1 == w1_id
|
||||
m.w1 = w2_id
|
||||
m.save
|
||||
elsif m.w2 == w1_id
|
||||
m.w2 = w2_id
|
||||
m.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,7 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :wrestlers, through: :weights
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :delegates, class_name: "TournamentDelegate"
|
||||
|
||||
|
||||
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
||||
|
||||
def self.search(search)
|
||||
@@ -136,36 +136,6 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
w1 = Wrestler.find(wrestler1_id)
|
||||
w2 = Wrestler.find(wrestler2_id)
|
||||
|
||||
#placeholder guy
|
||||
w3 = Wrestler.new
|
||||
w3.weight_id = w1.weight_id
|
||||
w3.original_seed = w1.original_seed
|
||||
w3.seed = w1.seed
|
||||
swapWrestlerMatches(w1.allMatches,wrestler1_id,w3.id)
|
||||
|
||||
#Swap wrestler 1 and wrestler 2
|
||||
swapWrestlerMatches(w2.allMatches,wrestler2_id,wrestler1_id)
|
||||
w1.seed = w2.seed
|
||||
|
||||
|
||||
swapWrestlerMatches(w3.allMatches,w3.id,wrestler2_id)
|
||||
w2.seed = w3.seed
|
||||
|
||||
|
||||
w1.save
|
||||
w2.save
|
||||
end
|
||||
|
||||
def swapWrestlerMatches(matchesToSwap,w1_id,w2_id)
|
||||
matchesToSwap.each do |m|
|
||||
if m.bracket_position == "Pool"
|
||||
m.swapWrestlers(w1_id,w2_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
self.tournament.swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
SwapWrestlers.new.swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
end
|
||||
|
||||
def returnPoolNumber(wrestler)
|
||||
|
||||
@@ -4,16 +4,16 @@ class Wrestler < ActiveRecord::Base
|
||||
has_one :tournament, through: :weight
|
||||
has_many :matches, through: :weight
|
||||
has_many :deductedPoints, class_name: "Teampointadjust"
|
||||
attr_accessor :poolNumber, :poolAdvancePoints, :swapId
|
||||
attr_accessor :poolNumber, :poolAdvancePoints, :originalId, :swapId
|
||||
|
||||
validates :name, :weight_id, :school_id, presence: true
|
||||
|
||||
before_destroy do
|
||||
self.tournament.destroyAllMatches
|
||||
# self.tournament.destroyAllMatches
|
||||
end
|
||||
|
||||
before_create do
|
||||
self.tournament.destroyAllMatches
|
||||
# self.tournament.destroyAllMatches
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user