diff --git a/plugins/sub_organizations/controllers/sub_organizations_plugin_profile_controller.rb b/plugins/sub_organizations/controllers/sub_organizations_plugin_profile_controller.rb index 97ded24..69e379e 100644 --- a/plugins/sub_organizations/controllers/sub_organizations_plugin_profile_controller.rb +++ b/plugins/sub_organizations/controllers/sub_organizations_plugin_profile_controller.rb @@ -4,20 +4,40 @@ class SubOrganizationsPluginProfileController < ProfileController before_filter :organizations_only def children - @organizations = SubOrganizationsPlugin::Relation.children(profile) - + children = SubOrganizationsPlugin::Relation.children(profile) + family_relation(children) render 'related_organizations' end def parents - @organizations = SubOrganizationsPlugin::Relation.parents(profile) - + parents = SubOrganizationsPlugin::Relation.parents(profile) + family_relation(parents) render 'related_organizations' end - private + def family_relation(_profile) + @communities = _profile.communities + @enterprises = _profile.enterprises + @full = true + + if !params[:type] and !params[:display] + @communities = SubOrganizationsPlugin.limit(@communities) + @enterprises = SubOrganizationsPlugin.limit(@enterprises) + @full = false + elsif !params[:type] + @total = _profile + @total = @total.paginate(:per_page => 2, :page => params[:npage]) + if params[:display] == 'compact' + @full = false + end + else + @communities = @communities.paginate(:per_page => 2, :page => params[:npage]) + @enterprises = @enterprises.paginate(:per_page => 2, :page => params[:npage]) + end + end + def organizations_only render_not_found if !profile.organization? end diff --git a/plugins/sub_organizations/features/sub_organizations_display.feature b/plugins/sub_organizations/features/sub_organizations_display.feature new file mode 100644 index 0000000..e573a12 --- /dev/null +++ b/plugins/sub_organizations/features/sub_organizations_display.feature @@ -0,0 +1,80 @@ +Feature: sub_organizations_display + As a user + I want my organizations to have blocks that lists it's related-organizations + In order to have quick access to it's related-organizations + + Background: + Given "SubOrganizations" plugin is enabled + And the following users + | login | name | + | nelson | Nelson | + And feature "enterprise_registration" is enabled on environment + And the following community + | identifier | name | owner | description | city | state | + | springfield | Springfield | nelson | Springfield description | Los Angeles | California | + | moe | Moe | nelson | Moe description | Kansas | Texas | + And the following enterprise + | identifier | name | owner | description | city | state | + | school | School | nelson | School description | Terra do Nunca | Billy Jean | + And I am logged in as "nelson" + And I go to springfield's control panel + When I follow "Edit sideboxes" + And I follow "Add a block" + And I choose "Related Organizations" + And I press "Add" + + @selenium + Scenario: Display the sub organization block when there is a sub enterprise and communitys + When I go to springfield's control panel + And I follow "Manage sub-groups" + And I follow "Register a new sub-enterprise" + And I fill in "Name" with "Bart" + And I press "Next" + Then I should see "Enterprise registration completed" + And I am logged in as admin + And I go to admin_user's control panel + When I follow "Tasks" within ".control-panel" + Then I should see "Nelson wants to create enterprise Bart." + And the first mail is to admin_user@example.com + And I choose "Accept" + And I press "Apply!" + And I am logged in as "nelson" + When I go to springfield's control panel + And I follow "Manage sub-groups" + And I follow "Create a new sub-community" + And I fill in "Name" with "Homer" + And I press "Create" + When I go to springfield's "children" page from "SubOrganizationsPluginProfileController" of "SubOrganizations" plugin + Then I should see "Homer" within ".related-organizations-block" + And I should see "Bart" within ".related-organizations-block" + + Scenario: Display with compact mode + Given "moe" is a sub organization of "springfield" + And "school" is a sub organization of "springfield" + When I go to springfield's homepage + And I follow "View all" within ".related-organizations-block" + Then I should see "Springfield's sub-communities" + And I should see "Springfield's sub-enterprises" + + Scenario: Display with full mode for sub-communities + Given "moe" is a sub organization of "springfield" + When I go to springfield's homepage + And I follow "View all" within ".related-organizations-block" + Then I should see "Springfield's sub-communities" + And I follow "Full" within ".search-customize-options" + Then I should see "Moe description" within ".related-organizations-description" + And I should see "Kansas, Texas" within ".related-organizations-region-name" + + Scenario: Display with full mode for sub-enterprises + Given "school" is a sub organization of "springfield" + When I go to springfield's homepage + And I follow "View all" within ".related-organizations-block" + And I should see "Springfield's sub-enterprises" + And I follow "Full" within ".search-customize-options" + Then I should see "School description" within ".related-organizations-description" + And I should see "Terra do Nunca, Billy Jean" within ".related-organizations-region-name" + + Scenario: Display message when display full block are empty + Given I follow "View all" within ".related-organizations-block" + Then I should see "There are no sub-communities yet." + And I should see "There are no sub-enterprises yet." diff --git a/plugins/sub_organizations/lib/sub_organizations_plugin.rb b/plugins/sub_organizations/lib/sub_organizations_plugin.rb index 496ac15..46c0e24 100644 --- a/plugins/sub_organizations/lib/sub_organizations_plugin.rb +++ b/plugins/sub_organizations/lib/sub_organizations_plugin.rb @@ -1,7 +1,15 @@ require_dependency File.dirname(__FILE__) + '/related_organizations_block' +class SubOrganizationsPlugin < Noosfero::Plugin; end; + +require_dependency 'sub_organizations_plugin/search_helper' + class SubOrganizationsPlugin < Noosfero::Plugin + include SearchHelper + + DISPLAY_LIMIT = 12 + def self.plugin_name _("Sub-groups") end @@ -47,6 +55,10 @@ class SubOrganizationsPlugin < Noosfero::Plugin {'sub_organizations_plugin_parent_to_be' => parent_to_be} if parent_to_be.present? end + def self.limit(organizations) + organizations.all(:limit => DISPLAY_LIMIT, :order => 'updated_at DESC').sort_by{ rand } + end + def self.extra_blocks { RelatedOrganizationsBlock => {:type => [Enterprise, Community], :position => ['1', '2', '3']} diff --git a/plugins/sub_organizations/lib/sub_organizations_plugin/relation_helper.rb b/plugins/sub_organizations/lib/sub_organizations_plugin/relation_helper.rb new file mode 100644 index 0000000..4d41a2a --- /dev/null +++ b/plugins/sub_organizations/lib/sub_organizations_plugin/relation_helper.rb @@ -0,0 +1,9 @@ +module SubOrganizationsPlugin::RelationHelper + def display_relation(organization,type,display_mode) + if display_mode == 'full' + render :partial => 'sub_organizations_plugin_profile/full_related_organizations', :locals => {:organizations => organization,:organization_type => type} + else + render :partial => 'sub_organizations_plugin_profile/related_organizations', :locals => {:organizations => organization, :organization_type => type} + end + end +end \ No newline at end of file diff --git a/plugins/sub_organizations/lib/sub_organizations_plugin/search_helper.rb b/plugins/sub_organizations/lib/sub_organizations_plugin/search_helper.rb new file mode 100644 index 0000000..a271ad6 --- /dev/null +++ b/plugins/sub_organizations/lib/sub_organizations_plugin/search_helper.rb @@ -0,0 +1,18 @@ +require_dependency 'search_helper' + +module SubOrganizationsPlugin::SearchHelper + + include SearchHelper + + def display_selectors(display, float = 'right') + display = 'compact' if display.blank? + compact_link = display == 'compact' ? _('Compact') : link_to(_('Compact'), params.merge(:display => 'compact')) + full_link = display == 'full' ? _('Full') : link_to(_('Full'), params.merge(:display => 'full')) + content_tag('div', + content_tag('strong', _('Display')) + ': ' + [compact_link,full_link].compact.join(' | ').html_safe, + :class => 'search-customize-options' + ) + end + + +end diff --git a/plugins/sub_organizations/public/style.css b/plugins/sub_organizations/public/style.css index ff13e0e..776a019 100644 --- a/plugins/sub_organizations/public/style.css +++ b/plugins/sub_organizations/public/style.css @@ -17,3 +17,108 @@ padding-right: 15px; background: url(images/arrow-right-p.png) 100% 50% no-repeat; } + +.clearfix { + clear: both; +} + +.related-organizations-list-block .vcard{ + margin-right: 10px; + -webkit-border-radius: 0 !important; + -moz-border-radius: 0!important; + -o-border-radius: 0!important; + border-radius: 0!important; +} +.related-organizations-item-column-right .search-result-title{ + margin: 10px 0; +} + +#main-content-wrapper-8 ul{ + padding-left: 0; +} + +.related-organizations-list-block ul li{ + list-style: none; + margin: 10px 0; + border: 1px solid #ccc; + /*padding: 10px 5px;*/ +} + +.related-organizations-list-block ul li:hover{ + border: 1px solid #999; +} + +.related-organizations-list-block .profile_link{ + height: auto !important; + max-height: none !important; + max-width: none !important; + height: 150px; + width: 150px; +} + +.related-organizations-list-block .org { + display: none !important; +} + +.related-organizations-item .profile-image img{ + max-height: 150px; + max-width: 150px; +} + + +.menu-submenu-list>li{ + border: 0!important; +} + +.related-organizations-list-block .menu-submenu{ + bottom: 147px; + right: 5px; +} + +.related-organizations-region-name{ + line-height: 2em; + font-weight: bold; +} + +.related-organizations-description{ + color: #333; +} + + +.related-organizations-list-block .vcard a{ + padding: 0; + margin: 0; + border: 0; +} + +.related-organizations-list-block .vcard img { + opacity: 1; + -webkit-transition: all 0.5s ease-out; + -moz-transition: all 0.5s ease-out; + -o-transition: all 0.5s ease-out; + -ms-transition: all 0.5s ease-out; + transition: all 0.5s ease-out; +} + +.related-organizations-list-block .vcard img:hover { + opacity: 0.5; +} + +.related-organizations-item-column-right { + float: right; + position: relative; + width: 65%; +} + +.related-organizations-item-column-left { +float: left; +position: relative; +width: 35%; +} + +.related-organizations-block ul { + min-width: 196px; + width: 192px; + margin: 0px 0px 0px -3px; + padding: 0px; +} diff --git a/plugins/sub_organizations/views/sub_organizations_plugin_profile/_full_related_organizations.rhtml b/plugins/sub_organizations/views/sub_organizations_plugin_profile/_full_related_organizations.rhtml new file mode 100644 index 0000000..646f086 --- /dev/null +++ b/plugins/sub_organizations/views/sub_organizations_plugin_profile/_full_related_organizations.rhtml @@ -0,0 +1,63 @@ +<% extend SubOrganizationsPlugin::SearchHelper %> + diff --git a/plugins/sub_organizations/views/sub_organizations_plugin_profile/_related_organizations.rhtml b/plugins/sub_organizations/views/sub_organizations_plugin_profile/_related_organizations.rhtml index c706ff8..aab4afb 100644 --- a/plugins/sub_organizations/views/sub_organizations_plugin_profile/_related_organizations.rhtml +++ b/plugins/sub_organizations/views/sub_organizations_plugin_profile/_related_organizations.rhtml @@ -1,16 +1,27 @@ +<% extend SubOrganizationsPlugin::ApplicationHelper %>
-

