1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-31 19:45:45 +00:00

Moving pages to tournament from static_pages

This commit is contained in:
2015-11-04 16:10:56 -05:00
parent 0ad274b421
commit f86a577c8b
15 changed files with 111 additions and 114 deletions

View File

@@ -1,31 +1,7 @@
class StaticPagesController < ApplicationController
before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in]
def tournaments
@tournaments = Tournament.all.includes(:user,:matches,:mats)
end
def up_matches
if params[:tournament]
@tournament = Tournament.where(:id => params[:tournament]).includes(:matches,:mats).first
end
if @tournament
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
@mats = @tournament.mats.includes(:matches)
if @tournament.matches.empty?
redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}"
end
end
end
def team_scores
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@schools = School.where(tournament_id: @tournament.id)
@schools.sort_by{|x|[x.score]}
end
end
def results
if params[:tournament]
@@ -58,15 +34,6 @@ class StaticPagesController < ApplicationController
end
end
def weights
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@weights = Weight.where(tournament_id: @tournament.id)
@weights = @weights.sort_by{|x|[x.max]}
end
end
def createCustomWeights
@tournament = Tournament.find(params[:tournament])
@@ -77,20 +44,6 @@ class StaticPagesController < ApplicationController
end
def noMatches
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
end
def generate_matches
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
if @tournament
@tournament.generateMatchups
end
end
def weigh_in
if params[:wrestler]

View File

@@ -1,32 +1,51 @@
class TournamentsController < ApplicationController
before_action :set_tournament, only: [:show, :edit, :update, :destroy]
before_filter :check_access, only: [:update,:edit,:destroy]
before_action :set_tournament, only: [:show, :edit, :update, :destroy,:up_matches,:no_matches,:team_scores,:weights,:generate_matches]
before_filter :check_access, only: [:update,:edit,:destroy,:generate_matches]
before_filter :check_for_matches, only: [:up_matches]
# GET /tournaments
# GET /tournaments.json
def index
@tournaments = Tournament.all
def generate_matches
@tournament.generateMatchups
end
def weights
@weights = @tournament.weights
@weights.sort_by{|w| w.max}
end
def team_scores
@schools = @tournament.schools
@schools.sort_by{|s| s.score}
end
def no_matches
end
def up_matches
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
@mats = @tournament.mats.includes(:matches)
end
def index
@tournaments = Tournament.all.limit(50).includes(:schools,:weights,:mats,:matches,:user,:wrestlers)
end
# GET /tournaments/1
# GET /tournaments/1.json
def show
@schools = @tournament.schools
@weights = @tournament.weights.sort_by{|x|[x.max]}
@mats = @tournament.mats
end
# GET /tournaments/new
def new
@tournament = Tournament.new
end
# GET /tournaments/1/edit
def edit
end
# POST /tournaments
# POST /tournaments.json
def create
if user_signed_in?
else
@@ -44,8 +63,6 @@ class TournamentsController < ApplicationController
end
end
# PATCH/PUT /tournaments/1
# PATCH/PUT /tournaments/1.json
def update
respond_to do |format|
if @tournament.update(tournament_params)
@@ -58,8 +75,6 @@ class TournamentsController < ApplicationController
end
end
# DELETE /tournaments/1
# DELETE /tournaments/1.json
def destroy
@tournament.destroy
respond_to do |format|
@@ -71,16 +86,26 @@ class TournamentsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_tournament
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats).first
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
end
# 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)
end
#Check for tournament owner
def check_access
if current_user != @tournament.user
redirect_to root_path
redirect_to '/static_pages/not_allowed'
end
end
def check_for_matches
if @tournament
if @tournament.matches.empty?
redirect_to "/tournaments/#{@tournament.id}/no_matches"
end
end
end
end