Commit da80901859490132a5657754dd7cff6fc370ebdc

Authored by Fabio Teixeira
Committed by David Silva
1 parent f78b8a05
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Refactor InstitutionBlock

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
controllers/mpog_software_plugin_controller.rb
... ... @@ -138,8 +138,6 @@ class MpogSoftwarePluginController &lt; ApplicationController
138 138 protected
139 139  
140 140 def get_state_list
141   - redirect_to "/" unless request.xhr?
142   -
143 141 NationalRegion.find(
144 142 :all,
145 143 :conditions=>["national_region_type_id = ?", 2],
... ...
lib/institutions_block.rb
... ... @@ -21,11 +21,14 @@ class InstitutionsBlock &lt; CommunitiesBlock
21 21 case owner
22 22 when Profile
23 23 lambda do |context|
24   - link_to s_('institutions|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities', :type => 'Institution'
  24 + link_to s_('institutions|View all'), :profile => owner.identifier,
  25 + :controller => 'profile', :action => 'communities',
  26 + :type => 'Institution'
25 27 end
26 28 when Environment
27 29 lambda do |context|
28   - link_to s_('institutions|View all'), :controller => 'search', :action => 'communities', :type => 'Institution'
  30 + link_to s_('institutions|View all'), :controller => 'search',
  31 + :action => 'communities', :type => 'Institution'
29 32 end
30 33 else
31 34 ''
... ... @@ -33,25 +36,9 @@ class InstitutionsBlock &lt; CommunitiesBlock
33 36 end
34 37  
35 38 def profile_list
36   - result = nil
37   - visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
38   - if !prioritize_profiles_with_image
39   - result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
40   - elsif profiles.visible.with_image.count >= get_limit
41   - result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
42   - else
43   - result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
44   - end
45   -
46   - communities_with_institution_list = []
47   -
48   - result.each do |r|
49   - if r.class == Community and r.institution?
50   - communities_with_institution_list << r
51   - end
52   - end
  39 + result = get_visible_profiles
53 40  
54   - result = communities_with_institution_list
  41 + result = result.select { |p| p.class == Community && p.institution? }
55 42  
56 43 result.slice(0..get_limit-1)
57 44 end
... ... @@ -60,4 +47,25 @@ class InstitutionsBlock &lt; CommunitiesBlock
60 47 owner.communities
61 48 end
62 49  
  50 + private
  51 +
  52 + def get_visible_profiles
  53 + include_list = [:image,:domains,:preferred_domain,:environment]
  54 + visible_profiles = profiles.visible.includes(include_list)
  55 +
  56 + if !prioritize_profiles_with_image
  57 + visible_profiles.all(:limit => get_limit,
  58 + :order => 'profiles.updated_at DESC'
  59 + ).sort_by{ rand }
  60 + elsif profiles.visible.with_image.count >= get_limit
  61 + visible_profiles.with_image.all(:limit => get_limit * 5,
  62 + :order => 'profiles.updated_at DESC'
  63 + ).sort_by{ rand }
  64 + else
  65 + visible_profiles.with_image.sort_by{ rand } +
  66 + visible_profiles.without_image.all(:limit => get_limit * 5,
  67 + :order => 'profiles.updated_at DESC'
  68 + ).sort_by{ rand }
  69 + end
  70 + end
63 71 end
... ...