Commit fcffa9a4a7b8ead8bddb91a4005ab50088eca525

Authored by MoisesMachado
1 parent ab1cffa8

ActionItem135: added profile info block and merged enterprises_block into list_block


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1083 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/admin/edit_template_controller.rb
... ... @@ -4,7 +4,8 @@ class EditTemplateController < AdminController
4 4  
5 5 def block_types
6 6 %w[
7   - FavoriteLinksProfile
  7 + FavoriteLinks
  8 + ListBlock
8 9 ]
9 10 end
10 11  
... ...
app/controllers/application.rb
... ... @@ -42,7 +42,8 @@ class ApplicationController < ActionController::Base
42 42  
43 43 def render_not_found(path = nil)
44 44 @path ||= request.path
45   - render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false
  45 + raise "#{@path} not found"
  46 +# render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false
46 47 end
47 48  
48 49 def load_admin_controller
... ...
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -11,7 +11,7 @@ class ProfileEditorController < MyProfileController
11 11 %w[
12 12 FavoriteLinksProfile
13 13 ListBlock
14   - EnterprisesBlock
  14 + ProfileInfoBlock
15 15 ]
16 16 end
17 17  
... ...
app/design_blocks/enterprises_block/controllers/enterprises_block_controller.rb
... ... @@ -1,51 +0,0 @@
1   -class EnterprisesBlockController < ApplicationController
2   -
3   - # This controller always has the object @design_block available to it.
4   - # The method acts_as_design_block load a before_filter that always load
5   - # this object.
6   -
7   - needs_profile
8   -
9   - acts_as_design_block
10   -
11   - # You must have a hash on format:
12   - # {
13   - # 'action name' => 'How the action will be displayed on menu'
14   - # }
15   - #
16   - # EX:
17   - # CONTROL_ACTION_OPTIONS = {
18   - # 'design_edit' => _('Edit'),
19   - # 'manage_links' => _('Manage Links')
20   - # }
21   - #
22   - # This hash will define the options menu on edit mode.
23   - CONTROL_ACTION_OPTIONS = {
24   -# 'edit' => _('Edit')
25   - }
26   -
27   -
28   - ###########################
29   - # Mandatory methods
30   - ###########################
31   -
32   - def index
33   - @enterprises = Enterprise.find(:all)
34   - design_render
35   - end
36   -
37   - ###########################
38   - # Other Sample of methods
39   - ###########################
40   -
41   -# def edit
42   -# design_render_on_edit
43   -# end
44   -
45   -# def save
46   -# @design_block.update_attributes(params[:design_block])
47   -# design_render_on_edit :nothing => true
48   -# end
49   -
50   -
51   -end
app/design_blocks/enterprises_block/helpers/enterprises_block_helper.rb
... ... @@ -1,3 +0,0 @@
1   -module EnterprisesBlockHelper
2   -
3   -end
app/design_blocks/enterprises_block/helpers/list_block_helper.rb
... ... @@ -1,3 +0,0 @@
1   -module ListBlockHelper
2   -
3   -end
app/design_blocks/enterprises_block/models/enterprises_block.rb
... ... @@ -1,15 +0,0 @@
1   -class EnterprisesBlock < Design::Block
2   -
3   - # Define an specific method using the settings hash serialized
4   - # variable to keep the value desired by method.
5   - #
6   - # EX:
7   - # def max_number_of_element= value
8   - # self.settings[:limit_number] = value
9   - # end
10   -
11   - def self.description
12   - _('Enterprises Block')
13   - end
14   -
15   -end
app/design_blocks/enterprises_block/views/index.rhtml
... ... @@ -1,5 +0,0 @@
1   -<ul class='enterprises_list_block'>
2   - <% @enterprises.each do |e| %>
3   - <li> <%= link_to_homepage(content_tag('span', e.name), e.identifier) %> </li>
4   - <% end %>
5   -</ul>
app/design_blocks/list_block/controllers/list_block_controller.rb
... ... @@ -5,7 +5,7 @@ class ListBlockController &lt; ApplicationController
5 5 # this object.
6 6  
7 7 needs_profile
8   -
  8 +
9 9 acts_as_design_block
10 10  
11 11 # You must have a hash on format:
... ... @@ -30,8 +30,8 @@ class ListBlockController &lt; ApplicationController
30 30 ###########################
31 31  
32 32 def index
33   - @people = @design_block.people
34   - design_render
  33 + @elements = @design_block.elements
  34 + design_render :action => @design_block.view
35 35 end
36 36  
37 37 ###########################
... ... @@ -40,6 +40,7 @@ class ListBlockController &lt; ApplicationController
40 40  
41 41  
42 42 def edit
  43 + @elements_types = @design_block.elements_types
43 44 design_render_on_edit :controller => 'list_block', :action => 'edit'
44 45 end
45 46  
... ...
app/design_blocks/list_block/models/list_block.rb
... ... @@ -20,8 +20,26 @@ class ListBlock &lt; Design::Block
20 20 self.settings[:limit_number]
21 21 end
22 22  
23   - def people
24   - Person.find(:all, :limit => limit_number)
  23 + def elements_types
  24 + ['Person', 'Enterprise']
  25 + end
  26 +
  27 + def element_type
  28 + self.settings[:element_type]
  29 + end
  30 +
  31 + def element_type= value
  32 + return nil unless elements_types.include?(value)
  33 + self.settings[:element_type] = value
  34 + end
  35 +
  36 + def elements
  37 + return nil unless element_type
  38 + self.element_type.constantize.find(:all, :limit => limit_number)
  39 + end
  40 +
  41 + def view
  42 + element_type.to_s.underscore
25 43 end
26 44  
27 45 end
... ...
app/design_blocks/list_block/views/edit.rhtml
... ... @@ -4,10 +4,15 @@
4 4 <p>
5 5 <label for="design_block_title"> <%= _("Title") %> </label>
6 6 <%= text_field 'design_block', 'title'%>
  7 + </p>
  8 +
  9 + <p>
  10 + <label for="design_block_type"> <%= _("Type of objects to list") %> </label>
  11 + <%= select 'design_block', 'element_type', @elements_types %>
7 12 </p>
8 13  
9 14 <p>
10   - <label for="design_block_limit_number"> <%= _("Max number of people") %> </label>
  15 + <label for="design_block_limit_number"> <%= _("Max number of elements") %> </label>
11 16 <%= text_field 'design_block', 'limit_number'%>
12 17 </p>
13 18  
... ...
app/design_blocks/list_block/views/enterprise.rhtml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<ul class='enterprises_list_block'>
  2 + <% @elements.each do |p| %>
  3 + <li> <%= link_to_homepage(content_tag('span',p.name) + (p.image ? image_tag(p.image.public_filename :portrait) : ''), p.identifier) %> </li>
  4 + <% end %>
  5 +</ul>
... ...
app/design_blocks/list_block/views/index.rhtml
... ... @@ -1,5 +0,0 @@
1   -<ul class='people_list_block'>
2   - <% @people.each do |p| %>
3   - <li> <%= link_to_homepage(content_tag('span',p.name) + (p.image ? image_tag(p.image.public_filename :portrait) : ''), p.identifier) %> </li>
4   - <% end %>
5   -</ul>
app/design_blocks/list_block/views/person.rhtml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<ul class='people_list_block'>
  2 + <% @elements.each do |p| %>
  3 + <li> <%= link_to_homepage(content_tag('span',p.name) + (p.image ? image_tag(p.image.public_filename :portrait) : ''), p.identifier) %> </li>
  4 + <% end %>
  5 +</ul>
... ...
app/design_blocks/profile_info_block/controllers/profile_info_block_controller.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +class ProfileInfoBlockController < ApplicationController
  2 +
  3 + # This controller always has the object @design_block available to it.
  4 + # The method acts_as_design_block load a before_filter that always load
  5 + # this object.
  6 +
  7 + needs_profile
  8 +
  9 + acts_as_design_block
  10 +
  11 + # You must have a hash on format:
  12 + # {
  13 + # 'action name' => 'How the action will be displayed on menu'
  14 + # }
  15 + #
  16 + # EX:
  17 + # CONTROL_ACTION_OPTIONS = {
  18 + # 'design_edit' => _('Edit'),
  19 + # 'manage_links' => _('Manage Links')
  20 + # }
  21 + #
  22 + # This hash will define the options menu on edit mode.
  23 + CONTROL_ACTION_OPTIONS = {
  24 +# 'edit' => _('Edit')
  25 + }
  26 +
  27 +
  28 + ###########################
  29 + # Mandatory methods
  30 + ###########################
  31 +
  32 + def index
  33 + @info = @profile.info
  34 + design_render
  35 + end
  36 +
  37 + ###########################
  38 + # Other Sample of methods
  39 + ###########################
  40 +
  41 + def edit
  42 + design_render_on_edit
  43 + end
  44 +
  45 + def save
  46 + @design_block.update_attributes(params[:design_block])
  47 + design_render_on_edit :nothing => true
  48 + end
  49 +
  50 +
  51 +end
