Commit dedffcc6 by Joenio Costa

ActionItem696: enhancing my networks block

parent 6b8af367
......@@ -5,7 +5,7 @@ class ProfileDesignController < BoxOrganizerController
protect 'edit_profile_design', :profile
def available_blocks
blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock ]
blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock ]
# blocks exclusive for organizations
if profile.has_members?
......@@ -16,7 +16,6 @@ class ProfileDesignController < BoxOrganizerController
if profile.person?
blocks << FriendsBlock
blocks << FavoriteEnterprisesBlock
blocks << MyNetworkBlock
end
# product block exclusive for enterprises in environments that permits it
......
......@@ -15,18 +15,13 @@ class MyNetworkBlock < Block
end
def content
block_title(title) +
content_tag(
'ul',
content_tag('li', link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') )) +
content_tag('li', link_to(n__('One friend', '%s friends', owner.friends.count) %
content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends'))) +
content_tag('li', link_to(n__('One community', '%s communities', owner.communities.size) %
content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities'))) +
content_tag('li', link_to(n_('One tag', '%s tags', owner.tags.size) %
content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')))
)
block = self
lambda do
render :file => 'blocks/my_network', :locals => {
:title => block.title,
:owner => block.owner
}
end
end
end
<%= block_title(title) %>
<%= render :file => 'blocks/my_network/' + owner.class.name.underscore, :locals => { :owner => owner } %>
<ul>
<li><%= link_to(__('Homepage'), owner.url, :class => 'url') %></li>
<li><%= link_to(_('View profile'), owner.public_profile_url) %></li>
<% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %>
<li><%= link_to _('Control panel'), :controller => 'profile_editor' %></li>
<% end %>
</ul>
<div class="my-network-actions">
<%= render :file => 'blocks/profile_info_actions/' + owner.class.name.underscore %>
</div>
<ul>
<li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li>
<li><%= link_to(n_( 'One member', '%s members', owner.members.count) %
content_tag('b', owner.members.count), owner.public_profile_url.merge(:action => 'members') ) %></li>
<li><%= link_to(n_('One tag', '%s tags', owner.tags.size) %
content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li>
</ul>
<ul>
<li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li>
<li><%= link_to(n__('One friend', '%s friends', owner.friends.count) %
content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %></li>
<li><%= link_to(n__('One community', '%s communities', owner.communities.size) %
content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities')) %></li>
<li><%= link_to(n_('One tag', '%s tags', owner.tags.size) %
content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li>
</ul>
......@@ -14,7 +14,6 @@
</div>
</div>
<ul class="profile-info-data">
<li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li>
<li><%= link_to _('View profile'), block.owner.public_profile_url %></li>
......@@ -37,7 +36,7 @@
<% end %>
<div class="profile-info-options">
<%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %>
<%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %>
</div>
</div><!-- end class="vcard" -->
......@@ -22,3 +22,16 @@
color: #600;
}
.my-network-block .my-network-actions ul {
text-align: center;
}
.my-network-actions ul {
padding: 0;
padding-bottom: 10px;
}
.my-network-actions li {
list-style: none;
}
......@@ -143,19 +143,33 @@ class ProfileControllerTest < Test::Unit::TestCase
should 'show a link to own control panel' do
login_as(@profile.identifier)
get :index, :profile => @profile.identifier
assert_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
assert_tag :tag => 'a', :content => 'Control panel'
end
should 'show a link to own control panel in my-network-block if is a group' do
login_as(@profile.identifier)
community = Community.create!(:name => 'my test community')
community.blocks.each{|i| i.destroy}
community.boxes[0].blocks << MyNetworkBlock.new
community.add_admin(@profile)
get :index, :profile => community.identifier
assert_tag :tag => 'a', :content => 'Control panel'
end
should 'not show a link to others control panel' do
login_as(@profile.identifier)
other = create_user('person_1').person
other.blocks.each{|i| i.destroy}
other.boxes[0].blocks << ProfileInfoBlock.new
get :index, :profile => other.identifier
assert_no_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
end
should 'show a link to control panel if user has profile_editor permission' do
should 'show a link to control panel if user has profile_editor permission and is a group' do
login_as(@profile.identifier)
get :index, :profile => @profile.identifier
community = Community.create!(:name => 'my test community')
community.add_admin(@profile)
get :index, :profile => community.identifier
assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}" }, :content => 'Control panel'
end
......@@ -251,8 +265,9 @@ class ProfileControllerTest < Test::Unit::TestCase
end
should 'display "Site map" link for profiles' do
get :index, :profile => 'ze'
assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/ze/sitemap' }
profile = create_user('testmapuser').person
get :index, :profile => profile.identifier
assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/testmapuser/sitemap' }
end
should 'list top level articles in sitemap' do
......
......@@ -19,62 +19,12 @@ class MyNetworkBlockTest < ActiveSupport::TestCase
assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title
end
should 'count articles' do
mock_articles = mock
owner.stubs(:articles).returns(mock_articles)
owner.stubs(:tags).returns({}) # don't let tags call articles
mock_articles.stubs(:count).returns(5)
assert_tag_in_string block.content, :tag => 'li', :descendant => {
:tag => 'a',
:descendant => { :tag => 'b', :content => '5' },
:content => ' articles published',
:attributes => { :href => /\/profile\/testuser\/sitemap$/ }
}
end
should 'count friends' do
mock_friends = mock
owner.stubs(:friends).returns(mock_friends)
mock_friends.stubs(:count).returns(8)
assert_tag_in_string block.content, :tag => 'li', :descendant => {
:tag => 'a',
:descendant => { :tag => 'b', :content => '8' },
:content => ' friends',
:attributes => { :href => /\profile\/testuser\/friends/ }
}
end
should 'count communities' do
mock_communities = mock
owner.stubs(:communities).returns(mock_communities)
mock_communities.stubs(:size).returns(23)
assert_tag_in_string block.content, :tag => 'li', :descendant => {
:tag => 'a',
:descendant => { :tag => 'b', :content => '23' },
:content => ' communities',
:attributes => { :href => /\profile\/testuser\/communities/ }
}
end
should 'count tags' do
mock_tags = mock
owner.stubs(:tags).returns(mock_tags)
mock_tags.stubs(:size).returns(436)
assert_tag_in_string block.content, :tag => 'li', :descendant => {
:tag => 'a',
:descendant => { :tag => 'b', :content => '436' },
:content => ' tags',
:attributes => { :href => /\profile\/testuser\/tags/ }
}
end
should 'display its title' do
block.stubs(:title).returns('My Network')
assert_tag_in_string block.content, :content => 'My Network'
should 'display my-profile' do
self.expects(:render).with(:file => 'blocks/my_network', :locals => {
:title => 'My network',
:owner => owner
})
instance_eval(& block.content)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment