From fd65e2c1473333575a743558654dc2061d5165d2 Mon Sep 17 00:00:00 2001 From: Omar Junior Date: Tue, 21 Jul 2015 11:31:50 -0300 Subject: [PATCH] Split members page in admins and non-admins - Order members by name - Removed white spaces - Changed strings to be translated - Renamed div id and test - Adjust ul tag members - Fixed plugin dependency --- app/controllers/public/profile_controller.rb | 13 ++++++++++++- app/views/profile/members.html.erb | 45 ++++++++++++++++++++++++++++++++++++++------- plugins/people_block/controllers/people_block_plugin_profile_controller.rb | 2 +- plugins/people_block/views/people_block_profile/members.html.erb | 29 +++++++++++++++++++++++++++++ public/designs/themes/base/style.css | 8 ++++++++ public/javascripts/members_page.js | 24 ++++++++++++++++++++++++ public/stylesheets/application.css | 1 + test/functional/profile_controller_test.rb | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 plugins/people_block/views/people_block_profile/members.html.erb create mode 100644 public/javascripts/members_page.js diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index da07102..a0abf98 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -65,8 +65,19 @@ class ProfileController < PublicController def members if is_cache_expired?(profile.members_cache_key(params)) - @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => profile.members.count) + all_members = if params[:sort] and params[:sort] == "desc" + profile.members.order("name desc") + else + profile.members.order("name asc") + end + + @profile_admins = profile.admins + @total_members = all_members.count + @members_except_admins = all_members - @profile_admins + @members_count = @members_except_admins.count + @members_except_admins = @members_except_admins.paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => @members_count) end + end def fans diff --git a/app/views/profile/members.html.erb b/app/views/profile/members.html.erb index fc9f1ae..4c4fab8 100644 --- a/app/views/profile/members.html.erb +++ b/app/views/profile/members.html.erb @@ -1,16 +1,44 @@
-

<%= _("%s's members") % profile.name %>

+

<%= _("Members") + " (#{@total_members})" %>

+

<%= _("%s") % profile.name %>

<% cache_timeout(profile.members_cache_key(params), 4.hours) do %> - + +
+

<%= "#{@profile_admins.count} "+_("admins") %>

+
    + <% @profile_admins.each do |admin| %> + <%= profile_image_link(admin) %> + <% end %> +
+
+ +
+

<%= "#{@members_count} "+ _("members") %>

+ +
+ <%= label_tag("sort", _("Sort by:")) %> + <%= select_tag("sort", + options_for_select( + [ + [_("Name A-Z"), 'asc'], + [_("Name Z-A"), 'desc'], + ], :selected=>params[:sort]) + ) %> +
+
+ +
+
    + <% @members_except_admins.each do |member| %> + <%= profile_image_link(member) %> + <% end %> +
+
- <%= pagination_links @members, :param_name => 'npage' %> + <%= pagination_links @members_except_admins, :param_name => 'npage' %>
<% end %> @@ -26,4 +54,7 @@ <% end %> <% end %> +<%= hidden_field_tag "current_profile", profile.identifier %>
+ +<%= javascript_include_tag "members_page.js" %> diff --git a/plugins/people_block/controllers/people_block_plugin_profile_controller.rb b/plugins/people_block/controllers/people_block_plugin_profile_controller.rb index f879976..8f608c3 100644 --- a/plugins/people_block/controllers/people_block_plugin_profile_controller.rb +++ b/plugins/people_block/controllers/people_block_plugin_profile_controller.rb @@ -14,7 +14,7 @@ class PeopleBlockPluginProfileController < ProfileController end @members = @members.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => @members.count) end - render "profile/members" + render "people_block_profile/members" end end diff --git a/plugins/people_block/views/people_block_profile/members.html.erb b/plugins/people_block/views/people_block_profile/members.html.erb new file mode 100644 index 0000000..fd0c390 --- /dev/null +++ b/plugins/people_block/views/people_block_profile/members.html.erb @@ -0,0 +1,29 @@ +
+ +

<%= _("%s's members") % profile.name %>

