DG IZ; aspect deletion
This commit is contained in:
parent
1d616f001a
commit
0c7ba49e34
8 changed files with 100 additions and 39 deletions
|
|
@ -26,9 +26,15 @@ class AspectsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
@aspect = Aspect.find_by_id params[:id]
|
||||
@aspect.destroy
|
||||
flash[:notice] = "You are no longer sharing the aspect called #{@aspect.name}."
|
||||
respond_with :location => aspects_url
|
||||
|
||||
begin
|
||||
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
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -7,4 +7,12 @@ module AspectsHelper
|
|||
def link_for_aspect( aspect )
|
||||
link_to aspect.name, aspect
|
||||
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
|
||||
|
|
|
|||
|
|
@ -65,6 +65,15 @@ class User
|
|||
Aspect.create(opts)
|
||||
end
|
||||
|
||||
def drop_aspect( aspect )
|
||||
if aspect.people.size == 0
|
||||
aspect.destroy
|
||||
else
|
||||
raise "Aspect not empty"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def move_friend( opts = {})
|
||||
return true if opts[:to] == opts[:from]
|
||||
friend = Person.first(:_id => opts[:friend_id])
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@
|
|||
.aspect_name
|
||||
%h1{:contenteditable => true}= aspect.name
|
||||
|
||||
.tools
|
||||
= link_to "add a new friend", "#add_request_pane_#{aspect.id}", :class => 'add_request_button'
|
||||
|
|
||||
= link_to "show", aspect_path(aspect)
|
||||
%ul.tools
|
||||
%li= link_to "add a new friend", "#add_request_pane_#{aspect.id}", :class => 'add_request_button'
|
||||
%li= link_to "show", aspect_path(aspect)
|
||||
%li!= remove_link(aspect)
|
||||
|
||||
%ul{:id => aspect.id}
|
||||
%ul.dropzone{:id => aspect.id}
|
||||
|
||||
-if aspect.people.size < 1
|
||||
%li.grey Drag to add people
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ module Diaspora
|
|||
def receive_friend_request(friend_request)
|
||||
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)
|
||||
activate_friend(friend_request.person, aspect)
|
||||
|
||||
|
|
|
|||
|
|
@ -513,20 +513,33 @@ h1.big_text {
|
|||
.requests .aspect_name,
|
||||
.remove .aspect_name {
|
||||
position: relative; }
|
||||
.aspect .aspect_name .tools,
|
||||
.requests .aspect_name .tools,
|
||||
.remove .aspect_name .tools {
|
||||
.aspect .aspect_name ul.tools,
|
||||
.requests .aspect_name ul.tools,
|
||||
.remove .aspect_name ul.tools {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 0;
|
||||
display: inline; }
|
||||
.aspect .aspect_name:hover .tools,
|
||||
.requests .aspect_name:hover .tools,
|
||||
.remove .aspect_name:hover .tools {
|
||||
display: inline; }
|
||||
.aspect ul,
|
||||
.requests ul,
|
||||
.remove ul {
|
||||
display: inline;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none; }
|
||||
.aspect .aspect_name ul.tools li,
|
||||
.requests .aspect_name ul.tools li,
|
||||
.remove .aspect_name ul.tools li {
|
||||
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;
|
||||
margin: 0;
|
||||
margin-bottom: 25px;
|
||||
|
|
@ -574,14 +587,6 @@ h1.big_text {
|
|||
-webkit-box-shadow: 0 1px 3px #333333;
|
||||
-moz-box-shadow: 0 2px 4px #333333;
|
||||
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 {
|
||||
position: fixed;
|
||||
|
|
|
|||
|
|
@ -678,17 +678,29 @@ h1.big_text
|
|||
.aspect_name
|
||||
:position relative
|
||||
|
||||
.tools
|
||||
ul.tools
|
||||
:position absolute
|
||||
:top 10px
|
||||
:right 0
|
||||
:display inline
|
||||
|
||||
&:hover
|
||||
.tools
|
||||
:padding 0
|
||||
:margin 0
|
||||
:list
|
||||
:style none
|
||||
li
|
||||
:display inline
|
||||
:margin
|
||||
:right 1em
|
||||
|
||||
ul
|
||||
&:last-child
|
||||
:margin
|
||||
:right 0
|
||||
|
||||
.grey
|
||||
:color #999
|
||||
:cursor default
|
||||
|
||||
ul.dropzone
|
||||
:min-height 20px
|
||||
:margin 0
|
||||
:bottom 25px
|
||||
|
|
@ -726,12 +738,6 @@ h1.big_text
|
|||
:-moz-box-shadow 0 2px 4px #333
|
||||
:opacity 0.9
|
||||
|
||||
|
||||
.grey
|
||||
:font
|
||||
:style italic
|
||||
:color #666
|
||||
|
||||
#notification_badge
|
||||
:position fixed
|
||||
:bottom 0
|
||||
|
|
|
|||
|
|
@ -22,4 +22,31 @@ describe User do
|
|||
@user.profile.image_url.should == "http://clown.com"
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue