Commit 69cc2e431d4a1b76d97692355f5d1baffc965d63

Authored by AntonioTerceiro
1 parent 99872db5

ActionItem543: changing default title of blocks

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2184 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article_block.rb
@@ -36,8 +36,4 @@ class ArticleBlock < Block @@ -36,8 +36,4 @@ class ArticleBlock < Block
36 @article = obj 36 @article = obj
37 end 37 end
38 38
39 - def editable?  
40 - true  
41 - end  
42 -  
43 end 39 end
app/models/block.rb
@@ -47,7 +47,7 @@ class Block < ActiveRecord::Base @@ -47,7 +47,7 @@ class Block < ActiveRecord::Base
47 47
48 # Is this block editable? (Default to <tt>false</tt>) 48 # Is this block editable? (Default to <tt>false</tt>)
49 def editable? 49 def editable?
50 - false 50 + true
51 end 51 end
52 52
53 # must always return false, except on MainBlock clas. 53 # must always return false, except on MainBlock clas.
@@ -63,4 +63,16 @@ class Block &lt; ActiveRecord::Base @@ -63,4 +63,16 @@ class Block &lt; ActiveRecord::Base
63 self.class.name.underscore.gsub('_', '-') 63 self.class.name.underscore.gsub('_', '-')
64 end 64 end
65 65
  66 + def default_title
  67 + ''
  68 + end
  69 +
  70 + def title
  71 + if self[:title].blank?
  72 + self.default_title
  73 + else
  74 + self[:title]
  75 + end
  76 + end
  77 +
66 end 78 end
app/models/communities_block.rb
@@ -4,7 +4,7 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -4,7 +4,7 @@ class CommunitiesBlock &lt; ProfileListBlock
4 _('A block that displays your communities') 4 _('A block that displays your communities')
5 end 5 end
6 6
7 - def title 7 + def default_title
8 _('Communities') 8 _('Communities')
9 end 9 end
10 10
app/models/enterprises_block.rb
1 class EnterprisesBlock < ProfileListBlock 1 class EnterprisesBlock < ProfileListBlock
2 2
3 - def title 3 + def default_title
4 _('Enterprises') 4 _('Enterprises')
5 end 5 end
6 6
app/models/environment_statistics_block.rb
@@ -4,6 +4,10 @@ class EnvironmentStatisticsBlock &lt; Block @@ -4,6 +4,10 @@ class EnvironmentStatisticsBlock &lt; Block
4 _('Statistical overview of your environment.') 4 _('Statistical overview of your environment.')
5 end 5 end
6 6
  7 + def default_title
  8 + _('Statistics for %s') % owner.name
  9 + end
  10 +
7 def content 11 def content
8 users = owner.people.count 12 users = owner.people.count
9 enterprises = owner.enterprises.count 13 enterprises = owner.enterprises.count
@@ -15,7 +19,7 @@ class EnvironmentStatisticsBlock &lt; Block @@ -15,7 +19,7 @@ class EnvironmentStatisticsBlock &lt; Block
15 n_('One community', '%{num} communities', communities) % { :num => communities }, 19 n_('One community', '%{num} communities', communities) % { :num => communities },
16 ] 20 ]
17 21
18 - block_title(_('Statistics for %s') % owner.name) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) 22 + block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n"))
19 end 23 end
20 24
21 end 25 end
app/models/favorite_enterprises_block.rb
1 class FavoriteEnterprisesBlock < ProfileListBlock 1 class FavoriteEnterprisesBlock < ProfileListBlock
2 2
3 - def title 3 + def default_title
4 _('Favorite Enterprises') 4 _('Favorite Enterprises')
5 end 5 end
6 6
app/models/friends_block.rb
@@ -4,7 +4,7 @@ class FriendsBlock &lt; ProfileListBlock @@ -4,7 +4,7 @@ class FriendsBlock &lt; ProfileListBlock
4 _('A block that displays your friends') 4 _('A block that displays your friends')
5 end 5 end
6 6
7 - def title 7 + def default_title
8 _('Friends') 8 _('Friends')
9 end 9 end
10 10
app/models/main_block.rb
@@ -12,4 +12,8 @@ class MainBlock &lt; Block @@ -12,4 +12,8 @@ class MainBlock &lt; Block
12 true 12 true
13 end 13 end
14 14
  15 + def editable?
  16 + false
  17 + end
  18 +
15 end 19 end
app/models/members_block.rb
@@ -4,7 +4,7 @@ class MembersBlock &lt; ProfileListBlock @@ -4,7 +4,7 @@ class MembersBlock &lt; ProfileListBlock
4 _('A block that displays members.') 4 _('A block that displays members.')
5 end 5 end
6 6
7 - def title 7 + def default_title
8 _('Members') 8 _('Members')
9 end 9 end
10 10
app/models/people_block.rb
1 class PeopleBlock < ProfileListBlock 1 class PeopleBlock < ProfileListBlock
2 2
3 - def title 3 + def default_title
4 _('People') 4 _('People')
5 end 5 end
6 6
app/models/products_block.rb
@@ -4,8 +4,12 @@ class ProductsBlock &lt; Block @@ -4,8 +4,12 @@ class ProductsBlock &lt; Block
4 include ActionView::Helpers::UrlHelper 4 include ActionView::Helpers::UrlHelper
5 include ActionController::UrlWriter 5 include ActionController::UrlWriter
6 6
  7 + def default_title
  8 + _('Products')
  9 + end
  10 +
7 def content 11 def content
8 - block_title(_('Products')) + 12 + block_title(title) +
9 content_tag( 13 content_tag(
10 'ul', 14 'ul',
11 products.map {|product| content_tag('li', link_to(product.name, product.url, :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' )), :class => 'product' )} 15 products.map {|product| content_tag('li', link_to(product.name, product.url, :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' )), :class => 'product' )}
@@ -37,8 +41,4 @@ class ProductsBlock &lt; Block @@ -37,8 +41,4 @@ class ProductsBlock &lt; Block
37 end 41 end
38 end 42 end
39 43
40 - def editable?  
41 - true  
42 - end  
43 -  
44 end 44 end
app/models/profile_info_block.rb
@@ -15,4 +15,8 @@ class ProfileInfoBlock &lt; Block @@ -15,4 +15,8 @@ class ProfileInfoBlock &lt; Block
15 end 15 end
16 end 16 end
17 17
  18 + def editable?
  19 + false
  20 + end
  21 +
18 end 22 end
app/models/profile_list_block.rb
@@ -51,7 +51,7 @@ class ProfileListBlock &lt; Block @@ -51,7 +51,7 @@ class ProfileListBlock &lt; Block
51 end 51 end
52 52
53 # the title of the block. Probably will be overriden in subclasses. 53 # the title of the block. Probably will be overriden in subclasses.
54 - def title 54 + def default_title
55 _('People and Groups') 55 _('People and Groups')
56 end 56 end
57 57
app/models/recent_documents_block.rb
@@ -4,13 +4,17 @@ class RecentDocumentsBlock &lt; Block @@ -4,13 +4,17 @@ class RecentDocumentsBlock &lt; Block
4 _('List of recent content') 4 _('List of recent content')
5 end 5 end
6 6
  7 + def default_title
  8 + _('Recent content')
  9 + end
  10 +
7 settings_items :limit 11 settings_items :limit
8 12
9 include ActionController::UrlWriter 13 include ActionController::UrlWriter
10 def content 14 def content
11 docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit) 15 docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit)
12 16
13 - block_title(_('Recent content')) + 17 + block_title(title) +
14 content_tag('ul', docs.map {|item| content_tag('li', link_to(item.title, item.url))}.join("\n")) 18 content_tag('ul', docs.map {|item| content_tag('li', link_to(item.title, item.url))}.join("\n"))
15 19
16 end 20 end
app/models/tags_block.rb
@@ -8,6 +8,10 @@ class TagsBlock &lt; Block @@ -8,6 +8,10 @@ class TagsBlock &lt; Block
8 _('Block listing content count by tag') 8 _('Block listing content count by tag')
9 end 9 end
10 10
  11 + def default_title
  12 + _('tags')
  13 + end
  14 +
11 def help 15 def help
12 _('The tag is created when you add some one to your article. <p/> 16 _('The tag is created when you add some one to your article. <p/>
13 Try to add some tags to some articles and see your tag cloud to grow.') 17 Try to add some tags to some articles and see your tag cloud to grow.')
@@ -17,7 +21,7 @@ class TagsBlock &lt; Block @@ -17,7 +21,7 @@ class TagsBlock &lt; Block
17 tags = owner.tags 21 tags = owner.tags
18 return '' if tags.empty? 22 return '' if tags.empty?
19 23
20 - block_title( _('tags') ) + 24 + block_title(title) +
21 "\n<div class='tag_cloud'>\n"+ 25 "\n<div class='tag_cloud'>\n"+
22 tag_cloud( owner.tags, :id, 26 tag_cloud( owner.tags, :id,
23 owner.generate_url(:controller => 'profile', :action => 'tag'), 27 owner.generate_url(:controller => 'profile', :action => 'tag'),
app/views/box_organizer/_block.rhtml 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<!-- empty -->
app/views/box_organizer/edit.rhtml
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 <% form_tag(:action => 'save', :id => @block.id) do %> 3 <% form_tag(:action => 'save', :id => @block.id) do %>
4 4
  5 + <%= labelled_form_field(_('Custom title for this block: '), text_field(:block, :title)) %>
  6 +
5 <%= render :partial => partial_for_class(@block.class) %> 7 <%= render :partial => partial_for_class(@block.class) %>
6 8
7 <% button_bar do %> 9 <% button_bar do %>
test/unit/article_block_test.rb
@@ -52,8 +52,4 @@ class ArticleBlockTest &lt; Test::Unit::TestCase @@ -52,8 +52,4 @@ class ArticleBlockTest &lt; Test::Unit::TestCase
52 assert_nil block.article_id 52 assert_nil block.article_id
53 end 53 end
54 54
55 - should 'be editable' do  
56 - assert ArticleBlock.new.editable?  
57 - end  
58 -  
59 end 55 end
test/unit/block_test.rb
@@ -32,8 +32,20 @@ class BlockTest &lt; Test::Unit::TestCase @@ -32,8 +32,20 @@ class BlockTest &lt; Test::Unit::TestCase
32 assert_nil Block.new.footer 32 assert_nil Block.new.footer
33 end 33 end
34 34
35 - should 'not be editable by default' do  
36 - assert !Block.new.editable? 35 + should 'provide an empty default title' do
  36 + assert_equal '', Block.new.default_title
37 end 37 end
38 38
  39 + should 'be editable by default' do
  40 + assert Block.new.editable?
  41 + end
  42 +
  43 + should 'have default titles' do
  44 + b = Block.new
  45 + b.expects(:default_title).returns('my title')
  46 + assert_equal 'my title', b.title
  47 + end
  48 +
  49 +
  50 +
39 end 51 end
test/unit/communities_block_test.rb
@@ -6,8 +6,8 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -6,8 +6,8 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
6 assert_kind_of ProfileListBlock, CommunitiesBlock.new 6 assert_kind_of ProfileListBlock, CommunitiesBlock.new
7 end 7 end
8 8
9 - should 'declare its title' do  
10 - assert_not_equal ProfileListBlock.new.title, CommunitiesBlock.new.title 9 + should 'declare its default title' do
  10 + assert_not_equal ProfileListBlock.new.default_title, CommunitiesBlock.new.default_title
11 end 11 end
12 12
13 should 'describe itself' do 13 should 'describe itself' do
test/unit/enterprises_block_test.rb
@@ -6,8 +6,8 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -6,8 +6,8 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
6 assert_kind_of ProfileListBlock, EnterprisesBlock.new 6 assert_kind_of ProfileListBlock, EnterprisesBlock.new
7 end 7 end
8 8
9 - should 'declare its title' do  
10 - assert_not_equal ProfileListBlock.new.title, EnterprisesBlock.new.title 9 + should 'declare its default title' do
  10 + assert_not_equal ProfileListBlock.new.default_title, EnterprisesBlock.new.default_title
11 end 11 end
12 12
13 should 'describe itself' do 13 should 'describe itself' do
test/unit/environment_statistics_block_test.rb
@@ -10,6 +10,15 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase @@ -10,6 +10,15 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase
10 assert_not_equal Block.description, EnvironmentStatisticsBlock.description 10 assert_not_equal Block.description, EnvironmentStatisticsBlock.description
11 end 11 end
12 12
  13 + should 'provide a default title' do
  14 + owner = mock
  15 + owner.expects(:name).returns('my environment')
  16 +
  17 + block = EnvironmentStatisticsBlock.new
  18 + block.expects(:owner).returns(owner)
  19 + assert_equal 'Statistics for my environment', block.title
  20 + end
  21 +
13 should 'generate statistics' do 22 should 'generate statistics' do
14 env = Environment.create!(:name => "My test environment") 23 env = Environment.create!(:name => "My test environment")
15 user1 = create_user('testuser1', :environment_id => env.id) 24 user1 = create_user('testuser1', :environment_id => env.id)
test/unit/favorite_enterprises_block_test.rb
@@ -6,8 +6,8 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase @@ -6,8 +6,8 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase
6 assert_kind_of ProfileListBlock, FavoriteEnterprisesBlock.new 6 assert_kind_of ProfileListBlock, FavoriteEnterprisesBlock.new
7 end 7 end
8 8
9 - should 'declare its title' do  
10 - assert_not_equal ProfileListBlock.new.title, FavoriteEnterprisesBlock.new.title 9 + should 'declare its default title' do
  10 + assert_not_equal ProfileListBlock.new.default_title, FavoriteEnterprisesBlock.new.default_title
11 end 11 end
12 12
13 should 'describe itself' do 13 should 'describe itself' do
test/unit/friends_block_test.rb
@@ -6,8 +6,8 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase @@ -6,8 +6,8 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase
6 assert_not_equal ProfileListBlock.description, FriendsBlock.description 6 assert_not_equal ProfileListBlock.description, FriendsBlock.description
7 end 7 end
8 8
9 - should 'declare its title' do  
10 - assert_not_equal ProfileListBlock.new.title, FriendsBlock.new.title 9 + should 'declare its default title' do
  10 + assert_not_equal ProfileListBlock.new.default_title, FriendsBlock.new.default_title
11 end 11 end
12 12
13 should 'use its own finder' do 13 should 'use its own finder' do
test/unit/main_block_test.rb
@@ -11,4 +11,8 @@ class MainBlockTest &lt; Test::Unit::TestCase @@ -11,4 +11,8 @@ class MainBlockTest &lt; Test::Unit::TestCase
11 ok("MainBlock must not have a content") { MainBlock.new.content.blank? } 11 ok("MainBlock must not have a content") { MainBlock.new.content.blank? }
12 end 12 end
13 13
  14 + should 'not be editable' do
  15 + assert !MainBlock.new.editable?
  16 + end
  17 +
14 end 18 end
test/unit/members_block_test.rb
@@ -10,6 +10,10 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -10,6 +10,10 @@ class MembersBlockTest &lt; Test::Unit::TestCase
10 assert_not_equal ProfileListBlock.description, MembersBlock.description 10 assert_not_equal ProfileListBlock.description, MembersBlock.description
11 end 11 end
12 12
  13 + should 'provide a default title' do
  14 + assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title
  15 + end
  16 +
13 should 'link to "all members" page' do 17 should 'link to "all members" page' do
14 profile = create_user('mytestuser').person 18 profile = create_user('mytestuser').person
15 block = MembersBlock.new 19 block = MembersBlock.new
test/unit/people_block_test.rb
@@ -6,8 +6,8 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase @@ -6,8 +6,8 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase
6 assert_kind_of ProfileListBlock, PeopleBlock.new 6 assert_kind_of ProfileListBlock, PeopleBlock.new
7 end 7 end
8 8
9 - should 'declare its title' do  
10 - assert_not_equal ProfileListBlock.new.title, PeopleBlock.new.title 9 + should 'declare its default title' do
  10 + assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title
11 end 11 end
12 12
13 should 'describe itself' do 13 should 'describe itself' do
test/unit/products_block_test.rb
@@ -11,6 +11,10 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -11,6 +11,10 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
11 assert_kind_of Block, block 11 assert_kind_of Block, block
12 end 12 end
13 13
  14 + should 'provide default title' do
  15 + assert_not_equal Block.new.default_title, ProductsBlock.new.default_title
  16 + end
  17 +
14 should "list owner products" do 18 should "list owner products" do
15 19
16 enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') 20 enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise')
@@ -99,8 +103,4 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -99,8 +103,4 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
99 assert_equal [1, 2], block.product_ids 103 assert_equal [1, 2], block.product_ids
100 end 104 end
101 105
102 - should 'be editable' do  
103 - assert ProductsBlock.new.editable?  
104 - end  
105 -  
106 end 106 end
test/unit/profile_info_block_test.rb
@@ -20,5 +20,9 @@ class ProfileInfoBlockTest &lt; Test::Unit::TestCase @@ -20,5 +20,9 @@ class ProfileInfoBlockTest &lt; Test::Unit::TestCase
20 self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block}) 20 self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block})
21 instance_eval(& block.content) 21 instance_eval(& block.content)
22 end 22 end
  23 +
  24 + should 'not be editable' do
  25 + assert !ProfileInfoBlock.new.editable?
  26 + end
