Skip to content

Commit

Permalink
Adds basic+buggy user list
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <[email protected]>
  • Loading branch information
HashNuke committed Mar 12, 2012
1 parent 93e89e2 commit 42c1b9b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/backbone/broadcasters/faye.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Kandan.Broadcasters.FayeBroadcaster
@faye_client.addExtension(auth_extension)
@faye_client.subscribe "/app/activities", (data)=>
console.log "activities", data
$(document).data('active_users', data.data.active_users)
console.log "sets active users", $(document).data('active_users')
Kandan.Helpers.Channels.add_activity({
user: data.data.user,
action: data.event.split("#")[1]
Expand All @@ -24,5 +26,6 @@ class Kandan.Broadcasters.FayeBroadcaster
console.log "Subscribing to #{channel}"
subscription = @faye_client.subscribe channel, (data)=>
Kandan.Helpers.Channels.add_activity(data)
subscription.errback ()->
console.log "Oops! could not connect to the server"
subscription.errback(()->
alert "Oops! could not connect to the server"
)
4 changes: 4 additions & 0 deletions app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ window.Kandan =
Helpers: {}
Broadcasters: {}
Data: {}
Plugins: {}

init: ->
channels = new Kandan.Collections.Channels()
Expand All @@ -29,9 +30,12 @@ window.Kandan =
# TODO move broadcast subscription to a helper
# TODO change this to use the broadcaster from the settings
# TODO set as global to debug. remove later.
# TODO use wildcard channel names
window.broadcaster = new Kandan.Broadcasters.FayeBroadcaster()
for channel in channels.models
window.broadcaster.subscribe "/channels/#{channel.get('id')}"

console.log "plugins", Kandan.Plugins.all()
})


Expand Down
8 changes: 8 additions & 0 deletions app/assets/javascripts/backbone/plugins.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Kandan.Plugins
@plugins: []

@register: (plugin)->
@plugins.push(plugin)

@all: ()->
@plugins
21 changes: 21 additions & 0 deletions app/assets/javascripts/backbone/plugins/user_list.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Kandan.Plugins.UserList
@active_users: ()->
console.log "active users", $(document).data("active_users")
$(document).data("active_users") || []


@render: ()->
users = []
for user in @active_users()
users.push user.first_name
$(".user_list").html(users.join ", ")

@init: ()->
console.log "user list plugin started"
$('body').prepend($("<div class='user_list'></div>"))
@render()
$(document).bind 'changeData', (event, name, value)=>
@render() if name == "active_users"


Kandan.Plugins.register "Kandan.Plugins.UserList"
11 changes: 5 additions & 6 deletions app/assets/javascripts/backbone/post_init.js.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

$(document).ready ->
$(document).bind "changeData", (event, name, value)->
if name == "active_users"
for callback in Kandan.Helpers.ActiveUsers.callbacks
callback()
# $(document).ready ->
# $(document).bind "changeData", (event, name, value)->
# if name == "active_users"
# for callback in Kandan.Helpers.ActiveUsers.callbacks
# callback()
14 changes: 13 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%- Kandan::Config.broadcaster.assets.each do |asset| %>
<%= javascript_include_tag asset %>
<%- end %>

<%= javascript_include_tag "application" %>
<%= javascript_tag do %>
<%- if user_signed_in? %>
Expand All @@ -22,6 +22,18 @@
<%- end %>
<%- end %>

<%= javascript_tag do %>

<%- end %>

<%= javascript_tag do %>
$(document).ready(function(){
$.each(Kandan.Plugins.all(), function(index, plugin){
eval(plugin).init()
})
})
<%- end %>

<%= csrf_meta_tags %>
</head>
<body>
Expand Down

0 comments on commit 42c1b9b

Please sign in to comment.