From 897eb62e2f531bc1c3d551aa3af77878170c7848 Mon Sep 17 00:00:00 2001 From: Luciano Date: Wed, 21 Jan 2015 16:34:23 -0200 Subject: [PATCH] Software category search by checkbox --- lib/ext/search_controller.rb | 35 +++++++++++++++++++++++++++++++---- lib/mpog_software_plugin.rb | 1 + public/catalog-filter.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/style.css | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/search/_catalog_filter.html.erb | 59 ++++++++++++++++++++++++++++++++++++----------------------- views/search/_mpog_search_form.html.erb | 5 +++-- 6 files changed, 321 insertions(+), 29 deletions(-) create mode 100644 public/catalog-filter.js diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb index e5e04bc..df26904 100644 --- a/lib/ext/search_controller.rb +++ b/lib/ext/search_controller.rb @@ -22,9 +22,31 @@ class SearchController def software_infos - @titles[:software_infos] = _("Software Catalog") + @titles[:software_infos] = _("Public Software Catalog") @category_filters = [] @categories = Category.all + @selected_categories = params[:selected_categories] + + @selected_categories_name = [] + @message_selected_options = "Most options" + unless @selected_categories.nil? + @message_selected_options = _("Selected options: ") + @selected_categories.each do |k, v| + @message_selected_options << "#{k}; " + @selected_categories_name << k + end + end + + @categories.sort!{|a, b| a.name <=> b.name} + @categories_groupe_one = [] + @categories_groupe_two = [] + (0..(@categories.count - 1)).each do |i| + if i % 2 == 0 + @categories_groupe_one << @categories[i] + else + @categories_groupe_two << @categories[i] + end + end results = filter_software_infos_list results = results.paginate(:per_page => 24, :page => params[:page]) @@ -54,11 +76,16 @@ class SearchController def filter_software_infos_list filtered_software_list = SoftwareInfo.like_search(params[:query]) - if not params[:categories].blank? - @category_filters = params[:categories].select {|c| c.to_i != 0 } + category_ids = [] + unless params[:selected_categories].blank? + category_ids = params[:selected_categories].values + end + category_ids = category_ids.map(&:to_i) + unless category_ids.empty? filtered_software_list.select! do |software| - !(software.community.category_ids & @category_filters).blank? + result_ids = (software.community.category_ids & category_ids).sort + result_ids == category_ids.sort end end diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index ee86fb6..0b0c420 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -130,6 +130,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin mpog-search.js software-catalog.js mpog-software-block.js + catalog-filter.js ) end diff --git a/public/catalog-filter.js b/public/catalog-filter.js new file mode 100644 index 0000000..6ae5905 --- /dev/null +++ b/public/catalog-filter.js @@ -0,0 +1,59 @@ +jQuery(function(){ + function show_head_message() { + if (jQuery("#filter-categories-select-catalog").text().blank()){ + jQuery("#filter-categories-select-catalog").hide(); + jQuery("#filter-option-catalog-software").show(); + }else{ + jQuery("#filter-categories-select-catalog").show(); + jQuery("#filter-option-catalog-software").hide(); + } + } + + show_head_message(); + + jQuery("#filter-categories-option").hide(); + jQuery("#filter-option-catalog-software").click(function(){ + jQuery("#filter-categories-option").slideDown(); + jQuery("#filter-option-catalog-software").hide(); + }); + + jQuery("#filter-categories-option").hide(); + jQuery("#filter-categories-select-catalog").click(function(){ + jQuery("#filter-categories-option").slideDown(); + jQuery("#filter-categories-select-catalog").hide(); + }); + + jQuery("#close-filter-catalog").click(function(){ + jQuery("#filter-categories-option").slideUp(); + show_head_message(); + }); + + jQuery("#cleanup-filter-catalg").click(function(){ + jQuery("#filter-categories-option").slideUp(); + jQuery("#filter-option-catalog-software").show(); + jQuery("#group-categories input:checked").each(function() { + jQuery(this).prop('checked', false); + }); + }); + + jQuery(".categories-catalog").click(function(){ + jQuery("#filter-categories-option").slideUp(); + jQuery("#filter-categories-select-catalog").show(); + jQuery("#filter-option-catalog-software").hide(); + }); + + jQuery(".project-software").click(function(){ + jQuery("#filter-categories-option").slideUp(); + jQuery("#filter-categories-select-catalog").show(); + jQuery("#filter-option-catalog-software").hide(); + }); + + function clear_categories_filter(e) { + e.preventDefault(); + jQuery("#categories-filter input:checked").each(function() { + jQuery(this).prop('checked', false); + }); + } +}); + + diff --git a/public/style.css b/public/style.css index b6abf77..2676827 100644 --- a/public/style.css +++ b/public/style.css @@ -268,3 +268,194 @@ background-color:rgba(255, 255, 255, 0.9); } /* End software block main area definitions */ + +/* Software catalog definitions */ + +#main-content-wrapper-8 h2{ + margin:0px; + font-family: arial; + font-weight: normal; + font-size: 16px; + color: #F50054; + text-transform: uppercase; +} + +#main-content-wrapper-8 h1{ + font-family: arial; + color:#121D2B; +} + +.search-form{ + background:#EAEBEE; /*#1A397D;*/ + /*padding:10px;*/ + padding: 5px 5px 1px 10px; + border-top-left-radius:4px; + border-top-right-radius: 4px; +} + +.search-form h3{ + text-transform: uppercase; + font-family: arial; + font-size: 14px; + margin-bottom: 5px; + color:#2B51A8; +} + +#search-input{ + width: 700px; + border-radius:3px; + font-size: 140%; + background: #ffffff; + border: medium none; +} + +input.button.with-text.icon-search.submit{ + font-size: 14px; + background:#2B51A8; /*#2B65CD;*#1A397D;*/ + margin-top:8px; + color:#ffffff; + text-transform: uppercase; + border-radius: 4px; + /*border: 1px solid #ffffff;*/ + border: 1px solid #2B51A8; + padding: 5px 15px; + +} + +#filter-option-catalog-software{ + padding:8px; + color:#000; + text-transform: uppercase; + text-align: right; + border-top: 1px solid #ffffff; + background-color: #D4D5DC; /*#172857;*/ + border-bottom-left-radius:4px; + border-bottom-right-radius: 4px; +} + +#filter-option-catalog-software:hover{ + background-color: #2B65CD; + border-bottom-left-radius:4px; + border-bottom-right-radius: 4px; + cursor:pointer; +} + +#filter-categories-select-catalog{ + border-top: 1px solid #ffffff; + margin:0px; + cursor:pointer; + padding: 8px; + /*color: #FFF;*/ + text-transform: uppercase; +} + +#filter-categories-option{ + border-top: 1px solid #ffffff; + padding: 15px 10px; +} + +/*#filter-categories{ + margin:10px 5px; + color:#ffffff; +}*/ + +#filter-categories-catalog h4{ + margin:10px 5px; + color:#000; +} + +#group-categories{ + line-height: 31px; +} + +#gruop-catalog-01{ + float:left; + width: 50%; +} + +#gruop-catalog-02{ + margin-left: 50%; + line-height: 31px; +} + +.project-software{ + border-top: 1px dashed; + border-bottom: 1px dashed; + margin-top:10px; + padding:10px; +} + + +#filter-catalog-software{ + /*border: 1px solid #ffffff;*/ + background-color: #D4D5DC; /*#ccc;#172857;*/ + border-bottom-left-radius:4px; + border-bottom-right-radius: 4px; + +} + +#cleanup-filter-catalg{ + margin-left:5px; +} + +#cleanup-filter-catalg{ + background:#2B65CD; /*#1A397D;*/ + margin-top:5px; + color:#ffffff; + /*text-transform: uppercase;*/ + border-radius: 4px; + /*border: 1px solid #ffffff;*/ + border: 1px solid #2B65CD; + padding: 5px 10px; + font-size: 12px; +} +#cleanup-filter-catalg:hover{ + background-color: #172857; +} + +#close-filter-catalog{ + float:right; + border:none; + background: none; + font-size:12px; + margin-top: 5px; + color: #000; + text-transform: uppercase; + padding: 5px; + +} +/* +#close-filter-catalog:hover{ + background:#2B65CD; + border-radius: 4px; + margin-top: 5px; + color: #FFF; + text-transform: uppercase; + border-radius: 4px; + border: 1px solid #2B65CD; + padding: 5px; +} + +#close-filter-catalog:after{ + content:"︿"; + padding-left: 7px; + padding-right: 4px; + color: #172857; + background: none repeat scroll 0% 0% #EEE; + border-radius: 4px; + font-size: 15px; + line-height: 20px; + text-align: center; + position: relative; + margin-left: 5px; + top: 2px; + margin-right: 15px; +} +*/ + +input[type=checkbox] { + border:1px solid #000; + margin:8px; + cursor:pointer; +} +/* End software catalog definitions */ \ No newline at end of file diff --git a/views/search/_catalog_filter.html.erb b/views/search/_catalog_filter.html.erb index bd59eba..8eae030 100644 --- a/views/search/_catalog_filter.html.erb +++ b/views/search/_catalog_filter.html.erb @@ -1,29 +1,42 @@ -
-
- -
+
+ +
+ +
Mais opções
+ -
-
- <%= _('Selected options: ') %> sagdhjasgdhjagsd -
+
<%= @message_selected_options %>
-
-
-
    - <% @categories.each do |category| %> -
  • - <%= labelled_check_box category.name, "categories[]", category.id %> -
  • +
    + +

    <%= _("Categories") %>

    +
    +
    + <% @categories_groupe_one.each do |category| %> +
    + <% end %> +
    +
    + <% @categories_groupe_two.each do |category| %> +
    <% end %> -
+
-
+ +
<%= _("Software Projects:") %> + + (?) + +

+ <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> + <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %>
+ \ No newline at end of file diff --git a/views/search/_mpog_search_form.html.erb b/views/search/_mpog_search_form.html.erb index 4e46072..a31ecd2 100644 --- a/views/search/_mpog_search_form.html.erb +++ b/views/search/_mpog_search_form.html.erb @@ -3,6 +3,8 @@ <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, :method => 'get', :class => 'search_form' ) do %> +
+
<%= hidden_field_tag :display, params[:display] %> <%= hidden_field_tag :filter, params[:filter] %> @@ -12,12 +14,11 @@ <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> - <%= submit_button(:search, _('Search')) %> + <%= submit_button(:search, _('Search'), :class => "button with-text icon-search submit") %> <%= render :partial => 'search_form_extra_fields' %> <%= render :partial => 'catalog_filter' %> - <% end %> <% if @empty_query %> -- libgit2 0.21.2