From dc5b321b62713d3da5c623829e8aa10a6da66037 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 30 Jun 2010 00:20:44 -0700 Subject: [PATCH 1/4] sorry for the monster commit.... 4 small chores...1) moved tons of dynamic javascript to haml partials in the new js view folder, and moved some of the js that got put in the application layout into view.js 2. set up a static config prefrence loader in initializers, loaded from yaml 3) fixed the top right login text from being pushed over. 4) fixed a bug when no user is on the node and someone hits the landing page.... you still cant create a new user from there, but now at least it doesnt blow up. --- app/controllers/application_controller.rb | 1 + app/controllers/blogs_controller.rb | 1 - app/views/js/_google_a_js.haml | 11 ++++ app/views/js/_websocket_js.haml | 27 +++++++++ app/views/layouts/application.html.haml | 68 ++--------------------- app/views/layouts/session_wall.html.haml | 13 +++-- config/app_config.yml | 11 ++++ config/initializers/load_app_config.rb | 2 + config/initializers/socket.rb | 7 ++- public/javascripts/view.js | 19 +++++++ public/stylesheets/application.css | 6 +- public/stylesheets/sass/application.sass | 4 +- 12 files changed, 92 insertions(+), 78 deletions(-) create mode 100644 app/views/js/_google_a_js.haml create mode 100644 app/views/js/_websocket_js.haml create mode 100644 config/app_config.yml create mode 100644 config/initializers/load_app_config.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7f0ca264e..890d32a1c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery :except => :receive layout 'application' + before_filter :set_friends layout :layout_by_resource diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 333cb694a..7ca1f2441 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,7 +1,6 @@ class BlogsController < ApplicationController before_filter :authenticate_user! - def index @blogs = Blog.paginate :page => params[:page], :order => 'created_at DESC' end diff --git a/app/views/js/_google_a_js.haml b/app/views/js/_google_a_js.haml new file mode 100644 index 000000000..d160024f4 --- /dev/null +++ b/app/views/js/_google_a_js.haml @@ -0,0 +1,11 @@ +:javascript + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-17207587-1']); + _gaq.push(['_setDomainName', '#{root_url}']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); \ No newline at end of file diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml new file mode 100644 index 000000000..00d130029 --- /dev/null +++ b/app/views/js/_websocket_js.haml @@ -0,0 +1,27 @@ +- if user_signed_in? + - unless request.user_agent.include? "Safari" ||"Chrome" + = javascript_include_tag 'FABridge', 'swfobject', 'web_socket' + :javascript + WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; + :javascript + $(document).ready(function(){ + function debug(str){ $("#debug").append("

" + str); }; + + ws = new WebSocket("ws://#{request.host}:8080/"); + ws.onmessage = function(evt) { + var obj = jQuery.parseJSON(evt.data); + debug("got a " + obj['class']); + if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { + $("#stream").prepend( + $(obj['html']).fadeIn("fast", function(){ + $("#stream label:first").inFieldLabels(); + } + ) + ); + }; + }; + ws.onclose = function() { debug("socket closed"); }; + ws.onopen = function() { + ws.send(location.pathname); + debug("connected..."); + };}); \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 2cf2f02d6..94b5b87dc 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,8 @@ %html %head %title - = "diaspora" + = "diaspora " + = "- #{User.first.real_name}" if User.first %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } @@ -11,73 +12,12 @@ /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" = javascript_include_tag 'jquery142', 'rails', 'view', 'publisher' = javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel' - :javascript - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-17207587-1']); - _gaq.push(['_setDomainName', '#{root_url}']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - - - unless request.user_agent.include? "Safari" ||"Chrome" - = javascript_include_tag 'FABridge', 'swfobject', 'web_socket' - :javascript - WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; - + = render "js/google_a_js" + = render "js/websocket_js" = csrf_meta_tag = yield(:head) - - if user_signed_in? - :javascript - $(document).ready(function(){ - function debug(str){ $("#debug").append("

