From d7c5e12d6465d1def05d75df0e913f894a638f3c Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sun, 28 Nov 2010 02:30:25 -0500 Subject: [PATCH] move photo-show js to assets. remove EM::next_tick from controller#create actions. make photo show pages render again. --- app/controllers/photos_controller.rb | 21 +++++++--- app/controllers/status_messages_controller.rb | 4 +- app/views/photos/show.html.haml | 41 ++----------------- config/assets.yml | 2 + public/javascripts/photo-show.js | 32 +++++++++++++++ public/stylesheets/sass/application.sass | 4 +- spec/controllers/comments_controller_spec.rb | 1 - .../status_message_controller_spec.rb | 2 - 8 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 public/javascripts/photo-show.js diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 04f019fc1..2b282ef5c 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -93,15 +93,24 @@ class PhotosController < ApplicationController end def show - @aspect = :none @photo = current_user.find_visible_post_by_id params[:id] - unless @photo - render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 - else - @ownership = current_user.owns? @photo + @parent = @photo.status_message - respond_with @photo + #if photo is not an attachment, fetch comments for self + unless @parent + @parent = @photo end + + comments_hash = Comment.hash_from_post_ids [@parent.id] + person_hash = Person.from_post_comment_hash comments_hash + @comment_hashes = comments_hash[@parent.id].map do |comment| + {:comment => comment, + :person => person_hash[comment.person_id] + } + end + @ownership = current_user.owns? @photo + + respond_with @photo end def edit diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index f5017550d..eeffa1785 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -26,10 +26,10 @@ class StatusMessagesController < ApplicationController raise 'MongoMapper failed to catch a failed save' unless @status_message.id @status_message.photos += photos unless photos.nil? - EM::next_tick {current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids])} + current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids]) for photo in photos - EM::next_tick { current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])} + current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) end respond_to do |format| diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index b423b4214..e945361ce 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -3,34 +3,7 @@ -# the COPYRIGHT file. - content_for :head do - :javascript - $(document).ready( function(){ - $("#edit_photo_toggle").bind('click', function(evt) { - evt.preventDefault(); - $("#photo_edit_options").toggle(); - $(".edit_photo input[type='text']").first().focus(); - }); - - $('.edit_photo').bind('ajax:loading', function(data, json, xhr) { - $("#photo_edit_options").toggle(); - $("#photo_spinner").show(); - $("#show_photo").find("img").fadeTo(200,0.3); - }); - - $('.edit_photo').bind('ajax:failure', function(data, json, xhr) { - alert('Failed to delete photo. Are you sure you own this?'); - $("#show_photo").find("img").fadeTo(200,1); - $("#photo_spinner").hide(); - }); - - $('.edit_photo').bind('ajax:success', function(data, json, xhr) { - json = $.parseJSON(json); - $(".edit_photo input[type='text']").val(json['photo']['caption']); - $("#caption").html(json['photo']['caption']); - $("#show_photo").find("img").fadeTo(200,1); - $("#photo_spinner").hide(); - }); - }); + = include_javascripts :photos = render 'shared/author_info', :person => @photo.person, :post => @photo @@ -79,12 +52,6 @@ %h4= t('_comments') - - if @photo.status_message_id - %div{:id => 'status_message_stream', :class => 'stream show'} - %li.message{:data=>{:guid=>@photo.status_message_id}} - = render "comments/comments", :post_id => @photo.status_message.id, :comments => @photo.status_message.comments - - - else - %div{:id => 'photo_stream', :class => 'stream show'} - %li.message{:data=>{:guid=>@photo.id}} - = render "comments/comments", :post_id => @photo.id, :comments => @photo.comments + %div{:id => 'photo_stream', :class => 'stream show'} + %li.message{:data=>{:guid=>@parent.id}} + = render "comments/comments", :post_id => @parent.id, :comment_hashes => @comment_hashes diff --git a/config/assets.yml b/config/assets.yml index 689b06a6f..f12a95f1c 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -27,6 +27,8 @@ javascripts: - public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js - public/javascripts/aspect-edit.js - public/javascripts/contact-list.js + photos: + - public/javascripts/photo-show.js stylesheets: default: diff --git a/public/javascripts/photo-show.js b/public/javascripts/photo-show.js new file mode 100644 index 000000000..972a16bd4 --- /dev/null +++ b/public/javascripts/photo-show.js @@ -0,0 +1,32 @@ +/* Copyright (c) 2010, Diaspora Inc. This file is + * licensed under the Affero General Public License version 3 or later. See + * the COPYRIGHT file. + */ + +$(document).ready( function(){ + $("#edit_photo_toggle").bind('click', function(evt) { + evt.preventDefault(); + $("#photo_edit_options").toggle(); + $(".edit_photo input[type='text']").first().focus(); + }); + + $('.edit_photo').bind('ajax:loading', function(data, json, xhr) { + $("#photo_edit_options").toggle(); + $("#photo_spinner").show(); + $("#show_photo").find("img").fadeTo(200,0.3); + }); + + $('.edit_photo').bind('ajax:failure', function(data, json, xhr) { + alert('Failed to delete photo. Are you sure you own this?'); + $("#show_photo").find("img").fadeTo(200,1); + $("#photo_spinner").hide(); + }); + + $('.edit_photo').bind('ajax:success', function(data, json, xhr) { + json = $.parseJSON(json); + $(".edit_photo input[type='text']").val(json['photo']['caption']); + $("#caption").html(json['photo']['caption']); + $("#show_photo").find("img").fadeTo(200,1); + $("#photo_spinner").hide(); + }); +}); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 95416213a..47912204b 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -24,7 +24,9 @@ a :color #22AAE0 &:active :color #005D9C - + +p + :word-wrap break-word h1, h2, h3, h4 :color #444 diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 992dd37cf..993a08577 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -15,7 +15,6 @@ describe CommentsController do before do sign_in :user, user - EM.stub!(:next_tick).and_yield(:block) end describe '#create' do diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 66d633eba..3eaf213dd 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -18,8 +18,6 @@ describe StatusMessagesController do request.env["HTTP_REFERER"] = "" sign_in :user, user @controller.stub!(:current_user).and_return(user) - - EM.stub!(:next_tick).and_yield(:block) end describe '#show' do