|
|
|
@ -15,18 +15,26 @@ class MashTournamentsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not @mash_tournament.done?
|
|
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
|
redirect_to new_mash_path
|
|
|
|
|
flash[:notice] = "You're not quite done there."
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
logger.info("Mash tournament #{@mash_tournament.id} is done!")
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
|
requester = Requester.find_or_initialize_by_ip(request.remote_ip)
|
|
|
|
|
if requester.current_tournament && !requester.current_tournament.done?
|
|
|
|
|
flash[:notice] = "But you haven't finished this one yet :-("
|
|
|
|
|
redirect_to new_mash_path and return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@mash_tournament = MashTournament.new
|
|
|
|
|
@mash_tournament = MashTournament.new(:requester => requester)
|
|
|
|
|
requester.save
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
@ -34,32 +42,35 @@ class MashTournamentsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
|
if not (requester = Requester.find_by_ip(request.remote_ip))
|
|
|
|
|
flash[:notice] = "Not so fast..."
|
|
|
|
|
redirect_to new_mash_tournament_path and return
|
|
|
|
|
end
|
|
|
|
|
if requester.current_tournament && !requester.current_tournament.done?
|
|
|
|
|
flash[:notice] = "Seriously, you haven't finished this one yet! :-P"
|
|
|
|
|
redirect_to new_mash_path and return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@mash_tournament = MashTournament.new(:requester => requester)
|
|
|
|
|
rounds = params.fetch(:mash_tournament, {}).fetch(:total_rounds, 3).to_i
|
|
|
|
|
|
|
|
|
|
@mash_tournament = MashTournament.new(
|
|
|
|
|
:requester => Requester.new(:ip => request.remote_ip)
|
|
|
|
|
)
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @mash_tournament.save && (
|
|
|
|
|
@mash_tournament.builder.create_rounds_for_contenders(8) == 3
|
|
|
|
|
) && (
|
|
|
|
|
@mash_tournament.builder.fill_in_next_round.length == 4
|
|
|
|
|
)
|
|
|
|
|
action_new = lambda { format.html { render :action => 'new' } }
|
|
|
|
|
|
|
|
|
|
if @mash_tournament.save
|
|
|
|
|
builder = @mash_tournament.builder
|
|
|
|
|
if builder.create_rounds_for_contenders(2 ** rounds) == rounds and
|
|
|
|
|
builder.fill_in_next_round.length == (2 ** rounds) / 2
|
|
|
|
|
flash[:notice] = "Let's start mashing!"
|
|
|
|
|
format.html { redirect_to :controller => 'mashes', :action => 'new' }
|
|
|
|
|
else
|
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to :controller => 'mashes', :action => 'new'
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
action_new.call
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
action_new.call
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def should_start_mashing?(ip)
|
|
|
|
|
if requester = Requester.find_by_ip(ip)
|
|
|
|
|
redirect_to :controller => 'mashes', :action => 'new'
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|