Skip to content

Commit d5e2f4d

Browse files
committed
Adds search; Faye callbacks for transport down and up; Some minor refactor to support search
Signed-off-by: Akash Manohar J <akash@akash.im>
1 parent 7144978 commit d5e2f4d

File tree

8 files changed

+59
-38
lines changed

8 files changed

+59
-38
lines changed

Gemfile.lock

+8-12
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,32 @@ GEM
8585
eco-source
8686
execjs
8787
eco-source (1.1.0.rc.1)
88-
em-http-request (1.0.1)
89-
addressable (>= 2.2.3)
90-
cookiejar
91-
em-socksify
92-
eventmachine (>= 1.0.0.beta.4)
93-
http_parser.rb (>= 0.5.3)
94-
em-socksify (0.1.0)
95-
eventmachine
88+
em-http-request (0.3.0)
89+
addressable (>= 2.0.0)
90+
escape_utils
91+
eventmachine (>= 0.12.9)
9692
erubis (2.7.0)
97-
eventmachine (1.0.0.beta.4)
93+
escape_utils (0.2.4)
94+
eventmachine (0.12.10)
9895
execjs (1.3.0)
9996
multi_json (~> 1.0)
10097
factory_girl (2.6.1)
10198
activesupport (>= 2.3.9)
10299
factory_girl_rails (1.7.0)
103100
factory_girl (~> 2.6.0)
104101
railties (>= 3.0.0)
105-
faye (0.8.0)
102+
faye (0.8.1)
106103
cookiejar (>= 0.3.0)
107104
em-http-request (>= 0.3.0)
108105
eventmachine (>= 0.12.0)
109106
faye-websocket (>= 0.4.0)
110107
rack (>= 1.0.0)
111108
yajl-ruby (>= 1.0.0)
112-
faye-websocket (0.4.1)
109+
faye-websocket (0.4.4)
113110
eventmachine (>= 0.12.0)
114111
ffi (1.0.11)
115112
highline (1.6.11)
116113
hike (1.2.1)
117-
http_parser.rb (0.5.3)
118114
httparty (0.8.1)
119115
multi_json
120116
multi_xml

app/assets/javascripts/backbone/broadcasters/faye.js.coffee

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class Kandan.Broadcasters.FayeBroadcaster
1111
}
1212
callback(message)
1313
}
14+
@faye_client.bind "transport:down", ()->
15+
console.log "Comm link to Cybertron is down!"
16+
17+
@faye_client.bind "transport:up", ()->
18+
console.log "Comm link is up!"
19+
1420
@faye_client.addExtension(auth_extension)
1521
@faye_client.subscribe "/app/activities", (data)=>
1622
$(document).data('active_users', data.data.active_users)
@@ -21,7 +27,6 @@ class Kandan.Broadcasters.FayeBroadcaster
2127

2228

2329
subscribe: (channel)->
24-
console.log "Subscribing to #{channel}"
2530
subscription = @faye_client.subscribe channel, (data)=>
2631
Kandan.Helpers.Channels.add_activity(data)
2732
subscription.errback(()->

app/assets/javascripts/backbone/data/active_users.js.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class Kandan.Data.ActiveUsers
77
@register_callback: (event, callback)->
88
@callbacks[event].push(callback)
99

10+
@run_callbacks: (event)->
11+
callback() for callback in @callbacks[event]
12+
1013
@unregister_callback: (event, callback)->
1114
delete @callbacks[@callbacks.indexOf(callback)]
1215
@callbacks.filter (element, index, array)->

app/assets/javascripts/backbone/kandan.js.coffee

+1-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ window.Kandan =
3333

3434
$(document).bind 'changeData', (element, name, value)->
3535
if(name=="active_users")
36-
callback() for callback in Kandan.Data.ActiveUsers.callbacks.change
36+
Kandan.Data.ActiveUsers.run_callbacks('change')
3737

3838
active_users = new Kandan.Collections.ActiveUsers()
3939
active_users.fetch({
@@ -55,14 +55,6 @@ window.Kandan =
5555
Kandan.Data.Channels.run_callbacks('change')
5656
})
5757

58-
# NOTE render widgets only after the chat area is rendered
5958
Kandan.Widgets.init_all()
6059
})
61-
62-
63-
6460
})
65-
66-
67-
$(document).ready ->
68-
Kandan.init()

app/controllers/main_controller.rb

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ class MainController < ApplicationController
22
before_filter :authenticate_user!
33

44
def index
5+
# TODO this isn't being used right now. use this for faster app
56
@channels = Channel.includes(:activities => :user).all
67
end
8+
9+
def search
10+
minimum_query_length = 3
11+
12+
if params[:query] and params[:query].length >= minimum_query_length
13+
@activities = Activity.includes(:user).where("content LIKE ?", "%#{params[:query]}%").limit(params[:limit] || 100).all
14+
end
15+
16+
respond_to do |format|
17+
format.html
18+
format.json { render :json => @activities.to_json(:include => :user) }
19+
end
20+
end
721
end

app/views/main/index.html.erb

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
<div class="container">
1+
<%= javascript_tag do %>
2+
$(document).ready(function(){
3+
Kandan.init()
4+
})
5+
<%- end %>
26

3-
<%= javascript_tag do %>
4-
$(function()
5-
{
6-
var channels_json = <%= @channels.to_json(
7-
:include => {
8-
:activities => {
9-
:include=>:user
10-
}
11-
}).html_safe %>
12-
});
13-
<%- end %>
14-
15-
</div>
16-
<div class="sidebar">
17-
</div>
7+
<div class="container"></div>
8+
<div class="sidebar"></div>

app/views/main/search.html.erb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<%= javascript_tag do %>
2+
$(document).ready(function(){
3+
Kandan.Plugins.init_all()
4+
activities = <%= @activities.to_json(:include => :user).html_safe %>;
5+
6+
$.each(activities, function(index, activity_attributes) {
7+
activity = new Kandan.Models.Activity(activity_attributes)
8+
activity_view = new Kandan.Views.ShowActivity({activity: activity});
9+
$('.activities').html(activity_view.render().el);
10+
})
11+
})
12+
13+
<%- end %>
14+
15+
<div class='activities'>
16+
</div>
17+
18+

config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
root :to => "main#index"
44
devise_for :users
55

6+
get '/search' => "main#search"
7+
68
resources :channels do
79
resources :activities
810
resources :attachments

0 commit comments

Comments
 (0)