mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-04 13:43:48 +00:00
Added mat assignment rules for the bout board and fixed the bug where a delegate making the tournamnet info public changes them to the owner
This commit is contained in:
82
app/controllers/mat_assignment_rules_controller.rb
Normal file
82
app/controllers/mat_assignment_rules_controller.rb
Normal file
@@ -0,0 +1,82 @@
|
||||
class MatAssignmentRulesController < ApplicationController
|
||||
before_action :set_tournament
|
||||
before_action :check_access_manage
|
||||
before_action :set_mat_assignment_rule, only: [:edit, :update, :show, :destroy]
|
||||
|
||||
def index
|
||||
@mat_assignment_rules = @tournament.mat_assignment_rules
|
||||
# Create a hash mapping each Weight ID to its Weight object for quick lookups
|
||||
@weights_by_id = @tournament.weights.index_by(&:id)
|
||||
end
|
||||
|
||||
def new
|
||||
@mat_assignment_rule = @tournament.mat_assignment_rules.build
|
||||
load_form_data
|
||||
end
|
||||
|
||||
def destroy
|
||||
@mat_assignment_rule.destroy
|
||||
redirect_to tournament_mat_assignment_rules_path(@tournament), notice: 'Mat assignment rule was successfully deleted.'
|
||||
end
|
||||
|
||||
def create
|
||||
@mat_assignment_rule = @tournament.mat_assignment_rules.build(mat_assignment_rule_params)
|
||||
load_form_data
|
||||
|
||||
if @mat_assignment_rule.save
|
||||
redirect_to tournament_mat_assignment_rules_path(@tournament), notice: 'Mat assignment rule created successfully.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
load_form_data
|
||||
end
|
||||
|
||||
def update
|
||||
load_form_data
|
||||
|
||||
if @mat_assignment_rule.update(mat_assignment_rule_params)
|
||||
redirect_to tournament_mat_assignment_rules_path(@tournament), notice: 'Mat assignment rule updated successfully.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_tournament
|
||||
@tournament = Tournament.find(params[:tournament_id])
|
||||
end
|
||||
|
||||
def set_mat_assignment_rule
|
||||
@mat_assignment_rule = @tournament.mat_assignment_rules.find(params[:id])
|
||||
end
|
||||
|
||||
def check_access_manage
|
||||
authorize! :manage, @tournament
|
||||
end
|
||||
|
||||
def mat_assignment_rule_params
|
||||
# Set defaults to empty arrays if no checkboxes are selected
|
||||
# otherwise rails interprets this as "don't modify"
|
||||
params[:mat_assignment_rule][:weight_classes] ||= []
|
||||
params[:mat_assignment_rule][:bracket_positions] ||= []
|
||||
params[:mat_assignment_rule][:rounds] ||= []
|
||||
|
||||
# Permit the parameters and convert specific fields to integer arrays
|
||||
params.require(:mat_assignment_rule).permit(:mat_id, weight_classes: [], bracket_positions: [], rounds: []).tap do |whitelisted|
|
||||
whitelisted[:weight_classes] = whitelisted[:weight_classes].map(&:to_i)
|
||||
whitelisted[:bracket_positions] = whitelisted[:bracket_positions].map(&:to_i)
|
||||
whitelisted[:rounds] = whitelisted[:rounds].map(&:to_i)
|
||||
end
|
||||
end
|
||||
|
||||
# Load data needed for the form
|
||||
def load_form_data
|
||||
@available_mats = Mat.all
|
||||
@unique_bracket_positions = @tournament.matches.select(:bracket_position).distinct.pluck(:bracket_position)
|
||||
@unique_rounds = @tournament.matches.select(:round).distinct.pluck(:round)
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
class TournamentsController < ApplicationController
|
||||
before_action :set_tournament, only: [:calculate_team_scores, :import,:export,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_manage, only: [:calculate_team_scores, :import,:export,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||
before_action :set_tournament, only: [:reset_bout_board,:calculate_team_scores, :import,:export,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_manage, only: [:reset_bout_board,:calculate_team_scores, :import,:export,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||
before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
||||
before_action :check_tournament_errors, only: [:generate_matches]
|
||||
before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||
@@ -248,6 +248,7 @@ class TournamentsController < ApplicationController
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.new(tournament_params)
|
||||
@tournament.user_id = current_user.id
|
||||
respond_to do |format|
|
||||
if @tournament.save
|
||||
format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' }
|
||||
@@ -282,6 +283,11 @@ class TournamentsController < ApplicationController
|
||||
def error
|
||||
end
|
||||
|
||||
def reset_bout_board
|
||||
@tournament.reset_and_fill_bout_board
|
||||
redirect_to tournament_path(@tournament), notice: "Successfully reset the bout board."
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_tournament
|
||||
@@ -290,7 +296,7 @@ class TournamentsController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def tournament_params
|
||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id, :date, :originalId, :swapId, :is_public)
|
||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :date, :originalId, :swapId, :is_public)
|
||||
end
|
||||
|
||||
#Check for tournament owner
|
||||
|
||||
Reference in New Issue
Block a user