Re-namespacing a bit to clear out some fairly old stuff from the top level
This commit is contained in:
10
oldstuff/map-mash/app/controllers/application_controller.rb
Normal file
10
oldstuff/map-mash/app/controllers/application_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# Filters added to this controller apply to all controllers in the application.
|
||||
# Likewise, all the methods added will be available for all controllers.
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
helper :all # include all helpers, all the time
|
||||
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
||||
|
||||
# Scrub sensitive parameters from your log
|
||||
# filter_parameter_logging :password
|
||||
end
|
28
oldstuff/map-mash/app/controllers/maps_controller.rb
Normal file
28
oldstuff/map-mash/app/controllers/maps_controller.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class MapsController < ApplicationController
|
||||
def index
|
||||
@maps = Map.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @maps }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.png do
|
||||
GoogleMapLocationFetcher.new.fetch([@map.name]) do |loc,image|
|
||||
dest = Rails.root.join("public/maps/#{@map.id}.png")
|
||||
FileUtils.mkdir_p(File.dirname(dest))
|
||||
|
||||
File.open(dest, 'w') do |f|
|
||||
f.write(image)
|
||||
end
|
||||
send_file(dest, :type => 'image/png')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,76 @@
|
||||
class MashTournamentsController < ApplicationController
|
||||
def index
|
||||
@mash_tournaments = MashTournament.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
begin
|
||||
@mash_tournament = MashTournament.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to :action => 'new' and return
|
||||
end
|
||||
|
||||
if not @mash_tournament.done?
|
||||
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
|
||||
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(:requester => requester)
|
||||
requester.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
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
|
||||
|
||||
respond_to do |format|
|
||||
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 do
|
||||
redirect_to :controller => 'mashes', :action => 'new'
|
||||
end
|
||||
else
|
||||
action_new.call
|
||||
end
|
||||
else
|
||||
action_new.call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
54
oldstuff/map-mash/app/controllers/mashes_controller.rb
Normal file
54
oldstuff/map-mash/app/controllers/mashes_controller.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
class MashesController < ApplicationController
|
||||
def redirect_to_new
|
||||
flash[:notice] = 'Sneaky pete.'
|
||||
redirect_to(:action => 'new')
|
||||
end
|
||||
|
||||
alias_method :index, :redirect_to_new
|
||||
alias_method :show, :redirect_to_new
|
||||
|
||||
def new
|
||||
return if not already_registered?(request.remote_ip)
|
||||
|
||||
requester = Requester.find_by_ip(request.remote_ip)
|
||||
@mash = requester.current_tournament.next_unplayed_mash
|
||||
|
||||
if not @mash
|
||||
flash[:notice] = "You're done!"
|
||||
redirect_to requester.current_tournament, :action => 'show'
|
||||
return
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return if not already_registered?(request.remote_ip)
|
||||
logger.info("Got params: #{params.inspect}")
|
||||
|
||||
@mash = Mash.find(params[:id])
|
||||
@mash.winner = Map.find((params[:mash][:winner_id] || -1).to_i)
|
||||
|
||||
logger.info("About to save #{@mash.inspect}")
|
||||
|
||||
respond_to do |format|
|
||||
if @mash.save
|
||||
flash[:notice] = 'Mashed!'
|
||||
format.html { redirect_to(:action => 'new') }
|
||||
else
|
||||
format.html { render :action => 'new' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def already_registered?(ip)
|
||||
if not Requester.find_by_ip(ip)
|
||||
redirect_to :controller => :mash_tournaments, :action => 'new'
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user