Commit da80901859490132a5657754dd7cff6fc370ebdc
Committed by
David Silva
1 parent
f78b8a05
Exists in
master
and in
79 other branches
Refactor InstitutionBlock
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
2 changed files
with
28 additions
and
22 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
@@ -138,8 +138,6 @@ class MpogSoftwarePluginController < ApplicationController | @@ -138,8 +138,6 @@ class MpogSoftwarePluginController < ApplicationController | ||
138 | protected | 138 | protected |
139 | 139 | ||
140 | def get_state_list | 140 | def get_state_list |
141 | - redirect_to "/" unless request.xhr? | ||
142 | - | ||
143 | NationalRegion.find( | 141 | NationalRegion.find( |
144 | :all, | 142 | :all, |
145 | :conditions=>["national_region_type_id = ?", 2], | 143 | :conditions=>["national_region_type_id = ?", 2], |
lib/institutions_block.rb
@@ -21,11 +21,14 @@ class InstitutionsBlock < CommunitiesBlock | @@ -21,11 +21,14 @@ class InstitutionsBlock < CommunitiesBlock | ||
21 | case owner | 21 | case owner |
22 | when Profile | 22 | when Profile |
23 | lambda do |context| | 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 | end | 27 | end |
26 | when Environment | 28 | when Environment |
27 | lambda do |context| | 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 | end | 32 | end |
30 | else | 33 | else |
31 | '' | 34 | '' |
@@ -33,25 +36,9 @@ class InstitutionsBlock < CommunitiesBlock | @@ -33,25 +36,9 @@ class InstitutionsBlock < CommunitiesBlock | ||
33 | end | 36 | end |
34 | 37 | ||
35 | def profile_list | 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 | result.slice(0..get_limit-1) | 43 | result.slice(0..get_limit-1) |
57 | end | 44 | end |
@@ -60,4 +47,25 @@ class InstitutionsBlock < CommunitiesBlock | @@ -60,4 +47,25 @@ class InstitutionsBlock < CommunitiesBlock | ||
60 | owner.communities | 47 | owner.communities |
61 | end | 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 | end | 71 | end |