Skip to content

Commit

Permalink
Removes the added logging and switches some js to camelcase
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information
HashNuke committed Mar 28, 2012
1 parent ef209f7 commit 84ed0d6
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 53 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ group :assets do
gem 'uglifier', '>= 1.0.3'
end

gem "tane", :group => :development, :path => "../tane"

# Test gems, obviously
group :test do
gem 'rspec-rails'
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
PATH
remote: ../tane
specs:
tane (0.0.3)
awesome_print
erubis
highline
launchy
rake
rest-client

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -30,6 +41,7 @@ GEM
multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
awesome_print (1.0.2)
aws-sdk (1.3.8)
httparty (~> 0.7)
json (~> 1.4)
Expand Down Expand Up @@ -105,6 +117,8 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
launchy (2.1.0)
addressable (~> 2.2.6)
mail (2.4.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand Down Expand Up @@ -215,5 +229,6 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
shoulda-matchers
sqlite3
tane!
thin
uglifier (>= 1.0.3)
13 changes: 11 additions & 2 deletions app/assets/javascripts/backbone/broadcasters/faye.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ class Kandan.Broadcasters.FayeBroadcaster
console.log "incoming", message
callback(message)
}
@faye_client.addExtension(auth_extension)

@faye_client.bind "transport:down", ()->
console.log "Comm link to Cybertron is down!"

@faye_client.bind "transport:up", ()->
console.log "Comm link is up!"

@faye_client.addExtension(auth_extension)
@faye_client.subscribe "/app/activities", (data)=>

@faye_client.subscribe "/app/user_activities", (data)=>
$(document).data('active_users', data.data.active_users)
Kandan.Helpers.Channels.add_activity({
user: data.data.user,
action: data.event.split("#")[1]
})

