2015-04-15 11:00:32 -04:00
|
|
|
require './environments'
|
|
|
|
|
|
|
|
set :public_folder, 'public'
|
|
|
|
|
2015-04-23 14:46:51 -04:00
|
|
|
# CONTROLLER
|
2015-04-15 11:00:32 -04:00
|
|
|
get '/' do
|
2015-04-26 09:42:23 -04:00
|
|
|
@raids = Raid.order('created_at DESC').page(params[:page])
|
2015-04-25 13:17:47 -04:00
|
|
|
leaders = Leader.all
|
|
|
|
last_update = leaders.first ? leaders.first.created_at : DateTime.new(0)
|
2015-04-26 11:42:19 -04:00
|
|
|
if last_update + 300 < DateTime.now
|
|
|
|
rebuild_leaders
|
2015-04-23 16:09:59 -04:00
|
|
|
end
|
|
|
|
|
2015-04-26 11:42:19 -04:00
|
|
|
leaders = Leader.all.includes(:last_attack, :last_defense)
|
2015-04-26 11:49:08 -04:00
|
|
|
@top20 = leaders.reject { |l| l.last_action } + leaders.select { |l| l.last_action }.sort_by { |l| l.last_action }
|
2015-04-23 16:57:54 -04:00
|
|
|
|
2015-04-15 11:00:32 -04:00
|
|
|
erb :index
|
|
|
|
end
|
|
|
|
|
|
|
|
post '/' do
|
|
|
|
response['Access-Control-Allow-Origin'] = 'http://trugul.com'
|
|
|
|
|
|
|
|
@raid = Raid.new(params[:raid])
|
|
|
|
|
|
|
|
if @raid.save
|
|
|
|
content_type :json
|
|
|
|
{ :message => 'Raid saved' }.to_json
|
|
|
|
else
|
|
|
|
content_type :json
|
|
|
|
{ :message => 'Raid failed to save' }.to_json
|
|
|
|
end
|
|
|
|
end
|
2015-04-28 10:12:01 -04:00
|
|
|
|
2015-04-28 10:41:58 -04:00
|
|
|
get '/bossfight' do
|
|
|
|
@username = params['username'] ? params['username'] : 'mafiaman'
|
2015-04-28 10:19:46 -04:00
|
|
|
user_raids = Raid.for_user(@username)
|
2015-04-28 10:12:01 -04:00
|
|
|
@first_negative = user_raids.first_negative
|
2015-04-28 10:35:42 -04:00
|
|
|
@soldiers_killed = user_raids.soldiers_lost_to_date(@first_negative.created_at)
|
2015-04-28 10:26:23 -04:00
|
|
|
@contributers = user_raids.contributors(@first_negative.created_at)
|
2015-04-28 10:12:01 -04:00
|
|
|
|
|
|
|
erb :bossfight
|
|
|
|
end
|