<%= __("#{profile.name}'s sub-#{organization_type.pluralize}") %>

- + + <% if organizations.length == 0 %> +
  • <%= __("There are no sub-#{organization_type.pluralize} yet. " ) %>
  • + <% end %> + <% button_bar(:class => "related-organizations-button-bar") do %> + <%= button :back, _('Go back'), { :controller => 'profile' } %> + <%= button :add, __("Add a new #{organization_type}"), :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %> -<% button_bar(:class => "related-organizations-button-bar") do %> - <%= button :back, _('Go back'), { :controller => 'profile' } %> - <%= button :add, __("Add a new #{organization_type}"), :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %> + <% if !@full %> + <%= button :more, _('View all'), { :controller => 'sub_organizations_plugin_profile', :action => params[:action], :type => organization_type } %> + <% end %> + <% end %> +
    +<% if @full %> +
    + <%= pagination_links(organizations, {:param_name => 'npage', :page_links => true}) %> +
    <% end %> - - + diff --git a/plugins/sub_organizations/views/sub_organizations_plugin_profile/related_organizations.rhtml b/plugins/sub_organizations/views/sub_organizations_plugin_profile/related_organizations.rhtml index ac613c3..cfbebc0 100644 --- a/plugins/sub_organizations/views/sub_organizations_plugin_profile/related_organizations.rhtml +++ b/plugins/sub_organizations/views/sub_organizations_plugin_profile/related_organizations.rhtml @@ -1,7 +1,21 @@ -<% if params[:type] != 'enterprise' %> - <%= render :partial => 'sub_organizations_plugin_profile/related_organizations', :locals => {:organizations => @organizations.communities, :organization_type => 'community'} %> +<% extend SubOrganizationsPlugin::SearchHelper %> +<% extend SubOrganizationsPlugin::RelationHelper %> + +
    + <%= display_selectors(params[:display]) %> +
    + +<% if params[:type] == 'community' %> + <%= display_relation(@communities,params[:type],params[:display]) %> +<% end %> + +<% if params[:type] == 'enterprise' %> + <%= display_relation(@enterprises,params[:type],params[:display]) %> <% end %> -<% if params[:type] != 'community' %> - <%= render :partial => 'sub_organizations_plugin_profile/related_organizations', :locals => {:organizations => @organizations.enterprises, :organization_type => 'enterprise'} %> +<% if ["full"].include?(params[:display]) and !params[:type] %> + <%= display_relation(@total,"organizations",params[:display]) %> +<% elsif !params[:type] %> + <%= display_relation(@communities,"community",params[:display]) %> + <%= display_relation(@enterprises,"enterprise",params[:display]) %> <% end %> -- libgit2 0.21.2