DG IZ; aspect deletion

This commit is contained in:
danielvincent 2010-09-16 16:03:18 -07:00
parent 1d616f001a
commit 0c7ba49e34
8 changed files with 100 additions and 39 deletions

View file

@ -26,9 +26,15 @@ class AspectsController < ApplicationController
def destroy def destroy
@aspect = Aspect.find_by_id params[:id] @aspect = Aspect.find_by_id params[:id]
@aspect.destroy
flash[:notice] = "You are no longer sharing the aspect called #{@aspect.name}." begin
respond_with :location => aspects_url current_user.drop_aspect @aspect
flash[:notice] = "#{@aspect.name} was successfully removed."
rescue RuntimeError => e
flash[:error] = e.message
end
respond_with :location => aspects_manage_path
end end
def show def show

View file

@ -7,4 +7,12 @@ module AspectsHelper
def link_for_aspect( aspect ) def link_for_aspect( aspect )
link_to aspect.name, aspect link_to aspect.name, aspect
end end
def remove_link( aspect )
if aspect.people.size == 0
link_to "remove", aspect, :method => :delete
else
"<span class='grey' title='Aspect not empty'>remove</span>"
end
end
end end

View file

@ -65,6 +65,15 @@ class User
Aspect.create(opts) Aspect.create(opts)
end end
def drop_aspect( aspect )
if aspect.people.size == 0
aspect.destroy
else
raise "Aspect not empty"
end
end
def move_friend( opts = {}) def move_friend( opts = {})
return true if opts[:to] == opts[:from] return true if opts[:to] == opts[:from]
friend = Person.first(:_id => opts[:friend_id]) friend = Person.first(:_id => opts[:friend_id])

View file

@ -36,12 +36,12 @@
.aspect_name .aspect_name
%h1{:contenteditable => true}= aspect.name %h1{:contenteditable => true}= aspect.name
.tools %ul.tools
= link_to "add a new friend", "#add_request_pane_#{aspect.id}", :class => 'add_request_button' %li= link_to "add a new friend", "#add_request_pane_#{aspect.id}", :class => 'add_request_button'
| %li= link_to "show", aspect_path(aspect)
= link_to "show", aspect_path(aspect) %li!= remove_link(aspect)
%ul{:id => aspect.id} %ul.dropzone{:id => aspect.id}
-if aspect.people.size < 1 -if aspect.people.size < 1
%li.grey Drag to add people %li.grey Drag to add people

View file

@ -62,7 +62,7 @@ module Diaspora
def receive_friend_request(friend_request) def receive_friend_request(friend_request)
Rails.logger.info("receiving friend request #{friend_request.to_json}") Rails.logger.info("receiving friend request #{friend_request.to_json}")
if request_from_me?(friend_request) if request_from_me?(friend_request) && self.aspect_by_id(friend_request.aspect_id)
aspect = self.aspect_by_id(friend_request.aspect_id) aspect = self.aspect_by_id(friend_request.aspect_id)
activate_friend(friend_request.person, aspect) activate_friend(friend_request.person, aspect)

View file

@ -513,20 +513,33 @@ h1.big_text {
.requests .aspect_name, .requests .aspect_name,
.remove .aspect_name { .remove .aspect_name {
position: relative; } position: relative; }
.aspect .aspect_name .tools, .aspect .aspect_name ul.tools,
.requests .aspect_name .tools, .requests .aspect_name ul.tools,
.remove .aspect_name .tools { .remove .aspect_name ul.tools {
position: absolute; position: absolute;
top: 10px; top: 10px;
right: 0; right: 0;
display: inline; } display: inline;
.aspect .aspect_name:hover .tools, padding: 0;
.requests .aspect_name:hover .tools, margin: 0;
.remove .aspect_name:hover .tools { list-style: none; }
display: inline; } .aspect .aspect_name ul.tools li,
.aspect ul, .requests .aspect_name ul.tools li,
.requests ul, .remove .aspect_name ul.tools li {
.remove ul { display: inline;
margin-right: 1em; }
.aspect .aspect_name ul.tools li:last-child,
.requests .aspect_name ul.tools li:last-child,
.remove .aspect_name ul.tools li:last-child {
margin-right: 0; }
.aspect .grey,
.requests .grey,
.remove .grey {
color: #999999;
cursor: default; }
.aspect ul.dropzone,
.requests ul.dropzone,
.remove ul.dropzone {
min-height: 20px; min-height: 20px;
margin: 0; margin: 0;
margin-bottom: 25px; margin-bottom: 25px;
@ -574,14 +587,6 @@ h1.big_text {
-webkit-box-shadow: 0 1px 3px #333333; -webkit-box-shadow: 0 1px 3px #333333;
-moz-box-shadow: 0 2px 4px #333333; -moz-box-shadow: 0 2px 4px #333333;
opacity: 0.9; } opacity: 0.9; }
.aspect .person .grey,
.aspect .requested_person .grey,
.requests .person .grey,
.requests .requested_person .grey,
.remove .person .grey,
.remove .requested_person .grey {
font-style: italic;
color: #666666; }
#notification_badge { #notification_badge {
position: fixed; position: fixed;

View file

@ -678,17 +678,29 @@ h1.big_text
.aspect_name .aspect_name
:position relative :position relative
.tools ul.tools
:position absolute :position absolute
:top 10px :top 10px
:right 0 :right 0
:display inline :display inline
:padding 0
&:hover :margin 0
.tools :list
:style none
li
:display inline :display inline
:margin
:right 1em
ul &:last-child
:margin
:right 0
.grey
:color #999
:cursor default
ul.dropzone
:min-height 20px :min-height 20px
:margin 0 :margin 0
:bottom 25px :bottom 25px
@ -726,12 +738,6 @@ h1.big_text
:-moz-box-shadow 0 2px 4px #333 :-moz-box-shadow 0 2px 4px #333
:opacity 0.9 :opacity 0.9
.grey
:font
:style italic
:color #666
#notification_badge #notification_badge
:position fixed :position fixed
:bottom 0 :bottom 0

View file

@ -22,4 +22,31 @@ describe User do
@user.profile.image_url.should == "http://clown.com" @user.profile.image_url.should == "http://clown.com"
end end
end end
describe 'aspects' do
it 'should delete an empty aspect' do
@user.aspects.include?(@aspect).should == true
@user.drop_aspect(@aspect)
@user.reload
@user.aspects.include?(@aspect).should == false
end
it 'should not delete an aspect with friends' do
user2 = Factory.create(:user)
aspect2 = user2.aspect(:name => 'stuff')
user2.reload
aspect2.reload
friend_users(@user, Aspect.find_by_id(@aspect.id), user2, Aspect.find_by_id(aspect2.id))
@aspect.reload
@user.aspects.include?(@aspect).should == true
proc{@user.drop_aspect(@aspect)}.should raise_error /Aspect not empty/
@user.reload
@user.aspects.include?(@aspect).should == true
end
end
end end