23 27
24 end 28 end
test/unit/profile_list_block_test.rb
@@ -6,6 +6,10 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase @@ -6,6 +6,10 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
6 assert_not_equal Block.description, ProfileListBlock.description 6 assert_not_equal Block.description, ProfileListBlock.description
7 end 7 end
8 8
  9 + should 'provide a default title' do
  10 + assert_not_equal Block.new.default_title, ProfileListBlock.new.default_title
  11 + end
  12 +
9 should 'accept a limit of people to be displayed (and default to 6)' do 13 should 'accept a limit of people to be displayed (and default to 6)' do
10 block = ProfileListBlock.new 14 block = ProfileListBlock.new
11 assert_equal 6, block.limit 15 assert_equal 6, block.limit
test/unit/recent_documents_block_test.rb
@@ -18,6 +18,10 @@ class RecentDocumentsBlockTest &lt; Test::Unit::TestCase @@ -18,6 +18,10 @@ class RecentDocumentsBlockTest &lt; Test::Unit::TestCase
18 assert_not_equal Block.description, RecentDocumentsBlock.description 18 assert_not_equal Block.description, RecentDocumentsBlock.description
19 end 19 end
20 20
  21 + should 'provide a default title' do
  22 + assert_not_equal Block.new.default_title, RecentDocumentsBlock.new.default_title
  23 + end
  24 +
21 should 'output list with links to recent documents' do 25 should 'output list with links to recent documents' do
22 output = block.content 26 output = block.content
23 27
test/unit/tags_block_test.rb
@@ -17,6 +17,10 @@ class TagsBlockTest &lt; Test::Unit::TestCase @@ -17,6 +17,10 @@ class TagsBlockTest &lt; Test::Unit::TestCase
17 assert_not_equal Block.description, TagsBlock.description 17 assert_not_equal Block.description, TagsBlock.description
18 end 18 end
19 19
  20 + should 'provide a default title' do
  21 + assert_not_equal Block.new.default_title, TagsBlock.new.default_title
  22 + end
  23 +
20 should 'generate links to tags' do 24 should 'generate links to tags' do
21 assert_match /profile\/testinguser\/tag\/first-tag/, block.content 25 assert_match /profile\/testinguser\/tag\/first-tag/, block.content
22 assert_match /profile\/testinguser\/tag\/second-tag/, block.content 26 assert_match /profile\/testinguser\/tag\/second-tag/, block.content