-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes APIs to fix active users. Listen to unsubscribe instead of di…
…sconnect event. Changes user list to new APIs Signed-off-by: Akash Manohar J <[email protected]>
- Loading branch information
Showing
14 changed files
with
86 additions
and
31 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/backbone/collections/active_users.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Kandan.Collections.ActiveUsers extends Backbone.Collection | ||
url: "active_users" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/assets/javascripts/backbone/helpers/active_users.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Kandan.Helpers.ActiveUsers | ||
|
||
@all: ()-> | ||
# TODO return the active users list | ||
@all: (options)-> | ||
$(document).data("active_users") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Kandan.Modifiers | ||
@modifiers: [] | ||
|
||
@register: (regex, callback)-> | ||
@modifiers.push({regex: regex, callback: callback}) | ||
|
||
@all: ()-> | ||
@modifiers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 12 additions & 14 deletions
26
app/assets/javascripts/backbone/plugins/user_list.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
class Kandan.Plugins.UserList | ||
@active_users: ()-> | ||
console.log "active users", $(document).data("active_users") | ||
$(document).data("active_users") || [] | ||
|
||
@widget_name: "user_list" | ||
|
||
@render: ()-> | ||
users = [] | ||
for user in @active_users() | ||
users.push user.first_name | ||
$(".user_list").html(users.join ", ") | ||
@render: ($el)-> | ||
console.log "rendering user list" | ||
$users = $("<ul></ul>") | ||
|
||
@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" | ||
for user in Kandan.Data.ActiveUsers.all() | ||
$users.append "<li>#{user.first_name} #{user.last_name}</li>" | ||
$el.html($users) | ||
|
||
@init: ()-> | ||
console.log "init user plugin" | ||
Kandan.Widgets.register(@widget_name, "Kandan.Plugins.UserList") | ||
Kandan.Data.ActiveUsers.register_callback "change", ()=> | ||
Kandan.Widgets.render(@widget_name) | ||
|
||
Kandan.Plugins.register "Kandan.Plugins.UserList" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Kandan.Widgets | ||
@widgets: {} | ||
|
||
@register: (widget_name, callback)-> | ||
@widgets[widget_name] = callback | ||
|
||
@all: ()-> | ||
@widgets | ||
|
||
@widget_names: ()-> | ||
widget_names = [] | ||
for widget_name of @all() | ||
widget_names.push(widget_name) if @all().hasOwnProperty(widget_name) | ||
widget_names | ||
|
||
@init_all: ()-> | ||
console.log "widget_names", @widget_names() | ||
@init(widget_name) for widget_name in @widget_names() | ||
|
||
@init: (widget_name)-> | ||
$(".sidebar").append("<div class='#{widget_name}'></div>") | ||
@render(widget_name) | ||
|
||
@render: (widget_name)-> | ||
$widget_el = $(".sidebar .#{widget_name}") | ||
eval(@widgets[widget_name]).render($widget_el) if $widget_el != [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ApisController < ApplicationController | ||
def active_users | ||
respond_to do |format| | ||
format.js { render :json => ActiveUsers.all } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
<%- end %> | ||
|
||
</div> | ||
<div class="sidebar"> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters