Permalink
Browse files

sockets are roughly working

  • Loading branch information...
1 parent e2ea253 commit 0bc8eb319357df802795004b00028ab0cd911ac2 @rauhryan rauhryan committed Jul 3, 2012
View
@@ -31,6 +31,7 @@ class API < Sinatra::Base
end
post '/:user/:repo/movecard' do
+ publish "#{params[:user]}/#{params[:repo]}", "Moved.#{params[:index]}", params[:issue]
json pebble.move_card params[:user], params[:repo], params[:issue], params[:index]
end
View
@@ -65,7 +65,7 @@ def protected!
end
get '/:user/:repo/board/?' do
- @parameters = params.merge({:login => current_user.login})
+ @parameters = params.merge({:login => current_user.login, :socket_backend => socket_backend})
erb :board, :layout => :layout_fluid
end
View
@@ -64,6 +64,15 @@ def gh
@gh ||= Ghee.new(:access_token => user_token)
end
+ def socket_backend
+ return settings.socket_backend if settings.respond_to? :socket_backend
+ end
+
+ def publish(channel,event,payload)
+ return if socket_backend.nil?
+ conn = Faraday.post "#{socket_backend}/hook", {channel:channel, payload:{payload:payload,event:event}}
+ end
+
def json(obj)
content_type :json
JSON.pretty_generate(obj)
@@ -1,4 +1,6 @@
-define(function(){
+define(["socket"],function(socket){
+ var sockets = {};
+
return {
subscribe: function(channel, callback) {
@@ -9,6 +11,22 @@ define(function(){
},
publish: function (channel, payload) {
postal.channel(channel).publish(payload);
+ },
+ socket: function (channel, event, callback) {
+ var theChannel = postal.channel(channel);
+
+ postal.channel(event).subscribe(callback);
+
+ if(sockets[channel]) {
+ return;
+ } else {
+ sockets[channel] = channel;
+ socket.on(channel, function (message) {
+ postal.channel(message.event).publish(message.payload);
+ });
+ }
+
+
}
}
@@ -3,7 +3,7 @@ define(["./views/board"],function (board) {
return {
init: function (params) {
-
+ console.log("params",params)
app.board = new board(params);
@@ -1,5 +1,5 @@
define(["../collections/issues","text!../templates/board.html", "./columnView","./sidebarView"],
- function (issues, template, columnView, sidebarView) {
+ function (issues, template, columnView, sidebarView, postal) {
var calculateTallest = function (){
@@ -1,11 +1,19 @@
-define(["text!../templates/column.html","./cardView"],function(template, CardView){
+define(["text!../templates/column.html","./cardView","../events/postal"],function(template, CardView, postal){
var Column = Backbone.View.extend({
initialize : function(params) {
this.column = params.column;
this.repo = params.repo;
this.user = params.user;
this.latched = false;
+
+ postal.socket(params.user + "/" + params.repo,"Moved." + params.column.index, $.proxy(this.onSocket,this));
+ },
+ onSocket : function(data){
+ var self = this;
+ var card = new CardView({issue : data, user: self.user, repo: self.repo});
+ $("ul",this.el).append(card.render().el);
+
},
render: function(){
var column = $(_.template(template, this.column)),
View
@@ -6,12 +6,12 @@
<!-- This is a special version of jQuery with RequireJS built-in -->
<script src="/scripts/firebugx.js" type="text/javascript" charset="utf-8"></script>
+ <script src="/scripts/require.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/underscore.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/backbone.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/postal.min.js" type="text/javascript" charset="utf-8"></script>
- <script src="/scripts/require.js"></script>
<script src="/scripts/module-loader.js"></script>
<script src="/scripts/bootstrap/bootstrap-dropdown.js"></script>
View
@@ -4,13 +4,23 @@
<title><% yield_content :title %>Huboard</title>
<link rel="shortcut icon" type="image/png" href="/images/favicon.png" />
<!-- This is a special version of jQuery with RequireJS built-in -->
+ <script src="/scripts/require.js"></script>
+
+ <% if @parameters[:socket_backend] %>
+ <script src="<%= @parameters[:socket_backend] %>/socket.io/socket.io.js"></script>
+ <script>
+ define("socket",function() {
+ return io.connect("<%= @parameters[:socket_backend] %>");
+ });
+
+ </script>
+ <% end %>
<script src="/scripts/firebugx.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/underscore.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/backbone.js" type="text/javascript" charset="utf-8"></script>
<script src="/scripts/postal.min.js" type="text/javascript" charset="utf-8"></script>
- <script src="/scripts/require.js"></script>
<script src="/scripts/module-loader.js"></script>
<script src="/scripts/bootstrap/bootstrap-dropdown.js"></script>

0 comments on commit 0bc8eb3

Please sign in to comment.