Commit dedffcc6a535cfe7a097770c1485e1658565e929

Authored by Joenio Costa
1 parent 6b8af367

ActionItem696: enhancing my networks block

app/controllers/my_profile/profile_design_controller.rb
... ... @@ -5,7 +5,7 @@ class ProfileDesignController < BoxOrganizerController
5 5 protect 'edit_profile_design', :profile
6 6  
7 7 def available_blocks
8   - blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock ]
  8 + blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock ]
9 9  
10 10 # blocks exclusive for organizations
11 11 if profile.has_members?
... ... @@ -16,7 +16,6 @@ class ProfileDesignController < BoxOrganizerController
16 16 if profile.person?
17 17 blocks << FriendsBlock
18 18 blocks << FavoriteEnterprisesBlock
19   - blocks << MyNetworkBlock
20 19 end
21 20  
22 21 # product block exclusive for enterprises in environments that permits it
... ...
app/models/my_network_block.rb
... ... @@ -15,18 +15,13 @@ class MyNetworkBlock &lt; Block
15 15 end
16 16  
17 17 def content
18   - block_title(title) +
19   - content_tag(
20   - 'ul',
21   - content_tag('li', link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
22   - content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') )) +
23   - content_tag('li', link_to(n__('One friend', '%s friends', owner.friends.count) %
24   - content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends'))) +
25   - content_tag('li', link_to(n__('One community', '%s communities', owner.communities.size) %
26   - content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities'))) +
27   - content_tag('li', link_to(n_('One tag', '%s tags', owner.tags.size) %
28   - content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')))
29   - )
  18 + block = self
  19 + lambda do
  20 + render :file => 'blocks/my_network', :locals => {
  21 + :title => block.title,
  22 + :owner => block.owner
  23 + }
  24 + end
30 25 end
31 26  
32 27 end
... ...
app/views/blocks/my_network.rhtml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<%= block_title(title) %>
  2 +
  3 +<%= render :file => 'blocks/my_network/' + owner.class.name.underscore, :locals => { :owner => owner } %>
  4 +
  5 +<ul>
  6 + <li><%= link_to(__('Homepage'), owner.url, :class => 'url') %></li>
  7 + <li><%= link_to(_('View profile'), owner.public_profile_url) %></li>
  8 + <% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %>
  9 + <li><%= link_to _('Control panel'), :controller => 'profile_editor' %></li>
  10 + <% end %>
  11 +</ul>
  12 +
  13 +<div class="my-network-actions">
  14 + <%= render :file => 'blocks/profile_info_actions/' + owner.class.name.underscore %>
  15 +</div>
... ...
app/views/blocks/my_network/community.rhtml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<ul>
  2 + <li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
  3 + content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li>
  4 + <li><%= link_to(n_( 'One member', '%s members', owner.members.count) %
  5 + content_tag('b', owner.members.count), owner.public_profile_url.merge(:action => 'members') ) %></li>
  6 + <li><%= link_to(n_('One tag', '%s tags', owner.tags.size) %
  7 + content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li>
  8 +</ul>
... ...
app/views/blocks/my_network/enterprise.rhtml 0 → 100644
app/views/blocks/my_network/organization.rhtml 0 → 100644
app/views/blocks/my_network/person.rhtml 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<ul>
  2 + <li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) %
  3 + content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li>
  4 + <li><%= link_to(n__('One friend', '%s friends', owner.friends.count) %
  5 + content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %></li>
  6 + <li><%= link_to(n__('One community', '%s communities', owner.communities.size) %
  7 + content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities')) %></li>
  8 + <li><%= link_to(n_('One tag', '%s tags', owner.tags.size) %
  9 + content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li>
  10 +</ul>
... ...
app/views/blocks/profile_info.rhtml
... ... @@ -14,7 +14,6 @@
14 14 </div>
15 15 </div>
16 16  
17   -
18 17 <ul class="profile-info-data">
19 18 <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li>
20 19 <li><%= link_to _('View profile'), block.owner.public_profile_url %></li>
... ... @@ -37,7 +36,7 @@
37 36 <% end %>
38 37  
39 38 <div class="profile-info-options">
40   - <%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %>
  39 + <%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %>
41 40 </div>
42 41  
43 42 </div><!-- end class="vcard" -->
... ...
public/designs/themes/zen3/stylesheets/blocks/my-network-block.css
... ... @@ -22,3 +22,16 @@
22 22 color: #600;
23 23 }
24 24  
  25 +
  26 +.my-network-block .my-network-actions ul {
  27 + text-align: center;
  28 +}
  29 +
  30 +.my-network-actions ul {
  31 + padding: 0;
  32 + padding-bottom: 10px;
  33 +}
  34 +
  35 +.my-network-actions li {
  36 + list-style: none;
  37 +}
... ...
test/functional/profile_controller_test.rb
... ... @@ -143,19 +143,33 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
143 143 should 'show a link to own control panel' do
144 144 login_as(@profile.identifier)
145 145 get :index, :profile => @profile.identifier
146   - assert_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
  146 + assert_tag :tag => 'a', :content => 'Control panel'
  147 + end
  148 +
  149 + should 'show a link to own control panel in my-network-block if is a group' do
  150 + login_as(@profile.identifier)
  151 + community = Community.create!(:name => 'my test community')
  152 + community.blocks.each{|i| i.destroy}
  153 + community.boxes[0].blocks << MyNetworkBlock.new
  154 + community.add_admin(@profile)
  155 + get :index, :profile => community.identifier
  156 + assert_tag :tag => 'a', :content => 'Control panel'
147 157 end
148 158  
149 159 should 'not show a link to others control panel' do
150 160 login_as(@profile.identifier)
151 161 other = create_user('person_1').person
  162 + other.blocks.each{|i| i.destroy}
  163 + other.boxes[0].blocks << ProfileInfoBlock.new
152 164 get :index, :profile => other.identifier
153 165 assert_no_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
154 166 end
155 167  
156   - should 'show a link to control panel if user has profile_editor permission' do
  168 + should 'show a link to control panel if user has profile_editor permission and is a group' do
157 169 login_as(@profile.identifier)
158   - get :index, :profile => @profile.identifier
  170 + community = Community.create!(:name => 'my test community')
  171 + community.add_admin(@profile)
  172 + get :index, :profile => community.identifier
159 173 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}" }, :content => 'Control panel'
160 174 end
161 175  
... ... @@ -251,8 +265,9 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
251 265 end
252 266  
253 267 should 'display "Site map" link for profiles' do
254   - get :index, :profile => 'ze'
255   - assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/ze/sitemap' }
  268 + profile = create_user('testmapuser').person
  269 + get :index, :profile => profile.identifier
  270 + assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/testmapuser/sitemap' }
256 271 end
257 272  
258 273 should 'list top level articles in sitemap' do
... ...
test/unit/my_network_block_test.rb
... ... @@ -19,62 +19,12 @@ class MyNetworkBlockTest &lt; ActiveSupport::TestCase
19 19 assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title
20 20 end
21 21  
22   - should 'count articles' do
23   - mock_articles = mock
24   - owner.stubs(:articles).returns(mock_articles)
25   - owner.stubs(:tags).returns({}) # don't let tags call articles
26   - mock_articles.stubs(:count).returns(5)
27   -
28   - assert_tag_in_string block.content, :tag => 'li', :descendant => {
29   - :tag => 'a',
30   - :descendant => { :tag => 'b', :content => '5' },
31   - :content => ' articles published',
32   - :attributes => { :href => /\/profile\/testuser\/sitemap$/ }
33   - }
34   - end
35   -
36   - should 'count friends' do
37   - mock_friends = mock
38   - owner.stubs(:friends).returns(mock_friends)
39   - mock_friends.stubs(:count).returns(8)
40   -
41   - assert_tag_in_string block.content, :tag => 'li', :descendant => {
42   - :tag => 'a',
43   - :descendant => { :tag => 'b', :content => '8' },
44   - :content => ' friends',
45   - :attributes => { :href => /\profile\/testuser\/friends/ }
46   - }
47   - end
48   -
49   - should 'count communities' do
50   - mock_communities = mock
51   - owner.stubs(:communities).returns(mock_communities)
52   - mock_communities.stubs(:size).returns(23)
53   -
54   - assert_tag_in_string block.content, :tag => 'li', :descendant => {
55   - :tag => 'a',
56   - :descendant => { :tag => 'b', :content => '23' },
57   - :content => ' communities',
58   - :attributes => { :href => /\profile\/testuser\/communities/ }
59   - }
60   - end
61   -
62   - should 'count tags' do
63   - mock_tags = mock
64   - owner.stubs(:tags).returns(mock_tags)
65   - mock_tags.stubs(:size).returns(436)
66   -
67   - assert_tag_in_string block.content, :tag => 'li', :descendant => {
68   - :tag => 'a',
69   - :descendant => { :tag => 'b', :content => '436' },
70   - :content => ' tags',
71   - :attributes => { :href => /\profile\/testuser\/tags/ }
72   - }
73   - end
74   -
75   - should 'display its title' do
76   - block.stubs(:title).returns('My Network')
77   - assert_tag_in_string block.content, :content => 'My Network'
  22 + should 'display my-profile' do
  23 + self.expects(:render).with(:file => 'blocks/my_network', :locals => {
  24 + :title => 'My network',
  25 + :owner => owner
  26 + })
  27 + instance_eval(& block.content)
78 28 end
79 29  
80 30 end
... ...