From 2bc409497443d2d3f53fe054923a8ed18a80ccd4 Mon Sep 17 00:00:00 2001 From: Gust Date: Tue, 18 Nov 2014 08:45:42 -0200 Subject: [PATCH] Refactor search filters, add search extension --- lib/ext/search_controller.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ lib/mpog_software_plugin.rb | 76 ---------------------------------------------------------------------------- views/search/search_community_filter.html.erb | 2 +- 3 files changed, 48 insertions(+), 77 deletions(-) create mode 100644 lib/ext/search_controller.rb diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb new file mode 100644 index 0000000..5331a2d --- /dev/null +++ b/lib/ext/search_controller.rb @@ -0,0 +1,47 @@ +require_dependency 'search_controller' + +class SearchController + + def communities + if params[:type] == "Software" + softwares = SoftwareInfo.search(params[:name]) + communities = [] + softwares.each do |s| + communities << s.community + end + results = communities + results = results.paginate(:per_page => 24, :page => params[:page]) + @searches[@asset] = {:results => results} + @search = results + puts "-"*80, @searches + puts "-"*80, @search + elsif params[:type] == "Institution" + institutions = Institution.search_institution(params[:intitution_name]) + puts "="*80, institutions + communities = [] + institutions.each do |s| + communities << s.community + end + results = communities + puts "_"*80, results + results = results.paginate(:per_page => 24, :page => params[:page]) + puts "-="*80, results + @searches[@asset] = {:results => results} + @search = results + puts "="*80, @searches + puts "="*80, @search + else + unfiltered_list = visible_profiles(Community).select{ |com| com.name =~ /#{params[:query]}/} + list_without_software_and_institution = [] + unfiltered_list.each do |p| + if p.class == Community and !p.software? and !p.institution? + list_without_software_and_institution << p + end + end + results = list_without_software_and_institution + results = results.paginate(:per_page => 24, :page => params[:page]) + @searches[@asset] = {:results => results} + @search = results + end + end +end \ No newline at end of file diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 469f748..a7072c2 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -93,82 +93,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin }] end - def search_controller_filters - community_block = proc do - results = [] - if params[:type] == "Software" - softwares = SoftwareInfo.search(params[:name]) - communities = [] - softwares.each do |s| - communities << s.community - end - results = communities - results = results.paginate(:per_page => 24, :page => params[:page]) - @searches[@asset] = {:results => results} - @search = results - render :action => :communities - elsif params[:type] == "Institution" - institutions = Institution.search_institution(params[:intitution_name]) - communities = [] - institutions.each do |s| - communities << s.community - end - results = communities - results = results.paginate(:per_page => 24, :page => params[:page]) - @searches[@asset] = {:results => results} - @search = results - render :action => :communities - #FIXME: Careful while merginging, this else must be the default action - else - unfiltered_list = visible_profiles(Community).select{ |com| com.name =~ /#{params[:query]}/} - list_without_software_and_institution = [] - unfiltered_list.each do |p| - if p.class == Community and !p.software? and !p.institution? - list_without_software_and_institution << p - end - end - - results = list_without_software_and_institution - - results = results.paginate(:per_page => 24, :page => params[:page]) - @searches[@asset] = {:results => results} - @search = results - render :action => :communities - end - - end - - people_block = proc do - results = [] - - results = environment.people.search(name = params[:name], - state = params[:state], - city = params[:city], - email = params[:email] - ) - - results = results.paginate(:per_page => 24, :page => params[:page]) - @searches[@asset] = {:results => results} - @search = results - - render :action => :people - end - - - [{ - :type => "before_filter", - :method_name => "search_person_filters", - :options => { :only=>:people }, - :block => people_block - }, - { - :type => "before_filter", - :method_name => "search_software_filters", - :options => { :only=>:communities }, - :block => community_block - }] - end - def profile_tabs if context.profile.person? { :title => _("Secundary Information"), diff --git a/views/search/search_community_filter.html.erb b/views/search/search_community_filter.html.erb index 458a605..4596057 100644 --- a/views/search/search_community_filter.html.erb +++ b/views/search/search_community_filter.html.erb @@ -1,4 +1,4 @@ -
+
-- libgit2 0.21.2