" + str); }; - - ws = new WebSocket("ws://#{request.host}:8080/"); - ws.onmessage = function(evt) { - var obj = jQuery.parseJSON(evt.data); - debug("got a " + obj['class']); - if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { - $("#stream").prepend( - $(obj['html']).fadeIn("fast", function(){ - $("#stream label:first").inFieldLabels(); - } - ) - ); - }; - }; - ws.onclose = function() { debug("socket closed"); }; - ws.onopen = function() { - ws.send(location.pathname); - debug("connected..."); - }; - - - $("#stream li").hover(function() { - $(this).children(".destroy_link").fadeIn(0); - }, function() { - $(this).children(".destroy_link").fadeOut(0); - }); - - // in field label plugin - - $(".show_post_comments").click( function() { - if( $(this).hasClass( "visible" )) { - $(this).html($(this).html().replace("hide", "show")); - $(this).parents("li").children(".comments").fadeOut(100); - } else { - $(this).html($(this).html().replace("show", "hide")); - $(this).parents("li").children(".comments").fadeIn(100); - } - $(this).toggleClass( "visible" ); - }); - - - }); = javascript_include_tag 'satisfaction' , 'satisfaction-display' %body diff --git a/app/views/layouts/session_wall.html.haml b/app/views/layouts/session_wall.html.haml index dfcd5d12c..3838ba0d2 100644 --- a/app/views/layouts/session_wall.html.haml +++ b/app/views/layouts/session_wall.html.haml @@ -18,10 +18,13 @@ .container - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" - - %div#huge_text - welcome back, - %span - = User.first.real_name.downcase + - if User.first + %div#huge_text + welcome back, + %span + = User.first.real_name.downcase + -else + %div#huge_text + you need to add a user first! = yield diff --git a/config/app_config.yml b/config/app_config.yml new file mode 100644 index 000000000..56f842006 --- /dev/null +++ b/config/app_config.yml @@ -0,0 +1,11 @@ +development: + debug: true + socket_port: 8080 + +test: + debug: false + socket_port: 8081 + +production: + debug: false + socket_port: 8080 diff --git a/config/initializers/load_app_config.rb b/config/initializers/load_app_config.rb new file mode 100644 index 000000000..4e5bbdd9d --- /dev/null +++ b/config/initializers/load_app_config.rb @@ -0,0 +1,2 @@ +raw_config = File.read("#{Rails.root}/config/app_config.yml") +APP_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 3c716ef05..105314b8a 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -11,7 +11,10 @@ module WebSocket SocketRenderer.instantiate_view end - EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>true) do |ws| + EventMachine::WebSocket.start( + :host => "0.0.0.0", + :port => APP_CONFIG[:socket_port], + :debug =>APP_CONFIG[:debug]) do |ws| ws.onopen { sid = @channel.subscribe { |msg| ws.send msg } @@ -25,6 +28,4 @@ module WebSocket def self.update_clients(object) @channel.push(SocketRenderer.view_hash(object).to_json) if @channel end - - end diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 4ec1ed95b..3b062b36a 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -53,4 +53,23 @@ $(document).ready(function(){ $('#flash_notice, #flash_error, #flash_alert').delay(1500).slideUp(130); + $("#stream li").hover(function() { + $(this).children(".destroy_link").fadeIn(0); + }, function() { + $(this).children(".destroy_link").fadeOut(0); + }); + + // in field label plugin + + $(".show_post_comments").click( function() { + if( $(this).hasClass( "visible" )) { + $(this).html($(this).html().replace("hide", "show")); + $(this).parents("li").children(".comments").fadeOut(100); + } else { + $(this).html($(this).html().replace("show", "hide")); + $(this).parents("li").children(".comments").fadeIn(100); + } + $(this).toggleClass( "visible" ); + }); + });//end document ready diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 2145ea585..f80f31bc0 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -64,10 +64,10 @@ header { border: none; top: 10px; } header #session_action { - position: absolute; - right: 300px; + float: right; font-size: 110%; - top: 7px; } + top: 7px; + padding-right: 10px; } header #session_action a { color: #cccccc; border: none; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 201c5bf58..601794136 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -71,14 +71,14 @@ header :top 10px #session_action - :position absolute - :right 300px + :float right :font :size 110% :top 7px a :color #ccc :border none + :padding-right 10px #show_filters :z-index 100 From 340a57ea6dc933e214b8662c4358282dd631836f Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 30 Jun 2010 08:06:30 -0700 Subject: [PATCH 2/4] RS; figured out recursive serialization with ROXML, posts and comments now serialize with their persons --- app/models/comment.rb | 2 +- app/models/person.rb | 3 ++- app/models/post.rb | 1 + app/models/profile.rb | 6 +++++- spec/models/person_spec.rb | 10 ++++++++++ spec/models/post_spec.rb | 7 ++++++- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 1029e4bc3..af10726bd 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,7 +2,7 @@ class Comment include MongoMapper::Document include ROXML xml_accessor :text - + xml_accessor :person, :as => Person key :text, String key :target, String diff --git a/app/models/person.rb b/app/models/person.rb index 73161780b..1e7dd0f2b 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -4,7 +4,8 @@ class Person xml_accessor :email xml_accessor :url - + xml_accessor :profile, :as => Profile + key :email, String key :url, String diff --git a/app/models/post.rb b/app/models/post.rb index e5974f4c6..5cd679503 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -6,6 +6,7 @@ class Post include Diaspora::Webhooks xml_accessor :_id + xml_accessor :person, :as => Person key :person_id, ObjectId diff --git a/app/models/profile.rb b/app/models/profile.rb index 0e4e6c913..13febaaf3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,6 +1,10 @@ class Profile include MongoMapper::Document - + include ROXML + + xml_accessor :first_name + xml_accessor :last_name + key :first_name, String key :last_name, String diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 97ed93418..59ef0c21c 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,4 +13,14 @@ describe Person do friend.valid?.should == false end + it 'should serialize to xml' do + friend_one = Factory.create(:friend) + xml = friend_one.to_xml.to_s + (xml.include? "friend").should == true + end + it 'should have a profile in its xml' do + user = Factory.create(:user) + xml = user.to_xml.to_s + (xml.include? "first_name").should == true + end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index b3df7552f..93deadc99 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -77,6 +77,11 @@ describe Post do friend_posts.count.should == 2 end end - + describe 'xml' do + it 'should serialize to xml with its person' do + message = Factory.create(:status_message, :person => @user) + (message.to_xml.to_s.include? @user.email).should == true + end + end end From 2b0659e21d0cd42ed6ce3b8dddab813a7822615f Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 30 Jun 2010 08:28:24 -0700 Subject: [PATCH 3/4] Comment toggle now applies to socketed posts --- public/javascripts/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 3b062b36a..0a916e19a 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -61,7 +61,7 @@ $(document).ready(function(){ // in field label plugin - $(".show_post_comments").click( function() { + $(".show_post_comments").live('click', function() { if( $(this).hasClass( "visible" )) { $(this).html($(this).html().replace("hide", "show")); $(this).parents("li").children(".comments").fadeOut(100); From 3d976ca47eb9c28fa093f97dae411da1e3955ff6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 30 Jun 2010 08:36:51 -0700 Subject: [PATCH 4/4] RS, a little bit of autolinking in statuses and comments --- app/views/comments/_comment.html.haml | 2 +- app/views/status_messages/_status_message.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 3cf43c723..eb97c4123 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -1,6 +1,6 @@ %li.comment{:id => comment.id} %span.from = link_to_person comment.person - = comment.text + = auto_link comment.text %div.time = "#{time_ago_in_words(comment.updated_at)} ago" diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index e058eb5fb..f90687e61 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -1,7 +1,7 @@ %li.message{:id => post.id, :class => ("mine" if mine?(post))} %span.from = link_to_person post.person - = post.message + = auto_link post.message %div.time = link_to(how_long_ago(post), status_message_path(post))