+ +<% cache_timeout(profile.members_cache_key(params), 4.hours) do %> + + +
+ <%= pagination_links @members, :param_name => 'npage' %> +
+<% end %> + +<% button_bar do %> + <%= button :back, _('Go back'), { :controller => 'profile' } %> + <% if profile.community? and user %> + <% if user.has_permission?(:invite_members, profile) %> + <%= button :person, _('Invite people to join'), :controller => 'invite', :action => 'invite_friends' %> + <% end %> + <% if user.has_permission?(:send_mail_to_members, profile) %> + <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %> + <% end %> + <% end %> +<% end %> + +
\ No newline at end of file diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index 59a3a2e..0ee8d31 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -231,6 +231,10 @@ body, th, td, input { border-left: 0px; } +.menu-submenu-list>li{ + width: 100%; +} + #navigation .menu-submenu ul{ border: 1px solid #888a85; border-top: 0px; @@ -1530,3 +1534,7 @@ table#recaptcha_table tr:hover td { width: 494px; padding-left: 2px; } + +.profile-members-title-sort { + clear: both; +} \ No newline at end of file diff --git a/public/javascripts/members_page.js b/public/javascripts/members_page.js new file mode 100644 index 0000000..2ea43ca --- /dev/null +++ b/public/javascripts/members_page.js @@ -0,0 +1,24 @@ +(function($) { + "use strict"; + + function set_members_sort() { + var page_profile = $("#current_profile").val(); + var members_url = noosfero_root() + "/profile/" + page_profile + "/members"; + + $("#sort").on("change", function() { + var sort_value = this.value; + var actual_page_content = $(".common-profile-list-block"); + + $.get(members_url, {sort: sort_value}, function(response) { + var html_response = $(response); + + actual_page_content.html(html_response.html()); + set_members_sort(); + }); + }); + } + + $(document).ready(function() { + set_members_sort(); + }); +}) (jQuery); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 5c668ee..4c18991 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -5442,6 +5442,7 @@ h1#agenda-title { margin: 0; padding: 0; width: 100%; + height: 92px; } #content .menu-submenu-content ul { margin: 0; diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 5f4a779..d79ba08 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -55,7 +55,8 @@ class ProfileControllerTest < ActionController::TestCase assert_response :success assert_template 'members' - assert assigns(:members) + assert assigns(:members_except_admins) + assert assigns(:profile_admins) end should 'list favorite enterprises' do @@ -1748,4 +1749,68 @@ class ProfileControllerTest < ActionController::TestCase assert_no_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }} end + should 'only admins from a community be present in admin users div' do + community = fast_create(Community) + another_user = create_user('another_user').person + + login_as(@profile.identifier) + + community.add_admin(@profile) + community.add_member(another_user) + + get :members, :profile => community.identifier + + assert_tag :tag => 'div', :attributes => { :class => /profile-admins/}, + :descendant => { :tag => 'a', :attributes => { :title => "testuser" } } + + assert_no_tag :tag => 'div', :attributes => { :class => /profile-admins/}, + :descendant => { :tag => 'a', :attributes => { :title => "another_user" } } + end + + should 'only normal users from a community be present in normal users div' do + community = fast_create(Community) + another_user = create_user('another_user').person + + login_as(@profile.identifier) + + community.add_admin(@profile) + community.add_member(another_user) + + get :members, :profile => community.identifier + + assert_no_tag :tag => 'div', :attributes => { :class => /profile-members/}, + :descendant => { :tag => 'a', :attributes => { :title => "testuser" } } + + assert_tag :tag => 'div', :attributes => { :class => /profile-members/}, + :descendant => { :tag => 'a', :attributes => { :title => "another_user" } } + end + + should 'members be sorted by name in ascendant order' do + community = fast_create(Community) + another_user = create_user('another_user').person + different_user = create_user('different_user').person + + community.add_member(@profile) + community.add_member(another_user) + community.add_member(different_user) + + get :members, :profile => community.identifier, :sort => "asc" + + assert @response.body.index("another_user") < @response.body.index("different_user") + end + + should 'members be sorted by name in descendant order' do + community = fast_create(Community) + another_user = create_user('another_user').person + different_user = create_user('different_user').person + + community.add_member(@profile) + community.add_member(another_user) + community.add_member(different_user) + + get :members, :profile => community.identifier, :sort => "desc" + + assert @response.body.index("another_user") > @response.body.index("different_user") + end + end -- libgit2 0.21.2