1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 13:15:27 +00:00

Added a sort by bout number for assign_next_match

This commit is contained in:
2022-01-19 03:28:16 +00:00
parent f0e8c99b9f
commit d42b683f67
13 changed files with 199 additions and 10 deletions

View File

@@ -46,7 +46,7 @@ class MatchesController < ApplicationController
end
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.html { redirect_to session.delete(:return_path), alert: "Match did not save because: #{@match.errors.full_messages.to_s}" }
format.json { render json: @match.errors, status: :unprocessable_entity }
end
end

View File

@@ -21,7 +21,7 @@ class Mat < ActiveRecord::Base
end
def assign_next_match
t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil}
t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil}.sort_by{|m| m.bout_number}
if t_matches.size > 0
match = t_matches.sort_by{|m| m.bout_number}.first
match.mat_id = self.id

View File

@@ -4,6 +4,7 @@ class Match < ActiveRecord::Base
belongs_to :mat, touch: true
has_many :wrestlers, :through => :weight
has_many :schools, :through => :wrestlers
validate :score_validation, :win_type_validation, :bracket_position_validation
after_update :after_finished_actions, :if => :saved_change_to_finished? or :saved_change_to_winner_id? or :saved_change_to_win_type? or :saved_change_to_score?
def after_finished_actions
@@ -24,6 +25,34 @@ class Match < ActiveRecord::Base
BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis","Bracket","Conso", "Conso Quarter"]
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ", "BYE"]
def score_validation
if finished == 1
if win_type == "Pin" and ! score.match(/^[0-5]?[0-9]:[0-5][0-9]/)
errors.add(:score, "needs to be in time format MM:SS when win type is Pin example: 1:23 or 10:03")
end
if win_type == "Decision" or win_type == "Tech Fall" or win_type == "Major" and ! score.match(/^[0-9]?[0-9]-[0-9]?[0-9]/)
errors.add(:score, "needs to be in Number-Number format when win type is Decision, Tech Fall, and Major example: 10-2")
end
if (win_type == "Forfeit" or win_type == "Injury Default" or win_type == "Default" or win_type == "BYE" or win_type == "DQ") and (score != "")
errors.add(:score, "needs to be blank when win type is Forfeit, Injury Default, Default, BYE, or DQ win_type")
end
end
end
def win_type_validation
if finished == 1
if ! WIN_TYPES.include? win_type
errors.add(:win_type, "can only be one of the following #{WIN_TYPES.to_s}")
end
end
end
def bracket_position_validation
if ! BRACKET_POSITIONS.include? bracket_position
errors.add(:bracket_position, "can only be one of the following #{BRACKET_POSITIONS.to_s}")
end
end
def is_consolation_match
if self.bracket_position == "Conso" or self.bracket_position == "Conso Quarter" or self.bracket_position == "Conso Semis" or self.bracket_position == "3/4" or self.bracket_position == "5/6" or self.bracket_position == "7/8"

View File

@@ -52,11 +52,13 @@ class EightManDoubleEliminationGenerateLoserNames
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end

View File

@@ -72,11 +72,13 @@ class ModifiedSixteenManGenerateLoserNames
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end

View File

@@ -81,11 +81,13 @@ class SixteenManDoubleEliminationGenerateLoserNames
if match.w1 != nil
match.winner_id = match.w1
match.loser2_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
elsif match.w2 != nil
match.winner_id = match.w2
match.loser1_name = "BYE"
match.score = ""
match.save
match.advance_wrestlers
end

View File

@@ -40,6 +40,9 @@
<% if notice %>
<p id="notice" class="alert alert-success alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><%= notice %></p>
<% end %>
<% if alert %>
<p id="alert" class="alert alert-danger alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><%= alert %></p>
<% end %>
<div id="view"><%= yield %></div>
</div>
</div>

View File

@@ -87,7 +87,7 @@
</div>
<br>
<div class="field">
<%= f.label "Final Score" %> Also put pin time here if applicable. If default or forfeit, leave blank. Example: 7-2, 17-2, or 2:34<br>
<%= f.label "Final Score" %> For decision, major, or tech fall put the score here in Number-Number format. If pin, put the accumulated pin time in the format MM:SS. If default, injury default, dq, bye, or forfeit, leave blank. Examples: 7-2, 17-2, 0:30, or 2:34<br>
<%= f.text_field :score %>
</div>
<br>
@@ -104,6 +104,9 @@
<% end %>
<script>
// Localstorage
// https://stackoverflow.com/questions/12806198/how-do-i-save-data-on-localstorage-in-ruby-on-rails-3-2-8
//Create person object
function Person(stats){
this.stats=stats;
@@ -112,11 +115,28 @@
//Declare variables
var w1=new Person("");
var w2=new Person("");
updatejsvalues();
// Get variables
var tournament=<%= @match.tournament.id %>;
var bout=<%= @match.bout_number %>;
// if localstorage tournament id and bout number are the same and the html stat values are blank
// if the html stat values are not blank we want to honor what came from the db
if (localStorage.getItem('wrestler1') && localStorage.tournament == tournament && localStorage.bout == bout && document.getElementById("match_w1_stat").value == "" && document.getElementById("match_w2_stat").value == "") {
w1.stats = localStorage.getItem('wrestler1');
w2.stats = localStorage.getItem('wrestler2');
updatehtmlvalues();
} else {
updateLocalStorage();
}
function updatehtmlvalues(){
document.getElementById("match_w1_stat").value = w1.stats;
document.getElementById("match_w2_stat").value = w2.stats;
}
function updatejsvalues(){
w1.stats=document.getElementById("match_w1_stat").value;
w2.stats=document.getElementById("match_w2_stat").value;
@@ -130,6 +150,14 @@
updatejsvalues();
wrestler.stats = wrestler.stats + text + " ";
updatehtmlvalues();
updateLocalStorage();
}
function updateLocalStorage(){
localStorage.setItem("wrestler1",w1.stats);
localStorage.setItem("wrestler2",w2.stats);
localStorage.setItem("bout", bout);
localStorage.setItem("tournament", tournament);
}
//For Changing button colors
@@ -178,7 +206,7 @@
redColor("w1-top");
redColor("w1-bottom");
redColor("w1-nuetral");
redColor("w1-differ");
redColor("w1-defer");
redColor("w1-stalling");
redColor("w1-caution");
}
@@ -194,7 +222,7 @@
greenColor("w1-top");
greenColor("w1-bottom");
greenColor("w1-nuetral");
greenColor("w1-differ");
greenColor("w1-defer");
greenColor("w1-stalling");
greenColor("w1-caution");
}
@@ -210,7 +238,7 @@
redColor("w2-top");
redColor("w2-bottom");
redColor("w2-nuetral");
redColor("w2-differ");
redColor("w2-defer");
redColor("w2-stalling");
redColor("w2-caution");
}
@@ -226,7 +254,7 @@
greenColor("w2-top");
greenColor("w2-bottom");
greenColor("w2-nuetral");
greenColor("w2-differ");
greenColor("w2-defer");
greenColor("w2-stalling");
greenColor("w2-caution");
}