Commit a8cb8dcf2731adabde3ddbbfca842b36b9e43f1c
1 parent
d9020ffa
Exists in
manage_organization
Add type filter on manage organization page on admin panel
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
5 changed files
with
134 additions
and
13 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
... | ... | @@ -73,10 +73,20 @@ class AdminPanelController < AdminController |
73 | 73 | end |
74 | 74 | |
75 | 75 | def manage_organizations_status |
76 | - scope = environment.organizations | |
77 | 76 | @filter = params[:filter] || 'any' |
78 | 77 | @title = "Organization profiles" |
79 | 78 | @title = @title+" - "+@filter if @filter != 'any' |
79 | + @type = params[:type] || "any" | |
80 | + @types_filter = [['All', 'any'], [_('Community'), 'communities'], [_('Enterprise'), 'enterprises']] | |
81 | + @types_filter = @types_filter | @plugins.dispatch_without_flatten(:organization_types_filter_options).flatten(1) | |
82 | + | |
83 | + scope = if @type == "communities" | |
84 | + environment.communities | |
85 | + elsif @type == "enterprises" | |
86 | + environment.enterprises | |
87 | + else | |
88 | + environment.organizations | |
89 | + end | |
80 | 90 | |
81 | 91 | if @filter == 'enabled' |
82 | 92 | scope = scope.visible |
... | ... | @@ -85,8 +95,12 @@ class AdminPanelController < AdminController |
85 | 95 | end |
86 | 96 | |
87 | 97 | scope = scope.order('name ASC') |
98 | + result_plugin = @plugins.dispatch(:filter_manage_organization_scope, scope, @type) | |
99 | + scope = result_plugin if !result_plugin.blank? | |
88 | 100 | |
89 | 101 | @q = params[:q] |
90 | 102 | @collection = find_by_contents(:organizations, environment, scope, @q, {:per_page => 10, :page => params[:npage]})[:results] |
103 | + | |
104 | + render :layout=>false if request.xhr? | |
91 | 105 | end |
92 | 106 | end | ... | ... |
app/views/admin_panel/manage_organizations_status.html.erb
... | ... | @@ -23,15 +23,22 @@ |
23 | 23 | <div style="clear: both"></div> |
24 | 24 | </div> |
25 | 25 | |
26 | - <table> | |
26 | + <table id='organizations-list'> | |
27 | 27 | <colgroup> |
28 | - <col width="80%"> | |
28 | + <col width="60%"> | |
29 | + <col width="20%"> | |
29 | 30 | <col width="20%"> |
30 | 31 | </colgroup> |
31 | 32 | |
32 | 33 | <tr> |
33 | 34 | <th><%= _('Member') %></th> |
34 | 35 | <th><%= _('Actions') %></th> |
36 | + <th><%= _('Type') %> | |
37 | + | |
38 | + <select id="profile_type_select"> | |
39 | + <%= options_for_select(@types_filter, @type) %> | |
40 | + </select> | |
41 | + </th> | |
35 | 42 | </tr> |
36 | 43 | |
37 | 44 | <% @collection.each do |p| %> |
... | ... | @@ -48,22 +55,20 @@ |
48 | 55 | <%= button_without_text :'delete', _('Remove'), {:controller => "profile_editor", :action => 'destroy_profile', :profile => p.identifier, :id => p.id, :return_to => "/admin/admin_panel/manage_organizations_status"}, :method => :post, :confirm => _("Do you want to deactivate this profile ?") %> |
49 | 56 | </div> |
50 | 57 | </td> |
58 | + | |
59 | + <td> <%= _("#{p.type}") %> </td> | |
51 | 60 | </tr> |
52 | 61 | <% end %> |
53 | 62 | </table> |
54 | 63 | |
55 | 64 | <% end %> |
56 | 65 | |
57 | -<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %> | |
66 | +<div> | |
67 | + <%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %> | |
68 | +</div> | |
58 | 69 | |
59 | 70 | <% button_bar do %> |
60 | 71 | <%= button :back, _('Back'), :controller => 'admin_panel' %> |
61 | 72 | <% end %> |
62 | 73 | |
63 | -<script type="text/javascript"> | |
64 | - jQuery(document).ready(function(){ | |
65 | - jQuery("#profile_filter_select").change(function(){ | |
66 | - document.location.href = '/admin/admin_panel/manage_organizations_status?filter='+this.value; | |
67 | - }); | |
68 | - }); | |
69 | -</script> | |
70 | 74 | \ No newline at end of file |
75 | +<%= javascript_include_tag 'manage-organizations-status' %> | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -277,6 +277,18 @@ class Noosfero::Plugin |
277 | 277 | nil |
278 | 278 | end |
279 | 279 | |
280 | + # -> Filters the types of organizations that are shown on manage organizations | |
281 | + # returns a scope filtered by the specified type | |
282 | + def filter_manage_organization_scope scope, type | |
283 | + nil | |
284 | + end | |
285 | + | |
286 | + # -> Add new options for manage organization filters | |
287 | + # returns an array of new options | |
288 | + # i.e [[_('Type'), 'type'], [_('Type2'), 'type2']] | |
289 | + def organization_types_filter_options | |
290 | + nil | |
291 | + end | |
280 | 292 | # -> Adds content to profile editor info and settings |
281 | 293 | # returns = lambda block that creates html code or raw rhtml/html.erb |
282 | 294 | def profile_editor_extras | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +(function($) { | |
2 | + function set_events() { | |
3 | + $("#profile_filter_select").change(filter_page_loader); | |
4 | + $("#profile_type_select").change(filter_page_loader); | |
5 | + } | |
6 | + | |
7 | + function filter_page_loader() { | |
8 | + var page_action = '/admin/admin_panel/manage_organizations_status'; | |
9 | + var filter = $("#profile_filter_select").val(); | |
10 | + var type = $("#profile_type_select").val(); | |
11 | + | |
12 | + $.ajax({ | |
13 | + url: page_action, | |
14 | + type: 'GET', | |
15 | + data: { | |
16 | + 'filter': filter, | |
17 | + 'type': type, | |
18 | + 'npage': 1 | |
19 | + }, success: function(response) { | |
20 | + var response_html = $(response); | |
21 | + var table_data = response_html.find('#organizations-list tbody').html(); | |
22 | + var pagination_data = response_html.find('.pagination').html(); | |
23 | + var title_header = response_html.find('#environment-users-filter-title').html(); | |
24 | + var has_pagination = response_html.find('.pagination').length === 1; | |
25 | + | |
26 | + $('#environment-users-filter-title').html(title_header); | |
27 | + $('#organizations-list').html(table_data); | |
28 | + | |
29 | + if(has_pagination) { | |
30 | + $('.pagination').html(pagination_data); | |
31 | + } else { | |
32 | + $('.pagination').html(''); | |
33 | + } | |
34 | + | |
35 | + set_events(); | |
36 | + } | |
37 | + }); | |
38 | + } | |
39 | + | |
40 | + | |
41 | + $(document).ready(function(){ | |
42 | + set_events(); | |
43 | + filter_page_loader(); | |
44 | + }); | |
45 | +})(jQuery); | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -17,12 +17,12 @@ class AdminPanelControllerTest < ActionController::TestCase |
17 | 17 | should 'manage the correct environment' do |
18 | 18 | current = fast_create(Environment, :name => 'test environment', :is_default => false) |
19 | 19 | current.domains.create!(:name => 'example.com') |
20 | - | |
20 | + | |
21 | 21 | @request.expects(:host).returns('example.com').at_least_once |
22 | 22 | get :index |
23 | 23 | assert_equal current, assigns(:environment) |
24 | 24 | end |
25 | - | |
25 | + | |
26 | 26 | should 'link to site_info editing page' do |
27 | 27 | get :index |
28 | 28 | assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/site_info' } |
... | ... | @@ -411,4 +411,49 @@ class AdminPanelControllerTest < ActionController::TestCase |
411 | 411 | assert_not_match(/enabled community/, @response.body) |
412 | 412 | assert_match(/disabled community/, @response.body) |
413 | 413 | end |
414 | + | |
415 | + should 'show list only of enterprise' do | |
416 | + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") | |
417 | + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") | |
418 | + | |
419 | + user = create_user('user') | |
420 | + | |
421 | + Environment.default.add_admin user.person | |
422 | + login_as('user') | |
423 | + | |
424 | + get :manage_organizations_status, :type=>"enterprises" | |
425 | + assert_match(/Organization profiles/, @response.body) | |
426 | + assert_match(/Enterprise Test/, @response.body) | |
427 | + assert_not_match(/Community Test/, @response.body) | |
428 | + end | |
429 | + | |
430 | + should 'show list only of communities' do | |
431 | + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") | |
432 | + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") | |
433 | + | |
434 | + user = create_user('user') | |
435 | + | |
436 | + Environment.default.add_admin user.person | |
437 | + login_as('user') | |
438 | + | |
439 | + get :manage_organizations_status, :type=>"communities" | |
440 | + assert_match(/Organization profiles/, @response.body) | |
441 | + assert_not_match(/Enterprise Test/, @response.body) | |
442 | + assert_match(/Community Test/, @response.body) | |
443 | + end | |
444 | + | |
445 | + should 'show list all organizations' do | |
446 | + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") | |
447 | + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") | |
448 | + | |
449 | + user = create_user('user') | |
450 | + | |
451 | + Environment.default.add_admin user.person | |
452 | + login_as('user') | |
453 | + | |
454 | + get :manage_organizations_status, :type=>"any" | |
455 | + assert_match(/Organization profiles/, @response.body) | |
456 | + assert_match(/Enterprise Test/, @response.body) | |
457 | + assert_match(/Community Test/, @response.body) | |
458 | + end | |
414 | 459 | end | ... | ... |