mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a finished_at column on matches, created a callback to updated that only if finished changes and is 1, and display that on the match stats page.
This commit is contained in:
@@ -89,7 +89,7 @@ class MatchesController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def match_params
|
||||
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :overtime_type, :finished)
|
||||
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :overtime_type, :finished, :round)
|
||||
end
|
||||
|
||||
def check_access
|
||||
|
||||
@@ -5,6 +5,11 @@ class Match < ApplicationRecord
|
||||
has_many :wrestlers, :through => :weight
|
||||
has_many :schools, :through => :wrestlers
|
||||
validate :score_validation, :win_type_validation, :bracket_position_validation, :overtime_type_validation
|
||||
|
||||
# Callback to update finished_at when finished changes
|
||||
# for some reason saved_change_to_finished? does not work on before_save like it does for after_update
|
||||
before_save :update_finished_at, if: -> { will_save_change_to_attribute?(:finished) }
|
||||
|
||||
after_update :after_finished_actions, if: -> {
|
||||
saved_change_to_finished? ||
|
||||
saved_change_to_winner_id? ||
|
||||
@@ -20,7 +25,7 @@ class Match < ApplicationRecord
|
||||
if self.w2
|
||||
wrestler2.touch
|
||||
end
|
||||
if self.reload.finished == 1 && self.reload.winner_id != nil
|
||||
if self.finished == 1 && self.winner_id != nil
|
||||
if self.mat
|
||||
self.mat.assign_next_match
|
||||
end
|
||||
@@ -282,4 +287,10 @@ class Match < ApplicationRecord
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_finished_at
|
||||
self.finished_at = finished == 1 ? Time.current.utc : nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class Wrestler < ApplicationRecord
|
||||
|
||||
|
||||
def last_finished_match
|
||||
all_matches.select{|m| m.finished == 1}.sort_by{|m| m.bout_number}.last
|
||||
all_matches.select{|m| m.finished == 1}.sort_by{|m| m.finished_at}.last
|
||||
end
|
||||
|
||||
def total_team_points
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
<option value="red">Red</option>
|
||||
</select>
|
||||
<br>School: <%= @wrestler1_school_name %>
|
||||
<br>Last Match: <%= @wrestler1_last_match ? time_ago_in_words(@wrestler1_last_match.updated_at) : "N/A" %></th>
|
||||
<br>Last Match: <%= @wrestler1_last_match && @wrestler1_last_match.finished_at ? time_ago_in_words(@wrestler1_last_match.finished_at) : "N/A" %></th>
|
||||
<th>Name: <%= @wrestler2_name %> <select id="w2-color" onchange="changeW2Color(this)">
|
||||
<option value="red">Red</option>
|
||||
<option value="green">Green</option>
|
||||
</select>
|
||||
<br>School: <%= @wrestler2_school_name %>
|
||||
<br>Last Match: <%= @wrestler2_last_match ? time_ago_in_words(@wrestler2_last_match.updated_at) : "N/A" %></th>
|
||||
<br>Last Match: <%= @wrestler2_last_match && @wrestler2_last_match.finished_at ? time_ago_in_words(@wrestler2_last_match.finished_at) : "N/A" %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user