Commit 40df430a3b31efc91336b18418193bdde52eb3fc
1 parent
fcad091d
Exists in
master
and in
27 other branches
profile_suggestions: group suggestions interface
Users can: * add a suggestion as community * remove a suggestion from list (ActionItem3234)
Showing
6 changed files
with
101 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/memberships_controller.rb
| @@ -25,4 +25,19 @@ class MembershipsController < MyProfileController | @@ -25,4 +25,19 @@ class MembershipsController < MyProfileController | ||
| 25 | return | 25 | return |
| 26 | end | 26 | end |
| 27 | end | 27 | end |
| 28 | + | ||
| 29 | + def suggest | ||
| 30 | + @suggestions = profile.suggested_communities.paginate(:per_page => 8, :page => params[:npage]) | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + def remove_suggestion | ||
| 34 | + @community = profile.suggested_communities.find_by_identifier(params[:id]) | ||
| 35 | + redirect_to :action => 'suggest' unless @community | ||
| 36 | + if @community && request.post? | ||
| 37 | + suggestion = profile.profile_suggestions.find_by_suggestion_id @community.id | ||
| 38 | + suggestion.disable | ||
| 39 | + redirect_to :action => 'suggest' | ||
| 40 | + end | ||
| 41 | + end | ||
| 42 | + | ||
| 28 | end | 43 | end |
app/views/memberships/index.html.erb
| @@ -16,6 +16,8 @@ | @@ -16,6 +16,8 @@ | ||
| 16 | <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :id => 'memberships_filter')%> | 16 | <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :id => 'memberships_filter')%> |
| 17 | </p> | 17 | </p> |
| 18 | 18 | ||
| 19 | +<p><%= link_to _('See some suggestions of communities...'), :action => 'suggest' %></p> | ||
| 20 | + | ||
| 19 | <% if @memberships.empty? %> | 21 | <% if @memberships.empty? %> |
| 20 | <p> | 22 | <p> |
| 21 | <em><%= _('No groups to list') %></em> | 23 | <em><%= _('No groups to list') %></em> |
| @@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
| 1 | +<div class='communities-suggestions'> | ||
| 2 | + <h1><%= _("Communities suggestions for %s") % profile.name %></h1> | ||
| 3 | + | ||
| 4 | + <% button_bar do %> | ||
| 5 | + <%= button(:back, _('Go to groups list'), :controller => 'memberships') %> | ||
| 6 | + <% end %> | ||
| 7 | + | ||
| 8 | + <% if @suggestions.empty? %> | ||
| 9 | + <p> | ||
| 10 | + <em> | ||
| 11 | + <%= _('You have no suggestions yet.') %> | ||
| 12 | + <%= link_to _('Do you want to see communities in this environment?'), :controller => 'search', :action => 'assets', :asset => 'communities' %> | ||
| 13 | + </em> | ||
| 14 | + </p> | ||
| 15 | + <% else %> | ||
| 16 | + <ul class="profile-list"> | ||
| 17 | + <% @suggestions.each do |suggestion| %> | ||
| 18 | + <li> | ||
| 19 | + <%= link_to_profile profile_image(suggestion) + '<br/>' + suggestion.short_name, | ||
| 20 | + suggestion.identifier, :class => 'profile-link' %> | ||
| 21 | + <div class="controll"> | ||
| 22 | + <%= link_to content_tag('span',_('join')), | ||
| 23 | + suggestion.join_url, | ||
| 24 | + :class => 'button icon-add join-community', | ||
| 25 | + :title => _("Join %s") % suggestion.name %> | ||
| 26 | + <%= link_to content_tag('span',_('remove')), | ||
| 27 | + { :action => 'remove_suggestion', :id => suggestion.identifier }, | ||
| 28 | + :class => 'button icon-remove', | ||
| 29 | + :title => _('Remove suggestion'), | ||
| 30 | + :method => 'post', | ||
| 31 | + :confirm => _('Are you sure you want to remove this suggestion?') %> | ||
| 32 | + </div><!-- end class="controll" --> | ||
| 33 | + </li> | ||
| 34 | + <% end %> | ||
| 35 | + </ul> | ||
| 36 | + <% end %> | ||
| 37 | + | ||
| 38 | + <%= pagination_links @suggestions, :param_name => 'npage' %> | ||
| 39 | + <br style="clear:both" /> | ||
| 40 | +</div> |
public/javascripts/add-and-join.js
| @@ -12,7 +12,7 @@ jQuery(function($) { | @@ -12,7 +12,7 @@ jQuery(function($) { | ||
| 12 | }) | 12 | }) |
| 13 | 13 | ||
| 14 | $(".join-community").live('click', function(){ | 14 | $(".join-community").live('click', function(){ |
| 15 | - clicked = $(".join-community"); | 15 | + clicked = $(this); |
| 16 | url = clicked.attr("href"); | 16 | url = clicked.attr("href"); |
| 17 | loading_for_button(this); | 17 | loading_for_button(this); |
| 18 | $.post(url, function(data){ | 18 | $.post(url, function(data){ |
test/functional/memberships_controller_test.rb
| @@ -327,4 +327,42 @@ class MembershipsControllerTest < ActionController::TestCase | @@ -327,4 +327,42 @@ class MembershipsControllerTest < ActionController::TestCase | ||
| 327 | assert_includes assigns(:roles), role1 | 327 | assert_includes assigns(:roles), role1 |
| 328 | assert_not_includes assigns(:roles), role2 | 328 | assert_not_includes assigns(:roles), role2 |
| 329 | end | 329 | end |
| 330 | + | ||
| 331 | + should 'display list suggestions button' do | ||
| 332 | + community = fast_create(Community) | ||
| 333 | + profile.profile_suggestions.create(:suggestion => community) | ||
| 334 | + get :index, :profile => 'testuser' | ||
| 335 | + assert_tag :tag => 'a', :content => 'See some suggestions of communities...', :attributes => { :href => "/myprofile/testuser/memberships/suggest" } | ||
| 336 | + end | ||
| 337 | + | ||
| 338 | + should 'display communities suggestions' do | ||
| 339 | + community = fast_create(Community) | ||
| 340 | + profile.profile_suggestions.create(:suggestion => community) | ||
| 341 | + get :suggest, :profile => 'testuser' | ||
| 342 | + assert_tag :tag => 'a', :content => community.name, :attributes => { :href => "/profile/#{community.identifier}" } | ||
| 343 | + end | ||
| 344 | + | ||
| 345 | + should 'display button to join on community suggestion' do | ||
| 346 | + community = fast_create(Community) | ||
| 347 | + profile.profile_suggestions.create(:suggestion => community) | ||
| 348 | + get :suggest, :profile => 'testuser' | ||
| 349 | + assert_tag :tag => 'a', :attributes => { :href => "/profile/#{community.identifier}/join" } | ||
| 350 | + end | ||
| 351 | + | ||
| 352 | + should 'display button to remove community suggestion' do | ||
| 353 | + community = fast_create(Community) | ||
| 354 | + profile.profile_suggestions.create(:suggestion => community) | ||
| 355 | + get :suggest, :profile => 'testuser' | ||
| 356 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/remove_suggestion/#{community.identifier}" } | ||
| 357 | + end | ||
| 358 | + | ||
| 359 | + should 'remove suggestion of community' do | ||
| 360 | + community = fast_create(Community) | ||
| 361 | + suggestion = profile.profile_suggestions.create(:suggestion => community) | ||
| 362 | + post :remove_suggestion, :profile => 'testuser', :id => community.identifier | ||
| 363 | + | ||
| 364 | + assert_redirected_to :action => 'suggest' | ||
| 365 | + assert_equal false, ProfileSuggestion.find(suggestion.id).enabled | ||
| 366 | + end | ||
| 367 | + | ||
| 330 | end | 368 | end |