Skip to content

Commit

Permalink
added migration for nap and bedtime
Browse files Browse the repository at this point in the history
  • Loading branch information
txizzle committed Jul 22, 2015
1 parent d996e41 commit 740918e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
63 changes: 61 additions & 2 deletions app/assets/javascripts/home.js.coffee
Expand Up @@ -15,7 +15,7 @@ jQuery ->
ga('send', 'event', 'Error', 'Name', name)
$('#failure-regex').fadeIn()
$('#unregister-input').addClass('regex-error')
else
else if !time
$('#loader_decaf').show()
$('#unregister-input').removeClass('regex-error')
ga('send', 'event', 'Unregister', 'Name', name)
Expand All @@ -41,12 +41,41 @@ jQuery ->
$('#count').addClass('count-change')
)
ga('send', 'event', 'Unregister', 'Success')
else
$('#loader_decaf').show()
$('#unregister-input').removeClass('regex-error')
ga('send', 'event', 'Unregister', 'Name', name)
$.ajax '/decaf/',
type: 'POST'
data:
name: name
'_method': 'delete'
error: (jqXHR) ->
$('#loader_decaf').fadeOut()
$('#failure').fadeIn()
ga('send', 'event', 'Unregister', 'Error')
success: (data, textStatus, jqXHR) ->
$('#loader_decaf').fadeOut()
if jqXHR.status == 201
$('#already-removed').fadeIn()
else
$('#success-removed').fadeIn()
new_count = $('#count').data('count') - 1
$('#count').data('count', new_count)
$('#count').fadeOut(500).fadeIn(500, ->
$('#count').html(new_count)
$('#count').addClass('count-change')
)
ga('send', 'event', 'Unregister', 'Success')
))

$(document).on('click', '#register', ( ->
$('.info').hide()
regex = /^[a-zA-Z0-9\-]+$/
name = $('#register-input').val().toLowerCase().trim();
time = $('#register-time').val();
console.log "hi"
console.log time
if name.length > 30
ga('send', 'event', 'Error', 'Name', name)
$('#failure-name').fadeIn()
Expand All @@ -55,14 +84,43 @@ jQuery ->
ga('send', 'event', 'Error', 'Name', name)
$('#failure-regex').fadeIn()
$('#register-input').addClass('regex-error')
else
else if !time
$('#loader').show()
$('#register-input').removeClass('regex-error')
ga('send', 'event', 'Registration', 'Name', name)
$.ajax '/register',
type: 'POST'
data:
name: name
nap: false
time: "00:00"
error: (jqXHR) ->
$('#loader').fadeOut()
$('#failure').fadeIn()
ga('send', 'event', 'Registration', 'Error')
success: (data, textStatus, jqXHR) ->
$('#loader').fadeOut()
if jqXHR.status == 201
$('#already').fadeIn()
else
$('#success').fadeIn()
new_count = $('#count').data('count') + 1
$('#count').data('count', new_count)
$('#count').fadeOut(500).fadeIn(500, ->
$('#count').html(new_count)
$('#count').addClass('count-change')
)
ga('send', 'event', 'Registration', 'Success')
else
$('#loader').show()
$('#register-input').removeClass('regex-error')
ga('send', 'event', 'Registration', 'Name', name)
$.ajax '/register',
type: 'POST'
data:
name: name
nap: true
time: time
error: (jqXHR) ->
$('#loader').fadeOut()
$('#failure').fadeIn()
Expand All @@ -80,4 +138,5 @@ jQuery ->
$('#count').addClass('count-change')
)
ga('send', 'event', 'Registration', 'Success')

))
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Expand Up @@ -13,7 +13,7 @@ def index
def register
if Site.find_by_name(params[:name])
render json: {}, status: 201
else Site.create(:name => params[:name])
else Site.create(:name => params[:name], :nap=> params[:nap],:bedtime => params[:bedtime])
url = "http://#{params[:name]}.herokuapp.com"
Rails.logger.info "ping #{Time.now} #{url}"
Net::HTTP.get_response(URI.parse(url))
Expand Down
4 changes: 4 additions & 0 deletions app/models/site.rb
@@ -1,2 +1,6 @@
class Site < ActiveRecord::Base
def defaults
self.nap ||= false
self.bedtime||= "00:00"
end
end
3 changes: 3 additions & 0 deletions app/views/home/index.html.erb
Expand Up @@ -15,6 +15,9 @@
<input id="register-input" type="text" placeholder="app name..."></input>
<span id="com">.herokuapp.com</span>
</div>
<div class="sleeptime">
<input id="register-time" type="time">
</div>
<a id="register" class="button">Give my app a caffeine shot every 30 minutes <%= fa_icon("coffee") %></a>

<div class="information">
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20150722022255_add_sleep_to_sites.rb
@@ -0,0 +1,6 @@
class AddSleepToSites < ActiveRecord::Migration
def change
add_column :sites, :nap, :boolean
add_column :sites, :bedtime, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140415141939) do
ActiveRecord::Schema.define(version: 20150722022255) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -20,6 +20,8 @@
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "nap"
t.string "bedtime"
end

end

0 comments on commit 740918e

Please sign in to comment.