mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added queues for mats and provided a way for tournament directors to move matches to a mat.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class MatchesController < ApplicationController
|
||||
before_action :set_match, only: [:show, :edit, :update, :stat, :spectate]
|
||||
before_action :check_access, only: [:edit,:update, :stat]
|
||||
before_action :set_match, only: [:show, :edit, :update, :stat, :spectate, :edit_assignment, :update_assignment]
|
||||
before_action :check_access, only: [:edit, :update, :stat, :edit_assignment, :update_assignment]
|
||||
|
||||
# GET /matches/1
|
||||
# GET /matches/1.json
|
||||
@@ -21,7 +21,7 @@ class MatchesController < ApplicationController
|
||||
session[:return_path] = "/tournaments/#{@match.tournament.id}/matches"
|
||||
end
|
||||
|
||||
def stat
|
||||
def stat
|
||||
# @show_next_bout_button = false
|
||||
if params[:match]
|
||||
@match = Match.where(:id => params[:match]).includes(:wrestlers).first
|
||||
@@ -50,8 +50,21 @@ class MatchesController < ApplicationController
|
||||
end
|
||||
@tournament = @match.tournament
|
||||
end
|
||||
session[:return_path] = "/tournaments/#{@tournament.id}/matches"
|
||||
session[:error_return_path] = "/matches/#{@match.id}/stat"
|
||||
if @match&.mat
|
||||
@mat = @match.mat
|
||||
queue_position = @mat.queue_position_for_match(@match)
|
||||
@next_match = queue_position == 1 ? @mat.queue2_match : nil
|
||||
@show_next_bout_button = queue_position == 1
|
||||
if request.referer&.include?("/tournaments/#{@tournament.id}/matches")
|
||||
session[:return_path] = "/tournaments/#{@tournament.id}/matches"
|
||||
else
|
||||
session[:return_path] = mat_path(@mat)
|
||||
end
|
||||
session[:error_return_path] = "/matches/#{@match.id}/stat"
|
||||
else
|
||||
session[:return_path] = "/tournaments/#{@tournament.id}/matches"
|
||||
session[:error_return_path] = "/matches/#{@match.id}/stat"
|
||||
end
|
||||
end
|
||||
|
||||
# GET /matches/:id/spectate
|
||||
@@ -71,6 +84,49 @@ class MatchesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /matches/1/edit_assignment
|
||||
def edit_assignment
|
||||
@tournament = @match.tournament
|
||||
@mats = @tournament.mats.sort_by(&:name)
|
||||
@current_mat = @match.mat
|
||||
@current_queue_position = @current_mat&.queue_position_for_match(@match)
|
||||
session[:return_path] = "/tournaments/#{@tournament.id}/matches"
|
||||
end
|
||||
|
||||
# PATCH /matches/1/update_assignment
|
||||
def update_assignment
|
||||
@tournament = @match.tournament
|
||||
mat_id = params.dig(:match, :mat_id)
|
||||
queue_position = params.dig(:match, :queue_position)
|
||||
|
||||
if mat_id.blank?
|
||||
Mat.where("queue1 = :match_id OR queue2 = :match_id OR queue3 = :match_id OR queue4 = :match_id", match_id: @match.id)
|
||||
.find_each { |mat| mat.remove_match_from_queue_and_collapse!(@match.id) }
|
||||
@match.update(mat_id: nil)
|
||||
redirect_to session.delete(:return_path) || "/tournaments/#{@tournament.id}/matches", notice: "Match assignment cleared."
|
||||
return
|
||||
end
|
||||
|
||||
if queue_position.blank?
|
||||
redirect_to edit_assignment_match_path(@match), alert: "Queue position is required when selecting a mat."
|
||||
return
|
||||
end
|
||||
|
||||
unless %w[1 2 3 4].include?(queue_position.to_s)
|
||||
redirect_to edit_assignment_match_path(@match), alert: "Queue position must be between 1 and 4."
|
||||
return
|
||||
end
|
||||
|
||||
mat = @tournament.mats.find_by(id: mat_id)
|
||||
unless mat
|
||||
redirect_to edit_assignment_match_path(@match), alert: "Selected mat was not found."
|
||||
return
|
||||
end
|
||||
|
||||
mat.assign_match_to_queue!(@match, queue_position)
|
||||
redirect_to session.delete(:return_path) || "/tournaments/#{@tournament.id}/matches", notice: "Match assignment updated."
|
||||
end
|
||||
|
||||
# PATCH/PUT /matches/1
|
||||
# PATCH/PUT /matches/1.json
|
||||
def update
|
||||
|
||||
@@ -10,13 +10,13 @@ class MatsController < ApplicationController
|
||||
|
||||
if bout_number_param
|
||||
@show_next_bout_button = false
|
||||
@match = @mat.unfinished_matches.find { |m| m.bout_number == bout_number_param.to_i }
|
||||
@match = @mat.queue_matches.compact.find { |m| m.bout_number == bout_number_param.to_i }
|
||||
else
|
||||
@show_next_bout_button = true
|
||||
@match = @mat.unfinished_matches.first
|
||||
@match = @mat.queue1_match
|
||||
end
|
||||
|
||||
@next_match = @mat.unfinished_matches.second # Second unfinished match on the mat
|
||||
@next_match = @mat.queue2_match # Second match on the mat
|
||||
|
||||
@wrestlers = []
|
||||
if @match
|
||||
@@ -82,8 +82,8 @@ class MatsController < ApplicationController
|
||||
def assign_next_match
|
||||
@tournament = @mat.tournament_id
|
||||
respond_to do |format|
|
||||
if @mat.assign_next_match
|
||||
format.html { redirect_to "/tournaments/#{@mat.tournament.id}", notice: "Next Match on Mat #{@mat.name} successfully completed." }
|
||||
if @mat.advance_queue!
|
||||
format.html { redirect_to "/tournaments/#{@mat.tournament.id}", notice: "Mat #{@mat.name} queue advanced." }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { redirect_to "/tournaments/#{@mat.tournament.id}", alert: "There was an error." }
|
||||
|
||||
@@ -1,53 +1,50 @@
|
||||
class Mat < ApplicationRecord
|
||||
include ActionView::RecordIdentifier
|
||||
belongs_to :tournament
|
||||
has_many :matches, dependent: :nullify
|
||||
has_many :mat_assignment_rules, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
before_destroy do
|
||||
if tournament.matches.size > 0
|
||||
tournament.reset_mats
|
||||
matsToAssign = tournament.mats.select{|m| m.id != self.id}
|
||||
tournament.assign_mats(matsToAssign)
|
||||
end
|
||||
end
|
||||
|
||||
after_create do
|
||||
if tournament.matches.size > 0
|
||||
tournament.reset_mats
|
||||
matsToAssign = tournament.mats
|
||||
tournament.assign_mats(matsToAssign)
|
||||
end
|
||||
end
|
||||
QUEUE_SLOTS = %w[queue1 queue2 queue3 queue4].freeze
|
||||
|
||||
def assign_next_match
|
||||
slot = first_empty_queue_slot
|
||||
return true unless slot
|
||||
|
||||
match = next_eligible_match
|
||||
self.matches.reload
|
||||
if match and self.unfinished_matches.size < 4
|
||||
match.mat_id = self.id
|
||||
if match.save
|
||||
# Invalidate any wrestler caches
|
||||
if match.w1
|
||||
match.wrestler1.touch
|
||||
match.wrestler1.school.touch
|
||||
return false unless match
|
||||
|
||||
place_match_in_empty_slot!(match, slot)
|
||||
true
|
||||
end
|
||||
|
||||
def advance_queue!(finished_match = nil)
|
||||
self.class.transaction do
|
||||
if finished_match
|
||||
position = queue_position_for_match(finished_match)
|
||||
if position == 1
|
||||
shift_queue_forward!
|
||||
fill_queue_slots!
|
||||
elsif position
|
||||
remove_match_from_queue_and_collapse!(finished_match.id)
|
||||
else
|
||||
fill_queue_slots!
|
||||
end
|
||||
if match.w2
|
||||
match.wrestler2.touch
|
||||
match.wrestler2.school.touch
|
||||
end
|
||||
return true
|
||||
else
|
||||
return false
|
||||
if queue1_match&.finished == 1
|
||||
shift_queue_forward!
|
||||
end
|
||||
fill_queue_slots!
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
broadcast_current_match
|
||||
true
|
||||
end
|
||||
|
||||
def next_eligible_match
|
||||
# Start with all matches that are either unfinished (nil or 0), have a bout number, and are ordered by bout_number
|
||||
filtered_matches = tournament.matches
|
||||
filtered_matches = Match.where(tournament_id: tournament_id)
|
||||
.where(finished: [nil, 0]) # finished is nil or 0
|
||||
.where(mat_id: nil) # mat_id is nil
|
||||
.where.not(bout_number: nil) # bout_number is not nil
|
||||
@@ -57,6 +54,11 @@ class Mat < ApplicationRecord
|
||||
filtered_matches = filtered_matches
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
|
||||
# Filter out matches without a wrestlers
|
||||
filtered_matches = filtered_matches
|
||||
.where("w1 IS NOT NULL")
|
||||
.where("w2 IS NOT NULL")
|
||||
|
||||
# Apply mat assignment rules
|
||||
mat_assignment_rules.each do |rule|
|
||||
@@ -80,9 +82,178 @@ class Mat < ApplicationRecord
|
||||
filtered_matches.first
|
||||
end
|
||||
|
||||
def queue_match_ids
|
||||
QUEUE_SLOTS.map { |slot| public_send(slot) }
|
||||
end
|
||||
|
||||
def queue_matches
|
||||
queue_match_ids.map { |match_id| match_id ? Match.find_by(id: match_id) : nil }
|
||||
end
|
||||
|
||||
def queue1_match
|
||||
queue_match_at(1)
|
||||
end
|
||||
|
||||
def queue2_match
|
||||
queue_match_at(2)
|
||||
end
|
||||
|
||||
def queue3_match
|
||||
queue_match_at(3)
|
||||
end
|
||||
|
||||
def queue4_match
|
||||
queue_match_at(4)
|
||||
end
|
||||
|
||||
def queue_position_for_match(match)
|
||||
return nil unless match
|
||||
return 1 if queue1 == match.id
|
||||
return 2 if queue2 == match.id
|
||||
return 3 if queue3 == match.id
|
||||
return 4 if queue4 == match.id
|
||||
nil
|
||||
end
|
||||
|
||||
def remove_match_from_queue_and_collapse!(match_id)
|
||||
queue_ids = queue_match_ids
|
||||
return if queue_ids.none? { |id| id == match_id }
|
||||
|
||||
queue_ids.map! { |id| id == match_id ? nil : id }
|
||||
queue_ids = queue_ids.compact
|
||||
queue_ids += [nil] * (4 - queue_ids.size)
|
||||
|
||||
update!(
|
||||
queue1: queue_ids[0],
|
||||
queue2: queue_ids[1],
|
||||
queue3: queue_ids[2],
|
||||
queue4: queue_ids[3]
|
||||
)
|
||||
|
||||
fill_queue_slots!
|
||||
broadcast_current_match
|
||||
end
|
||||
|
||||
def assign_match_to_queue!(match, position)
|
||||
position = position.to_i
|
||||
raise ArgumentError, "Queue position must be 1-4" unless (1..4).cover?(position)
|
||||
|
||||
self.class.transaction do
|
||||
match.update!(mat_id: id)
|
||||
remove_match_from_other_mats!(match.id)
|
||||
|
||||
queue_ids = queue_match_ids.map { |id| id == match.id ? nil : id }
|
||||
queue_ids = queue_ids.compact
|
||||
|
||||
queue_ids.insert(position - 1, match.id)
|
||||
bumped_match_id = queue_ids.length > 4 ? queue_ids.pop : nil
|
||||
|
||||
queue_ids += [nil] * (4 - queue_ids.length)
|
||||
|
||||
update!(
|
||||
queue1: queue_ids[0],
|
||||
queue2: queue_ids[1],
|
||||
queue3: queue_ids[2],
|
||||
queue4: queue_ids[3]
|
||||
)
|
||||
|
||||
bumped_match = Match.find_by(id: bumped_match_id)
|
||||
if bumped_match && bumped_match.finished != 1
|
||||
bumped_match.update!(mat_id: nil)
|
||||
end
|
||||
end
|
||||
broadcast_current_match
|
||||
end
|
||||
|
||||
def clear_queue!
|
||||
update!(queue1: nil, queue2: nil, queue3: nil, queue4: nil)
|
||||
end
|
||||
|
||||
def unfinished_matches
|
||||
matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def queue_match_at(position)
|
||||
match_id = public_send("queue#{position}")
|
||||
match_id ? Match.find_by(id: match_id) : nil
|
||||
end
|
||||
|
||||
def first_empty_queue_slot
|
||||
QUEUE_SLOTS.each_with_index do |slot, index|
|
||||
return index + 1 if public_send(slot).nil?
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def shift_queue_forward!
|
||||
update!(
|
||||
queue1: queue2,
|
||||
queue2: queue3,
|
||||
queue3: queue4,
|
||||
queue4: nil
|
||||
)
|
||||
end
|
||||
|
||||
def fill_queue_slots!
|
||||
queue_ids = queue_match_ids
|
||||
updated = false
|
||||
|
||||
QUEUE_SLOTS.each_with_index do |_slot, index|
|
||||
next if queue_ids[index].present?
|
||||
|
||||
match = next_eligible_match
|
||||
break unless match
|
||||
|
||||
queue_ids[index] = match.id
|
||||
match.update!(mat_id: id)
|
||||
updated = true
|
||||
end
|
||||
|
||||
if updated
|
||||
update!(
|
||||
queue1: queue_ids[0],
|
||||
queue2: queue_ids[1],
|
||||
queue3: queue_ids[2],
|
||||
queue4: queue_ids[3]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_match_from_other_mats!(match_id)
|
||||
self.class.where.not(id: id)
|
||||
.where("queue1 = :match_id OR queue2 = :match_id OR queue3 = :match_id OR queue4 = :match_id", match_id: match_id)
|
||||
.find_each do |mat|
|
||||
mat.remove_match_from_queue_and_collapse!(match_id)
|
||||
end
|
||||
end
|
||||
|
||||
def place_match_in_empty_slot!(match, slot)
|
||||
self.class.transaction do
|
||||
match.update!(mat_id: id)
|
||||
remove_match_from_other_mats!(match.id)
|
||||
update!(slot_key(slot) => match.id)
|
||||
end
|
||||
broadcast_current_match
|
||||
end
|
||||
|
||||
def slot_key(slot)
|
||||
"queue#{slot}"
|
||||
end
|
||||
|
||||
def broadcast_current_match
|
||||
Turbo::StreamsChannel.broadcast_update_to(
|
||||
self,
|
||||
target: dom_id(self, :current_match),
|
||||
partial: "mats/current_match",
|
||||
locals: {
|
||||
mat: self,
|
||||
match: queue1_match,
|
||||
next_match: queue2_match,
|
||||
show_next_bout_button: true
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -37,12 +37,14 @@ class Match < ApplicationRecord
|
||||
wrestler2.touch
|
||||
end
|
||||
if self.finished == 1 && self.winner_id != nil
|
||||
if self.mat
|
||||
self.mat.assign_next_match
|
||||
end
|
||||
advance_wrestlers
|
||||
if self.mat
|
||||
self.mat.advance_queue!(self)
|
||||
end
|
||||
self.tournament.refill_open_bout_board_queues
|
||||
# School point calculation has move to the end of advance wrestler
|
||||
# calculate_school_points
|
||||
self.update(mat_id: nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -352,13 +354,13 @@ class Match < ApplicationRecord
|
||||
next unless mat
|
||||
|
||||
Turbo::StreamsChannel.broadcast_update_to(
|
||||
mat,
|
||||
target: dom_id(mat, :current_match),
|
||||
partial: "mats/current_match",
|
||||
locals: {
|
||||
mat: mat,
|
||||
match: mat.unfinished_matches.first,
|
||||
next_match: mat.unfinished_matches.second,
|
||||
mat,
|
||||
target: dom_id(mat, :current_match),
|
||||
partial: "mats/current_match",
|
||||
locals: {
|
||||
mat: mat,
|
||||
match: mat.queue1_match,
|
||||
next_match: mat.queue2_match,
|
||||
show_next_bout_button: true
|
||||
}
|
||||
)
|
||||
|
||||
@@ -82,23 +82,18 @@ class Tournament < ApplicationRecord
|
||||
matches.maximum(:round) || 0 # Return 0 if no matches or max round is nil
|
||||
end
|
||||
|
||||
def assign_mats(mats_to_assign)
|
||||
if mats_to_assign.count > 0
|
||||
until mats_to_assign.sort_by{|m| m.id}.last.matches.count == 4
|
||||
mats_to_assign.sort_by{|m| m.id}.each do |m|
|
||||
m.assign_next_match
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reset_mats
|
||||
matches.reload
|
||||
mats.reload
|
||||
matches_to_reset = matches.select{|m| m.mat_id != nil}
|
||||
# matches_to_reset.update_all( {:mat_id => nil } )
|
||||
matches_to_reset.each do |m|
|
||||
m.mat_id = nil
|
||||
m.save
|
||||
end
|
||||
mats.each do |mat|
|
||||
mat.clear_queue!
|
||||
end
|
||||
end
|
||||
|
||||
def pointAdjustments
|
||||
@@ -228,19 +223,24 @@ class Tournament < ApplicationRecord
|
||||
|
||||
def reset_and_fill_bout_board
|
||||
reset_mats
|
||||
|
||||
if mats.any?
|
||||
4.times do
|
||||
# Iterate over each mat and assign the next available match
|
||||
mats.each do |mat|
|
||||
match_assigned = mat.assign_next_match
|
||||
# If no more matches are available, exit early
|
||||
unless match_assigned
|
||||
puts "No more eligible matches to assign."
|
||||
return
|
||||
end
|
||||
matches.reload
|
||||
refill_open_bout_board_queues
|
||||
end
|
||||
|
||||
def refill_open_bout_board_queues
|
||||
return unless mats.any?
|
||||
|
||||
loop do
|
||||
assigned_any = false
|
||||
# Fill in round-robin order by queue depth:
|
||||
# all mats queue1 first, then queue2, then queue3, then queue4.
|
||||
(1..4).each do |slot|
|
||||
mats.reload.each do |mat|
|
||||
next unless mat.public_send("queue#{slot}").nil?
|
||||
assigned_any ||= mat.assign_next_match
|
||||
end
|
||||
end
|
||||
end
|
||||
break unless assigned_any
|
||||
end
|
||||
end
|
||||
|
||||
@@ -279,4 +279,4 @@ class Tournament < ApplicationRecord
|
||||
def connection_adapter
|
||||
ActiveRecord::Base.connection.adapter_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,11 @@ class TournamentBackupService
|
||||
attributes: @tournament.attributes,
|
||||
schools: @tournament.schools.map(&:attributes),
|
||||
weights: @tournament.weights.map(&:attributes),
|
||||
mats: @tournament.mats.map(&:attributes),
|
||||
mats: @tournament.mats.map do |mat|
|
||||
mat.attributes.merge(
|
||||
"queue_bout_numbers" => mat.queue_matches.map { |match| match&.bout_number }
|
||||
)
|
||||
end,
|
||||
mat_assignment_rules: @tournament.mat_assignment_rules.map do |rule|
|
||||
rule.attributes.merge(
|
||||
mat: Mat.find_by(id: rule.mat_id)&.attributes.slice("name"),
|
||||
|
||||
@@ -45,15 +45,16 @@ class WrestlingdevImporter
|
||||
# Note: Teampointadjusts are deleted via School/Wrestler cascade
|
||||
end
|
||||
|
||||
def parse_data
|
||||
parse_tournament(@import_data["tournament"]["attributes"])
|
||||
parse_schools(@import_data["tournament"]["schools"])
|
||||
parse_weights(@import_data["tournament"]["weights"])
|
||||
parse_mats(@import_data["tournament"]["mats"])
|
||||
parse_wrestlers(@import_data["tournament"]["wrestlers"])
|
||||
parse_matches(@import_data["tournament"]["matches"])
|
||||
parse_mat_assignment_rules(@import_data["tournament"]["mat_assignment_rules"])
|
||||
end
|
||||
def parse_data
|
||||
parse_tournament(@import_data["tournament"]["attributes"])
|
||||
parse_schools(@import_data["tournament"]["schools"])
|
||||
parse_weights(@import_data["tournament"]["weights"])
|
||||
parse_mats(@import_data["tournament"]["mats"])
|
||||
parse_wrestlers(@import_data["tournament"]["wrestlers"])
|
||||
parse_matches(@import_data["tournament"]["matches"])
|
||||
apply_mat_queues
|
||||
parse_mat_assignment_rules(@import_data["tournament"]["mat_assignment_rules"])
|
||||
end
|
||||
|
||||
def parse_tournament(attributes)
|
||||
attributes.except!("id")
|
||||
@@ -74,12 +75,18 @@ class WrestlingdevImporter
|
||||
end
|
||||
end
|
||||
|
||||
def parse_mats(mats)
|
||||
mats.each do |mat_attributes|
|
||||
mat_attributes.except!("id")
|
||||
Mat.create(mat_attributes.merge(tournament_id: @tournament.id))
|
||||
end
|
||||
end
|
||||
def parse_mats(mats)
|
||||
@mat_queue_bout_numbers = {}
|
||||
mats.each do |mat_attributes|
|
||||
mat_name = mat_attributes["name"]
|
||||
queue_bout_numbers = mat_attributes["queue_bout_numbers"]
|
||||
mat_attributes.except!("id", "queue1", "queue2", "queue3", "queue4", "queue_bout_numbers", "tournament_id")
|
||||
Mat.create(mat_attributes.merge(tournament_id: @tournament.id))
|
||||
if mat_name && queue_bout_numbers
|
||||
@mat_queue_bout_numbers[mat_name] = queue_bout_numbers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_mat_assignment_rules(mat_assignment_rules)
|
||||
mat_assignment_rules.each do |rule_attributes|
|
||||
@@ -134,9 +141,9 @@ class WrestlingdevImporter
|
||||
end
|
||||
end
|
||||
|
||||
def parse_matches(matches)
|
||||
matches.each do |match_attributes|
|
||||
next unless match_attributes # Skip if match_attributes is nil
|
||||
def parse_matches(matches)
|
||||
matches.each do |match_attributes|
|
||||
next unless match_attributes # Skip if match_attributes is nil
|
||||
|
||||
weight = Weight.find_by(max: match_attributes.dig("weight", "max"), tournament_id: @tournament.id)
|
||||
mat = Mat.find_by(name: match_attributes.dig("mat", "name"), tournament_id: @tournament.id)
|
||||
@@ -155,6 +162,53 @@ class WrestlingdevImporter
|
||||
w2: w2&.id,
|
||||
winner_id: winner&.id
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def apply_mat_queues
|
||||
if @mat_queue_bout_numbers.blank?
|
||||
Mat.where(tournament_id: @tournament.id).find_each do |mat|
|
||||
match_ids = mat.matches.where(finished: [nil, 0]).order(:bout_number).limit(4).pluck(:id)
|
||||
mat.update(
|
||||
queue1: match_ids[0],
|
||||
queue2: match_ids[1],
|
||||
queue3: match_ids[2],
|
||||
queue4: match_ids[3]
|
||||
)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@mat_queue_bout_numbers.each do |mat_name, bout_numbers|
|
||||
mat = Mat.find_by(name: mat_name, tournament_id: @tournament.id)
|
||||
next unless mat
|
||||
|
||||
matches = Array(bout_numbers).map do |bout_number|
|
||||
Match.find_by(bout_number: bout_number, tournament_id: @tournament.id)
|
||||
end
|
||||
|
||||
mat.update(
|
||||
queue1: matches[0]&.id,
|
||||
queue2: matches[1]&.id,
|
||||
queue3: matches[2]&.id,
|
||||
queue4: matches[3]&.id
|
||||
)
|
||||
|
||||
matches.compact.each do |match|
|
||||
match.update(mat_id: mat.id)
|
||||
end
|
||||
end
|
||||
|
||||
Mat.where(tournament_id: @tournament.id)
|
||||
.where(queue1: nil, queue2: nil, queue3: nil, queue4: nil)
|
||||
.find_each do |mat|
|
||||
match_ids = mat.matches.where(finished: [nil, 0]).order(:bout_number).limit(4).pluck(:id)
|
||||
mat.update(
|
||||
queue1: match_ids[0],
|
||||
queue2: match_ids[1],
|
||||
queue3: match_ids[2],
|
||||
queue4: match_ids[3]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ json.cache! ["api_tournament", @tournament] do
|
||||
|
||||
json.mats @mats do |mat|
|
||||
json.name mat.name
|
||||
json.unfinished_matches mat.unfinished_matches do |match|
|
||||
json.unfinished_matches mat.queue_matches.compact do |match|
|
||||
json.bout_number match.bout_number
|
||||
json.w1_name match.w1_name
|
||||
json.w2_name match.w2_name
|
||||
|
||||
34
app/views/matches/edit_assignment.html.erb
Normal file
34
app/views/matches/edit_assignment.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<h1>Assign Mat/Queue for Match <%= @match.bout_number %></h1>
|
||||
|
||||
<% if @current_mat %>
|
||||
<p>Current Assignment: Mat <%= @current_mat.name %><%= @current_queue_position ? " (Queue #{@current_queue_position})" : "" %></p>
|
||||
<% else %>
|
||||
<p>Current Assignment: Unassigned</p>
|
||||
<% end %>
|
||||
|
||||
<%= form_with model: @match, url: update_assignment_match_path(@match), method: :patch do |f| %>
|
||||
<div class="field">
|
||||
<%= f.label :mat_id, "Mat" %><br>
|
||||
<%= f.collection_select :mat_id, @mats, :id, :name, { include_blank: "Unassigned" } %>
|
||||
</div>
|
||||
<br>
|
||||
<div class="field">
|
||||
<%= f.label :queue_position, "Queue Position" %><br>
|
||||
<%= f.select :queue_position,
|
||||
options_for_select(
|
||||
[
|
||||
["On Mat (Queue 1)", 1],
|
||||
["On Deck (Queue 2)", 2],
|
||||
["In The Hole (Queue 3)", 3],
|
||||
["Warm Up (Queue 4)", 4]
|
||||
],
|
||||
@current_queue_position
|
||||
),
|
||||
include_blank: "Select position"
|
||||
%>
|
||||
</div>
|
||||
<br>
|
||||
<div class="actions">
|
||||
<%= f.submit "Update Assignment", class: "btn btn-success" %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,6 +1,6 @@
|
||||
<% @mat = mat %>
|
||||
<% @match = local_assigns[:match] || mat.unfinished_matches.first %>
|
||||
<% @next_match = local_assigns[:next_match] || mat.unfinished_matches.second %>
|
||||
<% @match = local_assigns[:match] || mat.queue1_match %>
|
||||
<% @next_match = local_assigns[:next_match] || mat.queue2_match %>
|
||||
<% @show_next_bout_button = local_assigns.key?(:show_next_bout_button) ? local_assigns[:show_next_bout_button] : true %>
|
||||
|
||||
<% @wrestlers = [] %>
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
"attributes": <%= @tournament.attributes.to_json %>,
|
||||
"schools": <%= @tournament.schools.map(&:attributes).to_json %>,
|
||||
"weights": <%= @tournament.weights.map(&:attributes).to_json %>,
|
||||
"mats": <%= @tournament.mats.map(&:attributes).to_json %>,
|
||||
"mats": <%= @tournament.mats.map { |mat| mat.attributes.merge(
|
||||
{
|
||||
"queue_bout_numbers": mat.queue_matches.map { |match| match&.bout_number }
|
||||
}
|
||||
) }.to_json %>,
|
||||
"wrestlers": <%= @tournament.wrestlers.map { |wrestler| wrestler.attributes.merge(
|
||||
{
|
||||
"school": wrestler.school&.attributes,
|
||||
@@ -20,4 +24,4 @@
|
||||
}
|
||||
) }.to_json %>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<td><%= match.finished %></td>
|
||||
<td><%= link_to 'Show', match, :class=>"btn btn-default btn-sm" %>
|
||||
<%= link_to 'Edit Wrestlers', edit_match_path(match), :class=>"btn btn-primary btn-sm" %>
|
||||
<%= link_to 'Edit Mat/Queue', edit_assignment_match_path(match), :class=>"btn btn-primary btn-sm" %>
|
||||
<%= link_to 'Stat Match', "/matches/#{match.id}/stat", :class=>"btn btn-primary btn-sm" %>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -36,4 +37,4 @@
|
||||
</table>
|
||||
<br>
|
||||
<p>Total matches without byes: <%= @matches.select{|m| m.loser1_name != 'BYE' and m.loser2_name != 'BYE'}.size %></p>
|
||||
<p>Unfinished matches: <%= @matches.select{|m| m.finished != 1 and m.loser1_name != 'BYE' and m.loser2_name != 'BYE'}.size %></p>
|
||||
<p>Unfinished matches: <%= @matches.select{|m| m.finished != 1 and m.loser1_name != 'BYE' and m.loser2_name != 'BYE'}.size %></p>
|
||||
|
||||
@@ -45,31 +45,31 @@
|
||||
<tr>
|
||||
<td><%= m.name %></td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> (<%= m.unfinished_matches.first.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.first.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.first.w2_bracket_name %>
|
||||
<% if m.queue1_match %><strong><%=m.queue1_match.bout_number%></strong> (<%= m.queue1_match.bracket_position %>)<br>
|
||||
<%= m.queue1_match.weight_max %> lbs
|
||||
<br><%= m.queue1_match.w1_bracket_name %> vs. <br>
|
||||
<%= m.queue1_match.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> (<%= m.unfinished_matches.second.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.second.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.second.w2_bracket_name %>
|
||||
<% if m.queue2_match %><strong><%=m.queue2_match.bout_number%></strong> (<%= m.queue2_match.bracket_position %>)<br>
|
||||
<%= m.queue2_match.weight_max %> lbs
|
||||
<br><%= m.queue2_match.w1_bracket_name %> vs. <br>
|
||||
<%= m.queue2_match.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> (<%= m.unfinished_matches.third.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.third.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.third.w2_bracket_name %>
|
||||
<% if m.queue3_match %><strong><%=m.queue3_match.bout_number%></strong> (<%= m.queue3_match.bracket_position %>)<br>
|
||||
<%= m.queue3_match.weight_max %> lbs
|
||||
<br><%= m.queue3_match.w1_bracket_name %> vs. <br>
|
||||
<%= m.queue3_match.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> (<%= m.unfinished_matches.fourth.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.fourth.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.fourth.w2_bracket_name %>
|
||||
<% if m.queue4_match %><strong><%=m.queue4_match.bout_number%></strong> (<%= m.queue4_match.bracket_position %>)<br>
|
||||
<%= m.queue4_match.weight_max %> lbs
|
||||
<br><%= m.queue4_match.w1_bracket_name %> vs. <br>
|
||||
<%= m.queue4_match.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user