Commit 2bc409497443d2d3f53fe054923a8ed18a80ccd4
Committed by
Luciano Prestes
1 parent
402aba1a
Exists in
master
and in
5 other branches
Refactor search filters, add search extension
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com> Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Showing
3 changed files
with
48 additions
and
77 deletions
Show diff stats
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +require_dependency 'search_controller' | ||
2 | + | ||
3 | +class SearchController | ||
4 | + | ||
5 | + def communities | ||
6 | + if params[:type] == "Software" | ||
7 | + softwares = SoftwareInfo.search(params[:name]) | ||
8 | + communities = [] | ||
9 | + softwares.each do |s| | ||
10 | + communities << s.community | ||
11 | + end | ||
12 | + results = communities | ||
13 | + results = results.paginate(:per_page => 24, :page => params[:page]) | ||
14 | + @searches[@asset] = {:results => results} | ||
15 | + @search = results | ||
16 | + puts "-"*80, @searches | ||
17 | + puts "-"*80, @search | ||
18 | + elsif params[:type] == "Institution" | ||
19 | + institutions = Institution.search_institution(params[:intitution_name]) | ||
20 | + puts "="*80, institutions | ||
21 | + communities = [] | ||
22 | + institutions.each do |s| | ||
23 | + communities << s.community | ||
24 | + end | ||
25 | + results = communities | ||
26 | + puts "_"*80, results | ||
27 | + results = results.paginate(:per_page => 24, :page => params[:page]) | ||
28 | + puts "-="*80, results | ||
29 | + @searches[@asset] = {:results => results} | ||
30 | + @search = results | ||
31 | + puts "="*80, @searches | ||
32 | + puts "="*80, @search | ||
33 | + else | ||
34 | + unfiltered_list = visible_profiles(Community).select{ |com| com.name =~ /#{params[:query]}/} | ||
35 | + list_without_software_and_institution = [] | ||
36 | + unfiltered_list.each do |p| | ||
37 | + if p.class == Community and !p.software? and !p.institution? | ||
38 | + list_without_software_and_institution << p | ||
39 | + end | ||
40 | + end | ||
41 | + results = list_without_software_and_institution | ||
42 | + results = results.paginate(:per_page => 24, :page => params[:page]) | ||
43 | + @searches[@asset] = {:results => results} | ||
44 | + @search = results | ||
45 | + end | ||
46 | + end | ||
47 | +end | ||
0 | \ No newline at end of file | 48 | \ No newline at end of file |
lib/mpog_software_plugin.rb
@@ -93,82 +93,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -93,82 +93,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
93 | }] | 93 | }] |
94 | end | 94 | end |
95 | 95 | ||
96 | - def search_controller_filters | ||
97 | - community_block = proc do | ||
98 | - results = [] | ||
99 | - if params[:type] == "Software" | ||
100 | - softwares = SoftwareInfo.search(params[:name]) | ||
101 | - communities = [] | ||
102 | - softwares.each do |s| | ||
103 | - communities << s.community | ||
104 | - end | ||
105 | - results = communities | ||
106 | - results = results.paginate(:per_page => 24, :page => params[:page]) | ||
107 | - @searches[@asset] = {:results => results} | ||
108 | - @search = results | ||
109 | - render :action => :communities | ||
110 | - elsif params[:type] == "Institution" | ||
111 | - institutions = Institution.search_institution(params[:intitution_name]) | ||
112 | - communities = [] | ||
113 | - institutions.each do |s| | ||
114 | - communities << s.community | ||
115 | - end | ||
116 | - results = communities | ||
117 | - results = results.paginate(:per_page => 24, :page => params[:page]) | ||
118 | - @searches[@asset] = {:results => results} | ||
119 | - @search = results | ||
120 | - render :action => :communities | ||
121 | - #FIXME: Careful while merginging, this else must be the default action | ||
122 | - else | ||
123 | - unfiltered_list = visible_profiles(Community).select{ |com| com.name =~ /#{params[:query]}/} | ||
124 | - list_without_software_and_institution = [] | ||
125 | - unfiltered_list.each do |p| | ||
126 | - if p.class == Community and !p.software? and !p.institution? | ||
127 | - list_without_software_and_institution << p | ||
128 | - end | ||
129 | - end | ||
130 | - | ||
131 | - results = list_without_software_and_institution | ||
132 | - | ||
133 | - results = results.paginate(:per_page => 24, :page => params[:page]) | ||
134 | - @searches[@asset] = {:results => results} | ||
135 | - @search = results | ||
136 | - render :action => :communities | ||
137 | - end | ||
138 | - | ||
139 | - end | ||
140 | - | ||
141 | - people_block = proc do | ||
142 | - results = [] | ||
143 | - | ||
144 | - results = environment.people.search(name = params[:name], | ||
145 | - state = params[:state], | ||
146 | - city = params[:city], | ||
147 | - email = params[:email] | ||
148 | - ) | ||
149 | - | ||
150 | - results = results.paginate(:per_page => 24, :page => params[:page]) | ||
151 | - @searches[@asset] = {:results => results} | ||
152 | - @search = results | ||
153 | - | ||
154 | - render :action => :people | ||
155 | - end | ||
156 | - | ||
157 | - | ||
158 | - [{ | ||
159 | - :type => "before_filter", | ||
160 | - :method_name => "search_person_filters", | ||
161 | - :options => { :only=>:people }, | ||
162 | - :block => people_block | ||
163 | - }, | ||
164 | - { | ||
165 | - :type => "before_filter", | ||
166 | - :method_name => "search_software_filters", | ||
167 | - :options => { :only=>:communities }, | ||
168 | - :block => community_block | ||
169 | - }] | ||
170 | - end | ||
171 | - | ||
172 | def profile_tabs | 96 | def profile_tabs |
173 | if context.profile.person? | 97 | if context.profile.person? |
174 | { :title => _("Secundary Information"), | 98 | { :title => _("Secundary Information"), |
views/search/search_community_filter.html.erb
1 | -<form action="/search/communities" name="community_filter" method="get" class="search_form"> | 1 | +<form action="<%= Noosfero.root%>/search/communities" name="community_filter" method="get" class="search_form"> |
2 | <div id="search_content"> | 2 | <div id="search_content"> |
3 | 3 | ||
4 | <div class="search_options"> | 4 | <div class="search_options"> |