From 288cb6704ea7182f75dbe62220994398c94852ab Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Sun, 19 Jan 2025 20:35:33 -0500 Subject: [PATCH] Added a dynamic score form on the stats page, added stats page form validation on the in js to compliment the validation already in place on the model, and added the wrestler's score in the winner dropdown of the form. --- app/models/wrestler.rb | 4 + app/views/matches/_matchstats.html.erb | 378 ++++++++++-------- .../matches/_matchstats_color_change.html.erb | 108 +++++ .../_matchstats_variable_score_input.html.erb | 216 ++++++++++ 4 files changed, 543 insertions(+), 163 deletions(-) create mode 100644 app/views/matches/_matchstats_color_change.html.erb create mode 100644 app/views/matches/_matchstats_variable_score_input.html.erb diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index b56e9c8..f1f0a7e 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -295,4 +295,8 @@ class Wrestler < ApplicationRecord def short_bracket_name return "#{self.name} (#{self.school.abbreviation})" end + + def name_with_school + return "#{self.name} - #{self.school.name}" + end end diff --git a/app/views/matches/_matchstats.html.erb b/app/views/matches/_matchstats.html.erb index d27d957..4f7e10e 100644 --- a/app/views/matches/_matchstats.html.erb +++ b/app/views/matches/_matchstats.html.erb @@ -41,7 +41,7 @@ - + <%= @wrestler2_name %> Scoring
@@ -71,7 +71,34 @@ - Match Options
+ Match Options
+ + + + +
<%= @wrestler1_name %> Timer Controls
+ Injury Time (90 second max): 0 sec + + + +

+ Blood Time (600 second max): 0 sec + + + + + +
<%= @wrestler2_name %> Timer Controls
+ Injury Time (90 second max): 0 sec + + + +

+ Blood Time (600 second max): 0 sec + + + + @@ -92,13 +119,33 @@
<%= f.label "Winner" %> Please choose the winner
- <%= f.collection_select :winner_id, @wrestlers, :id, :name, include_blank: true %> + <%= f.collection_select :winner_id, @wrestlers, :id, :name_with_school, include_blank: true %>

-
- <%= 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.
- <%= f.text_field :score %> -
+ <% if @match.finished && @match.finished == 1 %> +
+ <%= 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.
+ <%= f.text_field :score %> +
+ <% else %> +
+ <%= f.label "Final Score" %> +
+ + The input will adjust based on the selected win type. + +
+
+ +
+ <%= f.hidden_field :score, id: "final-score-field" %> +
+ <%= render 'matches/matchstats_variable_score_input' %> + <% end %>
<%= f.hidden_field :finished, :value => 1 %> @@ -106,173 +153,178 @@
-
- <%= f.submit onclick: "return confirm('Is the name of the winner ' + document.getElementById('match_winner_id').options[document.getElementById('match_winner_id').selectedIndex].text + '?')", :class=>"btn btn-success" %> - -
+
+<%= f.submit "Update Match", id: "update-match-btn", onclick: "return confirm('Is the name of the winner ' + document.getElementById('match_winner_id').options[document.getElementById('match_winner_id').selectedIndex].text + '?')", class: "btn btn-success" %> +
+ <% end %> +<%= render 'matches/matchstats_color_change' %> + \ No newline at end of file +} + +// Update wrestler stats box with elapsed timer information +function updateStatsBox(wrestler, timerKey, elapsedSeconds) { + const timerType = timerKey.includes("injury") ? "Injury Time" : "Blood Time"; + const formattedTime = `${Math.floor(elapsedSeconds / 60)}m ${elapsedSeconds % 60}s`; + updateStats(wrestler, `${timerType}: ${formattedTime}`); +} + diff --git a/app/views/matches/_matchstats_color_change.html.erb b/app/views/matches/_matchstats_color_change.html.erb new file mode 100644 index 0000000..0740fe6 --- /dev/null +++ b/app/views/matches/_matchstats_color_change.html.erb @@ -0,0 +1,108 @@ + diff --git a/app/views/matches/_matchstats_variable_score_input.html.erb b/app/views/matches/_matchstats_variable_score_input.html.erb new file mode 100644 index 0000000..6d562ca --- /dev/null +++ b/app/views/matches/_matchstats_variable_score_input.html.erb @@ -0,0 +1,216 @@ +