... ...
app/design_blocks/profile_info_block/helpers/profile_info_block_helper.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +module ProfileInfoBlockHelper
  2 +
  3 +end
... ...
app/design_blocks/profile_info_block/models/profile_info_block.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class ProfileInfoBlock < Design::Block
  2 +
  3 + # Define an specific method using the settings hash serialized
  4 + # variable to keep the value desired by method.
  5 + #
  6 + # EX:
  7 + # def max_number_of_element= value
  8 + # self.settings[:limit_number] = value
  9 + # end
  10 +
  11 + def self.description
  12 + 'ProfileInfoBlock'
  13 + end
  14 +
  15 +end
... ...
app/design_blocks/profile_info_block/views/index.rhtml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<%= image_tag @profile.image.public_filename(:thumb) if @profile.image %> <br>
  2 +<%= @profile.name %><br>
  3 +<%= n_('1 years', '%{num} years', @info.age) % {:num => @info.age} %><br>
... ...
app/models/person_info.rb
1 1 class PersonInfo < ActiveRecord::Base
2 2  
3   - # FIXME: add file_column :photo
4   -
5 3 belongs_to :person
6 4  
7 5 def summary
8   - [
9   - [ PersonInfo.columns_hash['name'].human_name, self.name ],
10   - [ PersonInfo.columns_hash['address'].human_name, self.address ],
11   - [ PersonInfo.columns_hash['contact_information'].human_name, self.contact_information ],
12   - ]
  6 + ['name', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col|
  7 + [ PersonInfo.columns_hash[col] && PersonInfo.columns_hash[col].human_name, self.send(col) ]
  8 + end
  9 + end
  10 +
  11 + def age
  12 + a = Date.today.year - birth_date.year
  13 + Date.today.yday > birth_date.yday ? a : a-1
13 14 end
14 15  
15 16 end
... ...
app/models/profile.rb
... ... @@ -34,6 +34,7 @@ class Profile &lt; ActiveRecord::Base
34 34 not_found
35 35 cat
36 36 tag
  37 + environment
37 38 ]
38 39  
39 40 belongs_to :user
... ...
app/views/category/_product_category.rhtml
  1 +<%= link_to(_('I consume this'), {:profile => current_user.login, :controller => 'consumed_products', :action => 'new', 'consumption[product_category_id]' => @category.id }, :method => :post) %>
1 2 <ul>
2 3 <li><%= n_("One product in this category.", "%{num} products in this category.", @products.size) % { :num => @products.size } %></li>
3 4 <li><%= n_("One enterprise sells products in this category.", "%{num} enterprises sells products in this category.", @enterprises.size) % { :num => @enterprises.size} %></li>
... ...
app/views/profile_editor/enterprise_info.rhtml 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<label class='formlabel' for="name"><%= _('Name') %></label>
  2 +<p class='formfield text_field'><%= text_field 'enterprise', 'name', 'size' => 20, 'class' => 'formfield text_field' %></p>
  3 +
  4 +<p class='formfield text_field'><label for="address"><%= _('Address') %></label><br/>
  5 +<%= text_field 'enterprise', 'address', 'size' => 50 %></p>
  6 +
  7 +<p class='formfield text_field'><label for="contact_phone"><%= _('Contact Phone') %></label><br/>
  8 +<%= text_field 'enterprise', 'contact_phone', 'size' => 20 %></p>
  9 +
  10 +<p class='formfield text_field'><label for="contact_person"><%= _('Contact Person') %></label><br/>
  11 +<%= text_field 'organization_info', 'contact_person', 'size' => 20 %></p>
  12 +
  13 +<p class='formfield text_field'><label for="acronym"><%= _('Acronym') %></label><br/>
  14 +<%= text_field 'organization_info', 'acronym', 'size' => 20 %></p>
  15 +
  16 +<p class='formfield text_field'><label for="foundation_year"><%= _('Foundation Year') %></label><br/>
  17 +<%= text_field 'organization_info', 'foundation_year', 'size' => 20 %></p>
  18 +
  19 +<p class='formfield text_field'><label for="legal_form"><%= _('Legal Form') %></label><br/>
  20 +<%= text_field 'organization_info', 'legal_form', 'size' => 20 %></p>
  21 +
  22 +<p class='formfield text_field'><label for="economic_activity"><%= _('Economic Activity') %></label><br/>
  23 +<%= text_field 'organization_info', 'economic_activity', 'size' => 20 %></p>
  24 +
  25 +<p class='formfield text_area'><label for="management_information"><%= _('Management Information') %></label><br/>
  26 +<%= text_area 'organization_info', 'management_information', 'cols' => 40, 'rows' => 20 %></p>
  27 +
  28 +<p class='formfield select'><label for="validation_entity"><%= _('Validation Entity') %></label><br/>
  29 +<%= select 'validation_entity', 'id', @validation_entities.map{|v| [v.name, v.id]}, :include_blank => true %></p>
  30 +
  31 +<p class='formfield text_field'><label for="tag_list"><%= _('Tags') %></label><br/>
  32 +<%= text_field 'enterprise', 'tag_list', 'size' => 20 %></p>
