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
lib/institutions_block.rb
... | ... | @@ -21,11 +21,14 @@ class InstitutionsBlock < 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 < 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 < 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 | ... | ... |