@faye_client.subscribe "/app/channel_activities", (data)=>
$(document).data('active_users', data.data.active_users)
Kandan.Helpers.Channels.add_activity({
user: data.data.user,
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/backbone/data/active_users.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Kandan.Data.ActiveUsers
@register_callback: (event, callback)->
@callbacks[event].push(callback)

@run_callbacks: (event)->
@runCallbacks: (event)->
callback() for callback in @callbacks[event]

@unregister_callback: (event, callback)->
@unregisterCallback: (event, callback)->
delete @callbacks[@callbacks.indexOf(callback)]
@callbacks.filter (element, index, array)->
element!=undefined
8 changes: 4 additions & 4 deletions app/assets/javascripts/backbone/data/channels.js.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Kandan.Data.Channels
@callbacks: {"change": [] }

@active_channel_id: ()->
Kandan.Helpers.Channels.get_active_channel_id()
@activeChannelId: ()->
Kandan.Helpers.Channels.getActiveChannelId()

@all: (callbacks)->
attachments = new Kandan.Collections.Attachments([], {
channel_id: @active_channel_id()
channel_id: @activeChannelId()
})

@run_callbacks: (event)->
@runCallbacks: (event)->
callback() for callback in @callbacks[event]

@register_callback: (event, callback)->
Expand Down
76 changes: 38 additions & 38 deletions app/assets/javascripts/backbone/helpers/channels.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ class Kandan.Helpers.Channels
$tabNav.find(".create_channel").parent().remove()
$tabNav.append("<li>"+$createButton+"</li>")

@pastAutoScrollThreshold: (channel_id)->
currentPosition = @currentScrollPosition channel_id
@pastAutoScrollThreshold: (channelId)->
currentPosition = @currentScrollPosition channelId
totalHeight = $(document).height() - $(window).height()
scrollPercentage = (currentPosition) / (totalHeight)
scrollPercentage > @options.autoScrollThreshold

@scrollToLatestMessage: (channel_id)->
$("#channels-#{channel_id}").scrollTop(100000)
@scrollToLatestMessage: (channelId)->
$("#channels-#{channelId}").scrollTop(100000)

@currentScrollPosition: (channel_id)->
$("#channels-#{channel_id}").scrollTop()
@currentScrollPosition: (channelId)->
$("#channels-#{channelId}").scrollTop()

@channel_activities_el: (channel_id)->
$("#channel-activities-#{channel_id}")
@channel_activities_el: (channelId)->
$("#channel-activities-#{channelId}")

@channel_pagination_el: (channel_id)->
$("#channels-#{channel_id} .pagination")
@channel_pagination_el: (channelId)->
$("#channels-#{channelId} .pagination")

@get_channel_id_from_tab_index: (tab_index)->
@getChannelIdFromTabIndex: (tabIndex)->
$("#channels .ui-tabs-panel")
.eq(tab_index)
.eq(tabIndex)
.data('channel_id')

@selected_tab: ()->
$('#channels').tabs('option', 'selected')

@get_active_channel_id: ()->
@getActiveChannelId: ()->
if $(document).data('active_channel_id') == undefined
return $("#channels .ui-tabs-panel")
.eq(@selected_tab())
Expand All @@ -51,16 +51,16 @@ class Kandan.Helpers.Channels


@deleteChannel: (channelIndex)->
channelID = @get_channel_id_from_tab_index(channelIndex)
channel = new Kandan.Models.Channel({id: channelID})
channelId = @getChannelIdFromTabIndex(channelIndex)
channel = new Kandan.Models.Channel({id: channelId})
return false if @confirmDeletion() == false

channel.destroy({success: ()=>
$("#channels").tabs("remove", channelIndex)
})

@channel_not_exists: (channel_id)->
$("#channels-#{channel_id}").length == 0
@channel_not_exists: (channelId)->
$("#channels-#{channelId}").length == 0


@create_channel_area: (channel)->
Expand All @@ -74,10 +74,10 @@ class Kandan.Helpers.Channels
$(channel_area).data('channel_id', channel.get('id'))


@new_activity_view: (activity_attributes)->
activity = new Kandan.Models.Activity(activity_attributes)
activity_view = new Kandan.Views.ShowActivity({activity: activity})
return activity_view
@new_activity_view: (activityAttributes)->
activity = new Kandan.Models.Activity(activityAttributes)
activityView = new Kandan.Views.ShowActivity({activity: activity})
return activityView


@add_activity: (activity_attributes, state)->
Expand All @@ -90,30 +90,30 @@ class Kandan.Helpers.Channels
@add_notification(activity_attributes)

if activity_attributes.channel_id
channel_id = activity_attributes.channel_id
channelId = activity_attributes.channel_id
else
channel_id = @get_active_channel_id()
@scrollToLatestMessage(channel_id) if @pastAutoScrollThreshold(channel_id)
channelId = @getActiveChannelId()
@scrollToLatestMessage(channelId) if @pastAutoScrollThreshold(channelId)

@add_message: (activity_attributes, state)->
@channel_activities_el(activity_attributes.channel_id)
.append(@new_activity_view(activity_attributes).render().el)
@set_pagination_data(activity_attributes.channel_id)
@add_message: (activityAttributes, state)->
@channel_activities_el(activityAttributes.channel_id)
.append(@new_activity_view(activityAttributes).render().el)
@set_pagination_data(activityAttributes.channel_id)


@add_notification: (activity_attributes)->
$channel_elements = $(".channel-activities")
activity_attributes["created_at"] = new Date()
for el in $channel_elements
$(el).append(@new_activity_view(activity_attributes).render().el)
@add_notification: (activityAttributes)->
$channelElements = $(".channel-activities")
activityAttributes["created_at"] = new Date()
for el in $channelElements
$(el).append(@new_activity_view(activityAttributes).render().el)


@set_pagination_state: (channel_id, more_activities, oldest)->
@channel_pagination_el(channel_id).data('oldest', oldest)
if more_activities == true
@channel_pagination_el(channel_id).show()
@set_pagination_state: (channelId, moreActivities, oldest)->
@channel_pagination_el(channelId).data('oldest', oldest)
if moreActivities == true
@channel_pagination_el(channelId).show()
else
@channel_pagination_el(channel_id).hide()
@channel_pagination_el(channelId).hide()


@set_pagination_data: (channel_id)->
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ window.Kandan =

$(document).bind 'changeData', (element, name, value)->
if(name=="active_users")
Kandan.Data.ActiveUsers.run_callbacks('change')
Kandan.Data.ActiveUsers.runCallbacks('change')

active_users = new Kandan.Collections.ActiveUsers()
active_users.fetch({
Expand All @@ -73,9 +73,9 @@ window.Kandan =
$('#channels').tabs({
select: (event, ui)->
$(document).data('active_channel_id',
Kandan.Helpers.Channels.get_channel_id_from_tab_index(ui.index))
Kandan.Helpers.Channels.getChannelIdFromTabIndex(ui.index))
console.log "channel changed to index", ui.index
Kandan.Data.Channels.run_callbacks('change')
Kandan.Data.Channels.runCallbacks('change')
})

$("#channels").tabs 'option', 'tabTemplate', '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Kandan.Plugins.Attachments
''')

@channel_id: ()->
Kandan.Data.Channels.active_channel_id()
Kandan.Data.Channels.activeChannelId()

@csrf_param: ->
$('meta[name=csrf-param]').attr('content')
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/backbone/views/chatbox.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Kandan.Views.Chatbox extends Backbone.View
activity = new Kandan.Models.Activity({
'content': $chatbox.val(),
'action': 'message',
'channel_id': Kandan.Helpers.Channels.get_active_channel_id()
'channel_id': Kandan.Helpers.Channels.getActiveChannelId()
})

activity.save({},{success: ()->
Expand Down
3 changes: 1 addition & 2 deletions lib/faye_extensions/devise_auth.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class DeviseAuth
def incoming(message, callback)
if message['channel'] == "/meta/subscribe"
puts "MESSAGE: #{message.inspect}"
auth_token = message['ext']['auth_token']
user = User.find_by_authentication_token(auth_token)
if user
Expand All @@ -11,7 +10,7 @@ def incoming(message, callback)
message['error'] = "Invalid auth token"
end
end
puts "Message: #{message.inspect}"
# puts "Message: #{message.inspect}"
callback.call(message)
end

Expand Down

0 comments on commit 84ed0d6

Please sign in to comment.