... ...
app/views/profile_editor/person_info.rhtml
... ... @@ -4,9 +4,16 @@
4 4  
5 5 <%= display_form_field(_('Name'), f.text_field(:name)) %>
6 6  
7   - <%= display_form_field(_('Address'), f.text_area(:address, :rows => 5)) %>
8   -
9 7 <%= display_form_field(_('Contact Information'), f.text_area(:contact_information, :rows => 5)) %>
  8 + <%= display_form_field(_('Birth day'), f.date_select(:birth_date, :start_year => 1930, :use_month_numbers => true, :order => [:day, :month, :year])) %>
  9 +
  10 + <%= _('Sex: ') %>
  11 + <%= display_form_field(_('Male'), f.radio_button(:sex, 'male')) %>
  12 + <%= display_form_field(_('Female'), f.radio_button(:sex, 'female')) %>
  13 + <%= display_form_field(_('Address'), f.text_area(:address, :rows => 3)) %>
  14 + <%= display_form_field(_('City'), f.text_field(:city)) %>
  15 + <%= display_form_field(_('State'), f.text_field(:state)) %>
  16 + <%= display_form_field(_('Country'), f.text_field(:country)) %>
10 17  
11 18 <%= submit_tag _('Save') %>
12 19  
... ...
db/migrate/003_create_profiles.rb
... ... @@ -5,7 +5,7 @@ class CreateProfiles &lt; ActiveRecord::Migration
5 5 t.column :type, :string
6 6 t.column :identifier, :string
7 7 t.column :environment_id, :integer
8   - t.column :design_data, :text
  8 + t.column :design_data, :text
9 9  
10 10 t.column :active, :boolean, :default => true
11 11 t.column :address, :string
... ...
db/migrate/010_create_person_infos.rb
1 1 class CreatePersonInfos < ActiveRecord::Migration
2 2 def self.up
3 3 create_table :person_infos do |t|
4   - t.column :name, :string
5   - t.column :photo, :text
6   - t.column :address, :text
  4 + t.column :name, :string
  5 + t.column :photo, :text
7 6 t.column :contact_information, :text
  7 + t.column :birth_date, :date
  8 + t.column :sex, :string
  9 + t.column :address, :text
  10 + t.column :city, :string
  11 + t.column :state, :string
  12 + t.column :country, :string
8 13  
9   - t.column :person_id, :integer
  14 + t.column :created_at, :datetime
  15 + t.column :updated_at, :datetime
  16 + t.column :person_id, :integer
10 17 end
11 18 end
12 19  
... ...
test/integration/routing_test.rb
... ... @@ -83,6 +83,9 @@ class RoutingTest &lt; ActionController::IntegrationTest
83 83 def test_routing_to_controllers_inside_design_blocks_directory
84 84 assert_routing('/block/cojones/favorite_links_profile/show/1', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'show', :id => '1')
85 85 assert_routing('/block/cojones/favorite_links_profile/save', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'save')
  86 + assert_routing('/block/environment/favorite_links_profile/design_editor_destroy_block', :controller => 'favorite_links_profile', :action => 'design_editor_destroy_block' )
  87 +
  88 + assert_routing('/block/cojones/list_block/show/1', :profile => 'cojones', :controller => 'list_block', :action => 'show', :id => '1')
86 89 end
87 90  
88 91 def test_tag_viewing
... ...