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." }
|
||||
|
||||
Reference in New Issue
Block a user