From 5ef32b7d55947f745256d98658f717da3f91297c Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 12:03:25 -0700 Subject: [PATCH 1/5] DG IZ; a user can repost. aspects are not sent through the websocket. post does not show where it curently is going in its partial --- app/controllers/application_controller.rb | 9 +++++++++ app/views/status_messages/_status_message.html.haml | 6 ++++++ config/routes.rb | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f0ca5bfc8..ac0d11b1c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,4 +37,13 @@ class ApplicationController < ActionController::Base @request_count = Request.for_user(current_user).size if current_user end + def repost + @post = current_user.find_visible_post_by_id params[:id] + if current_user.repost( @post, :to => params[:aspect_ids] ) + flash[:notice] = "Item re-shared." + else + flash[:error] = "Failed to re-share." + end + end + end diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index dcee761d1..ee484f47b 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -22,3 +22,9 @@ - if current_user.owns?(post) .destroy_link = link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "delete" + + %b reshare: + -if @aspects + - for aspect in @aspects + = link_to aspect, repost_path( :id => post.id, :aspect_ids => aspect.id ) + diff --git a/config/routes.rb b/config/routes.rb index ae757499c..1a7a53925 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,12 +7,14 @@ Diaspora::Application.routes.draw do resources :people, :only => [:index, :show, :destroy] resources :users, :except => [:create, :new, :show] - resources :status_messages, :only => [:create, :destroy, :show] + resources :status_messages resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] resources :photos, :except => [:index] resources :albums + match 'repost', :to => 'application#repost', :as => 'repost' + match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' match 'aspects/manage', :to => 'aspects#manage' From 474cf7770815bb1cf87c277cc9727be9e8d627bc Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 15:05:51 -0700 Subject: [PATCH 2/5] DG IZ; reposting now works. redirects to a template missing page, though. --- app/views/shared/_reshare.haml | 27 +++++++++ .../status_messages/_status_message.html.haml | 8 +-- public/stylesheets/application.css | 37 ++++++++++++ public/stylesheets/sass/application.sass | 56 +++++++++++++++++++ 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 app/views/shared/_reshare.haml diff --git a/app/views/shared/_reshare.haml b/app/views/shared/_reshare.haml new file mode 100644 index 000000000..61f48e73b --- /dev/null +++ b/app/views/shared/_reshare.haml @@ -0,0 +1,27 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3. See +-# the COPYRIGHT file. + + + +:javascript + $(".reshare_button").toggle(function(e){ + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeIn(200); + }, function(e) { + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeOut(200); + }); + +.reshare_pane + %span.reshare_button + = link_to "Reshare", "#" + + %ul.reshare_box + - for aspect in current_user.aspects_with_post( post.id ) + %li.currently_sharing= aspect.name + + - for aspect in current_user.aspects + - unless aspect.posts.include? post + %li.aspect_to_share= link_to aspect, repost_path( :id => post.id, :aspect_ids => aspect.id ) + diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index ee484f47b..33764453f 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -17,14 +17,10 @@ \-- = link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments" - = render "comments/comments", :post => post + = render "comments/comments", :post => post - if current_user.owns?(post) .destroy_link = link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "delete" - - %b reshare: - -if @aspects - - for aspect in @aspects - = link_to aspect, repost_path( :id => post.id, :aspect_ids => aspect.id ) + = render "shared/reshare", :post => post, :current_user => current_user diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 9e8561cc2..e95107081 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -171,6 +171,40 @@ li.message { li.message .content div.info .time a { color: #666666; } +.reshare_pane { + margin-left: 5px; + margin-right: 5px; + display: inline; + position: relative; } + .reshare_pane ul.reshare_box { + display: none; + z-index: 10; + position: absolute; + margin-top: 5px; + padding: 0; + background-color: #fafafa; + list-style: none; + border: 5px solid #666666; + -webkit-box-shadow: 0 0 5px #666666; + -moz-box-shadow: 0 0 5px #666666; + text-shadow: 0 2px white; + color: black; } + .reshare_pane ul.reshare_box > li { + font-weight: bold; + padding: 8px; + padding-right: 15px; + border-top: 1px solid white; + border-bottom: 1px solid #cccccc; } + .reshare_pane ul.reshare_box > li:first-child { + border-top: none; } + .reshare_pane ul.reshare_box > li:last-child { + border-bottom: none; } + .reshare_pane ul.reshare_box > li a { + display: block; + height: 100%; } + .reshare_pane ul.reshare_box > li a:hover { + background-color: #eeeeee; } + form { position: relative; font-size: 120%; @@ -270,6 +304,9 @@ ul.comment_set { .destroy_link a, .request_button a { color: #999999; font-weight: normal; } + .destroy_link a:hover, .request_button a:hover { + text-decoration: underline; + background: none; } .destroy_link { display: none; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 88145b6df..30f03f8c0 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -225,6 +225,58 @@ li.message a :color #666 +.reshare_pane + :margin + :left 5px + :right 5px + :display inline + :position relative + + ul.reshare_box + :display none + :z-index 10 + :position absolute + :margin + :top 5px + :padding 0 + + :background + :color #fafafa + + :list + :style none + + :border 5px solid #666 + :-webkit-box-shadow 0 0 5px #666 + :-moz-box-shadow 0 0 5px #666 + + :text-shadow 0 2px #fff + :color #000 + + > li + :font + :weight bold + + :padding 8px + :right 15px + :border + :top 1px solid #fff + :bottom 1px solid #ccc + + &:first-child + :border + :top none + &:last-child + :border + :bottom none + a + :display block + :height 100% + + &:hover + :background + :color #eee + form :position relative @@ -360,6 +412,10 @@ ul.comment_set :color #999 :font :weight normal + &:hover + :text + :decoration underline + :background none .destroy_link :display none From b9be543ef6695ee6737b40f9600815247ce7f5dc Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 15:32:11 -0700 Subject: [PATCH 3/5] DG IZ; reshare redirects to specific page --- app/views/shared/_publisher.haml | 2 +- app/views/shared/_reshare.haml | 4 ++-- public/stylesheets/application.css | 1 + public/stylesheets/sass/application.sass | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 4645ec65c..130f136a9 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -10,7 +10,7 @@ = f.error_messages %p %label{:for => "status_message_message"} Message - = f.text_area :message, :rows => 2 + = f.text_area :message, :rows => 2, :value => params[:prefill] %ul.aspect_selector{ :style => "display:none;"} going to... diff --git a/app/views/shared/_reshare.haml b/app/views/shared/_reshare.haml index 61f48e73b..0b4120d52 100644 --- a/app/views/shared/_reshare.haml +++ b/app/views/shared/_reshare.haml @@ -19,9 +19,9 @@ %ul.reshare_box - for aspect in current_user.aspects_with_post( post.id ) + %li.currently_sharing= aspect.name - for aspect in current_user.aspects - unless aspect.posts.include? post - %li.aspect_to_share= link_to aspect, repost_path( :id => post.id, :aspect_ids => aspect.id ) - + %li.aspect_to_share= link_to aspect, :controller => "aspects", :action => "show", :id => aspect.id, :prefill => post.message diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e95107081..82bbd8b6d 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -177,6 +177,7 @@ li.message { display: inline; position: relative; } .reshare_pane ul.reshare_box { + width: 150px; display: none; z-index: 10; position: absolute; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 30f03f8c0..7c77a0b79 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -233,6 +233,7 @@ li.message :position relative ul.reshare_box + :width 150px :display none :z-index 10 :position absolute From 955d9130a24fdb700b60cb5c241ebde707f5206f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 15:35:23 -0700 Subject: [PATCH 4/5] DG IZ; shift+enter in publisher box submits contents --- public/javascripts/view.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 4713c7164..092d69f16 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -41,6 +41,12 @@ $(document).ready(function(){ } ); + $("#publisher textarea").keydown( function(e) { + if (e.shiftKey && e.keyCode == 13) { + $("#publisher form").submit(); + } + }); + });//end document ready From e9d16cc09b5c6dd2ae256658e0ec8b30fb56f882 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 15:48:50 -0700 Subject: [PATCH 5/5] DG IZ; cleanup --- app/controllers/albums_controller.rb | 2 +- app/controllers/application_controller.rb | 9 --------- app/controllers/photos_controller.rb | 2 +- app/models/user.rb | 8 ++------ config/routes.rb | 2 -- spec/models/user/posting_spec.rb | 17 ++--------------- 6 files changed, 6 insertions(+), 34 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 14adcebe1..d3cad54e2 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -52,7 +52,7 @@ class AlbumsController < ApplicationController data = clean_hash(params[:album]) - if current_user.update_or_repost( @album, data ) + if current_user.update_post( @album, data ) flash[:notice] = "Album #{@album.name} successfully edited." respond_with @album else diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ac0d11b1c..f0ca5bfc8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,13 +37,4 @@ class ApplicationController < ActionController::Base @request_count = Request.for_user(current_user).size if current_user end - def repost - @post = current_user.find_visible_post_by_id params[:id] - if current_user.repost( @post, :to => params[:aspect_ids] ) - flash[:notice] = "Item re-shared." - else - flash[:error] = "Failed to re-share." - end - end - end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 8d383f53a..d0cb1871e 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -88,7 +88,7 @@ class PhotosController < ApplicationController data = clean_hash(params) - if current_user.update_or_repost( @photo, data[:photo] ) + if current_user.update_post( @photo, data[:photo] ) flash[:notice] = "Photo successfully updated." respond_with @photo else diff --git a/app/models/user.rb b/app/models/user.rb index 45f947807..8f74e2233 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -122,13 +122,9 @@ class User post end - def update_or_repost( post, post_hash = {} ) + def update_post( post, post_hash = {} ) if self.owns? post - if post_hash[:aspect_ids] - repost(post, post_hash[:aspect_ids]) if validate_aspect_permissions post_hash[:aspect_ids] - else - post.update_attributes!(post_hash) - end + post.update_attributes(post_hash) end end diff --git a/config/routes.rb b/config/routes.rb index 1a7a53925..0ac115b76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,8 +13,6 @@ Diaspora::Application.routes.draw do resources :photos, :except => [:index] resources :albums - match 'repost', :to => 'application#repost', :as => 'repost' - match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' match 'aspects/manage', :to => 'aspects#manage' diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 6b939b573..d307e7a43 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -65,27 +65,14 @@ describe User do end end - describe '#update_or_repost' do + describe '#update_post' do let!(:album) { user.post(:album, :name => "Profile Photos", :to => aspect.id) } - it 'should repost' do - update_hash = { :aspect_ids => aspect1.id } - user.should_receive(:repost).with(album, update_hash[:aspect_ids]).and_return album - user.update_or_repost( album, update_hash ) - end - it 'should update fields' do update_hash = { :name => "Other Photos" } - user.update_or_repost( album, update_hash ) + user.update_post( album, update_hash ) album.name.should == "Other Photos" end - - it 'should reject posting to an external aspect' do - update_hash = { :aspect_ids => [aspect3.id] } - proc{ - user.update_or_repost( album, update_hash ) - }.should raise_error /Cannot post to an aspect you do not own./ - end end end